From 59f5b4190063b1014cb7a810f00eead52382c0d9 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 29 Jun 2013 13:52:01 -0700 Subject: [PATCH] Use make.go from dev-* scripts. Updates Issue 140. Change-Id: I0acea921e311b8228829dbad37ee502034c7dfe7 --- .gitignore | 1 - dev-camget | 6 ---- dev-camput | 6 ---- dev-server | 5 --- make.go | 85 ++++++++++++++++++++++++++++++++------------------ misc/devlib.pl | 44 +++++++++++++++----------- 6 files changed, 79 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 4b2d2a875..836faae07 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ build/root .DS_Store bin/cam* tmp -gopath server/camlistored/newui/all.js server/camlistored/newui/all.js.map server/camlistored/newui/zembed_all.js.go diff --git a/dev-camget b/dev-camget index 30235c058..7800ca722 100755 --- a/dev-camget +++ b/dev-camget @@ -5,12 +5,6 @@ use FindBin qw($Bin); use Getopt::Long; require "$Bin/misc/devlib.pl"; -unless ($ENV{GOPATH}) { - $ENV{GOPATH} = "$Bin/gopath" -} - -system("go", "install", "camlistore.org/cmd/camget") and die "failed to build camget"; - sub usage { die "Usage: dev-camget [--tls] -- camget_args"; } diff --git a/dev-camput b/dev-camput index 98dd10018..53c504ef3 100755 --- a/dev-camput +++ b/dev-camput @@ -5,12 +5,6 @@ use FindBin qw($Bin); use Getopt::Long; require "$Bin/misc/devlib.pl"; -unless ($ENV{GOPATH}) { - $ENV{GOPATH} = "$Bin/gopath" -} - -system("go", "install", "camlistore.org/cmd/camput") and die "failed to build camput"; - sub usage { die "Usage: dev-camput [--tls] -- camput_args"; } diff --git a/dev-server b/dev-server index 227d2cf0e..861004217 100755 --- a/dev-server +++ b/dev-server @@ -58,11 +58,6 @@ my $port = shift; $port = "3179" unless defined($port); usage() unless $port =~ /^\d+$/; -unless ($ENV{GOPATH}) { - warn "WARNING: Your GOPATH isn't set; attempting workaround, but you should really set a GOPATH. See https://plus.google.com/106356964679457436995/posts/ftJaqe9sbS2 and make your working directory be \$GOPATH/src/camlistore.org for best results.\n"; - $ENV{GOPATH} = "$Bin/gopath" -} - unless ($opt_fast) { $ENV{DEV_THROTTLE_KBPS} = $opt_KBps; $ENV{DEV_THROTTLE_LATENCY_MS} = $opt_latency_ms; diff --git a/make.go b/make.go index 4c378eb43..a43e10156 100644 --- a/make.go +++ b/make.go @@ -47,6 +47,8 @@ var ( all = flag.Bool("all", false, "Force rebuild of everything (go install -a)") verbose = flag.Bool("v", false, "Verbose mode") targets = flag.String("targets", "", "Optional comma-separated list of targets (i.e go packages) to build and install. Empty means all. Example: camlistore.org/server/camlistored,camlistore.org/cmd/camput") + quiet = flag.Bool("quiet", false, "Don't print anything unless there's a failure.") + ifModsSince = flag.Int64("if_mods_since", 0, "If non-zero return immediately without building if there aren't any filesystem modifications past this time (in unix seconds)") ) var ( @@ -67,9 +69,8 @@ func main() { log.Fatalf("Failed to get current directory: %v", err) } verifyCamlistoreRoot(camRoot) - verifyGoVersion() - sql := haveSQLite() + sql := *wantSQLite && haveSQLite() buildBaseDir := "build-gopath" if !sql { @@ -110,16 +111,26 @@ func main() { goDirs := []string{"cmd", "pkg", "server/camlistored", "third_party"} // Copy files we do want in our mirrored GOPATH. This has the side effect of // populating wantDestFile, populated by mirrorFile. + var latestSrcMod time.Time for _, dir := range goDirs { oriPath := filepath.Join(camRoot, filepath.FromSlash(dir)) dstPath := buildSrcPath(dir) - if err := mirrorDir(oriPath, dstPath); err != nil { + if maxMod, err := mirrorDir(oriPath, dstPath); err != nil { log.Fatalf("Error while mirroring %s to %s: %v", oriPath, dstPath, err) + } else { + if maxMod.After(latestSrcMod) { + latestSrcMod = maxMod + } } } - closureEmbed := buildSrcPath("server/camlistored/ui/closure/z_data.go") + verifyGoVersion() + if *embedResources { + if *verbose { + log.Printf("Embedding resources...") + } + closureEmbed := buildSrcPath("server/camlistored/ui/closure/z_data.go") closureSrcDir := filepath.Join(camRoot, filepath.FromSlash("third_party/closure/lib")) err := embedClosure(closureSrcDir, closureEmbed) if err != nil { @@ -175,37 +186,43 @@ func main() { "GOPATH="+buildGoPath, "GOBIN="+binDir, ) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + var output bytes.Buffer + if *quiet { + cmd.Stdout = &output + cmd.Stderr = &output + } else { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + } if *verbose { log.Printf("Running go install of main binaries with args %s", targs) } if err := cmd.Run(); err != nil { - log.Fatalf("Error building: %v", err) + log.Fatalf("Error building: %v\n%s", err, output.String()) } - if !buildAll { + + if buildAll { + // Now do another build, but including everything, just to make + // sure everything compiles. But if there are any binaries (package main) in here, + // put them in a junk GOBIN (the default location), rather than polluting + // the GOBIN that the user will look in. + cmd = exec.Command("go", append(baseArgs, + "camlistore.org/pkg/...", + "camlistore.org/server/...", + "camlistore.org/third_party/...", + )...) + cmd.Env = append(cleanGoEnv(), "GOPATH="+buildGoPath) + if *verbose { + log.Printf("Running full go install with args %s", args) + } + if err := cmd.Run(); err != nil { + log.Fatalf("Error building: %v", err) + } + } + + if !*quiet { log.Printf("Success. Binaries are in %s", binDir) - os.Exit(0) } - - // Now do another build, but including everything, just to make - // sure everything compiles. But if there are any binaries (package main) in here, - // put them in a junk GOBIN (the default location), rather than polluting - // the GOBIN that the user will look in. - cmd = exec.Command("go", append(baseArgs, - "camlistore.org/pkg/...", - "camlistore.org/server/...", - "camlistore.org/third_party/...", - )...) - cmd.Env = append(cleanGoEnv(), "GOPATH="+buildGoPath) - if *verbose { - log.Printf("Running full go install with args %s", args) - } - if err := cmd.Run(); err != nil { - log.Fatalf("Error building: %v", err) - } - - log.Printf("Success. Binaries are in %s", binDir) } // cleanGoEnv returns a copy of the current environment with GOPATH and GOBIN removed. @@ -338,8 +355,8 @@ func verifyGoVersion() { } } -func mirrorDir(src, dst string) error { - return filepath.Walk(src, func(path string, fi os.FileInfo, err error) error { +func mirrorDir(src, dst string) (maxMod time.Time, err error) { + err = filepath.Walk(src, func(path string, fi os.FileInfo, err error) error { if err != nil { return err } @@ -358,8 +375,12 @@ func mirrorDir(src, dst string) error { if err != nil { return fmt.Errorf("Failed to find Rel(%q, %q): %v", src, path, err) } + if t := fi.ModTime(); t.After(maxMod) { + maxMod = t + } return mirrorFile(path, filepath.Join(dst, suffix)) }) + return } var wantDestFile = make(map[string]bool) // full dest filename => true @@ -420,7 +441,9 @@ func deleteUnwantedOldMirrorFiles(dir string) { return nil } if !wantDestFile[path] { - log.Printf("Deleting old file from temp build dir: %s", path) + if !*quiet { + log.Printf("Deleting old file from temp build dir: %s", path) + } return os.Remove(path) } return nil diff --git a/misc/devlib.pl b/misc/devlib.pl index 4062e5fab..5c13a8ef9 100644 --- a/misc/devlib.pl +++ b/misc/devlib.pl @@ -1,19 +1,33 @@ use strict; - +use Time::HiRes (); use FindBin qw($Bin); sub build_bin { my $target = shift; - $ENV{GOBIN} = find_gobin(); - print STDERR "Building $target ...\n"; - system("go", "install", "-v", $target) and die "go install $target failed"; - $target =~ s!.+/!!; - my $bin = "$ENV{GOBIN}/$target"; - unless (-e $bin) { - die "Expected binary $bin doesn't exist after installing target $target\n"; + my $final_bin = find_bin($target); + + my $full_target = $target; + $full_target =~ s!^\./((cmd|server)/(\w+))$!camlistore.org/$1! or die "Bogus target $target"; + + my $mtime = 0; + if (-f $final_bin) { + $mtime = (stat($final_bin))[9]; } - system("chmod", "+x", $bin) unless -x $bin; - return $bin; + + print STDERR "Building $full_target ...\n"; + my $t0 = Time::HiRes::time(); + system("go", "run", "make.go", + "--quiet", + "--embed_static=false", + "--sqlite=false", + "--if_mods_since=$mtime", + "--targets=$full_target") + and die "go install $target failed"; + my $td = Time::HiRes::time() - $t0; + + print STDERR "Build/init took " . sprintf("%0.03f", $td) . " seconds.\n"; + + return $final_bin; } sub find_bin { @@ -24,15 +38,7 @@ sub find_bin { } sub find_gobin { - my $env = `go env`; - # Note: ignoring cross-compiling environments (GOHOSTOS, - # GOHOSTARCH) for now at least. - my ($GOARCH) = $env =~ /^GOARCH=\"(.+)\"/m; - my ($GOOS) = $env =~ /^GOOS=\"(.+)\"/m; - die "Failed to find GOARCH and/or GOOS" unless $GOARCH && $GOOS; - my $bin = "$Bin/gopath/bin/${GOOS}_${GOARCH}"; - mkdir $bin, 0755 unless -d $bin; - return $bin; + return "$Bin/bin"; } 1;