From ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 3 Nov 2016 13:44:16 +0100 Subject: [PATCH] build, internal/build: misc improvements (#3229) * travis.yml: don't create darwin/386 builds * build: remove godep remains * internal/build: improve archives - enable compression for zip files - don't write half-complete archives * build: add -unstable to archive names --- .travis.yml | 4 +--- Makefile | 2 +- build/ci.go | 20 ++++++++++++-------- build/env.sh | 1 - build/update-license.go | 2 +- internal/build/archive.go | 28 ++++++++++++++++++---------- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index eba836695..a2271de12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,9 +45,7 @@ matrix: - azure-osx script: - go run build/ci.go install - - go run build/ci.go archive -type zip -signer OSX_SIGNING_KEY -upload gethstore/builds - - go run build/ci.go install -arch 386 - - go run build/ci.go archive -arch 386 -type zip -signer OSX_SIGNING_KEY -upload gethstore/builds + - go run build/ci.go archive -type tar -signer OSX_SIGNING_KEY -upload gethstore/builds install: - go get golang.org/x/tools/cmd/cover diff --git a/Makefile b/Makefile index f23b32f42..d3d67950e 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ test: all build/env.sh go run build/ci.go test clean: - rm -fr build/_workspace/pkg/ Godeps/_workspace/pkg $(GOBIN)/* + rm -fr build/_workspace/pkg/ $(GOBIN)/* # Cross Compilation Targets (xgo) diff --git a/build/ci.go b/build/ci.go index 910de6d60..c6c6f61c9 100644 --- a/build/ci.go +++ b/build/ci.go @@ -296,18 +296,20 @@ func doArchive(cmdline []string) { log.Fatal("unknown archive type: ", atype) } - env := build.Env() + var ( + env = build.Env() + base = archiveBasename(*arch, env) + geth = "geth-" + base + ext + alltools = "geth-alltools-" + base + ext + ) maybeSkipArchive(env) - - base := archiveBasename(*arch, env) - if err := build.WriteArchive("geth-"+base, ext, gethArchiveFiles); err != nil { + if err := build.WriteArchive(geth, gethArchiveFiles); err != nil { log.Fatal(err) } - if err := build.WriteArchive("geth-alltools-"+base, ext, allToolsArchiveFiles); err != nil { + if err := build.WriteArchive(alltools, allToolsArchiveFiles); err != nil { log.Fatal(err) } - - for _, archive := range []string{"geth-" + base + ext, "geth-alltools-" + base + ext} { + for _, archive := range []string{geth, alltools} { if err := archiveUpload(archive, *upload, *signer); err != nil { log.Fatal(err) } @@ -315,9 +317,11 @@ func doArchive(cmdline []string) { } func archiveBasename(arch string, env build.Environment) string { - // date := time.Now().UTC().Format("200601021504") platform := runtime.GOOS + "-" + arch archive := platform + "-" + build.VERSION() + if isUnstableBuild(env) { + archive += "-unstable" + } if env.Commit != "" { archive += "-" + env.Commit[:8] } diff --git a/build/env.sh b/build/env.sh index c418dae44..3914555d1 100755 --- a/build/env.sh +++ b/build/env.sh @@ -19,7 +19,6 @@ if [ ! -L "$ethdir/go-ethereum" ]; then fi # Set up the environment to use the workspace. -# Also add Godeps workspace so we build using canned dependencies. GOPATH="$workspace" export GOPATH diff --git a/build/update-license.go b/build/update-license.go index 96667be15..94b319550 100644 --- a/build/update-license.go +++ b/build/update-license.go @@ -45,7 +45,7 @@ var ( // paths with any of these prefixes will be skipped skipPrefixes = []string{ // boring stuff - "Godeps/", "tests/files/", "build/", + "vendor/", "tests/files/", "build/", // don't relicense vendored sources "crypto/sha3/", "crypto/ecies/", "logger/glog/", "crypto/secp256k1/curve.go", diff --git a/internal/build/archive.go b/internal/build/archive.go index 2a7090c0d..ac680ba63 100644 --- a/internal/build/archive.go +++ b/internal/build/archive.go @@ -41,14 +41,14 @@ type Archive interface { Close() error } -func NewArchive(file *os.File) Archive { +func NewArchive(file *os.File) (Archive, string) { switch { case strings.HasSuffix(file.Name(), ".zip"): - return NewZipArchive(file) + return NewZipArchive(file), strings.TrimSuffix(file.Name(), ".zip") case strings.HasSuffix(file.Name(), ".tar.gz"): - return NewTarballArchive(file) + return NewTarballArchive(file), strings.TrimSuffix(file.Name(), ".tar.gz") default: - return nil + return nil, "" } } @@ -74,17 +74,24 @@ func AddFile(a Archive, file string) error { } // WriteArchive creates an archive containing the given files. -func WriteArchive(basename, ext string, files []string) error { - archfd, err := os.Create(basename + ext) +func WriteArchive(name string, files []string) (err error) { + archfd, err := os.Create(name) if err != nil { return err } - defer archfd.Close() - archive := NewArchive(archfd) + + defer func() { + archfd.Close() + // Remove the half-written archive on failure. + if err != nil { + os.Remove(name) + } + }() + archive, basename := NewArchive(archfd) if archive == nil { - return fmt.Errorf("unknown archive extension: %s", ext) + return fmt.Errorf("unknown archive extension") } - fmt.Println(basename + ext) + fmt.Println(name) if err := archive.Directory(basename); err != nil { return err } @@ -118,6 +125,7 @@ func (a *ZipArchive) Header(fi os.FileInfo) (io.Writer, error) { return nil, fmt.Errorf("can't make zip header: %v", err) } head.Name = a.dir + head.Name + head.Method = zip.Deflate w, err := a.zipw.CreateHeader(head) if err != nil { return nil, fmt.Errorf("can't add zip header: %v", err)