mirror of https://github.com/perkeep/perkeep.git
Use make.go from dev-* scripts. Updates Issue 140.
Change-Id: I0acea921e311b8228829dbad37ee502034c7dfe7
This commit is contained in:
parent
8b4ebd59b7
commit
59f5b41900
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
45
make.go
45
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,19 +186,22 @@ func main() {
|
|||
"GOPATH="+buildGoPath,
|
||||
"GOBIN="+binDir,
|
||||
)
|
||||
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)
|
||||
}
|
||||
if !buildAll {
|
||||
log.Printf("Success. Binaries are in %s", binDir)
|
||||
os.Exit(0)
|
||||
log.Fatalf("Error building: %v\n%s", err, output.String())
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -204,9 +218,12 @@ func main() {
|
|||
if err := cmd.Run(); err != nil {
|
||||
log.Fatalf("Error building: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !*quiet {
|
||||
log.Printf("Success. Binaries are in %s", binDir)
|
||||
}
|
||||
}
|
||||
|
||||
// cleanGoEnv returns a copy of the current environment with GOPATH and GOBIN removed.
|
||||
func cleanGoEnv() (clean []string) {
|
||||
|
@ -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] {
|
||||
if !*quiet {
|
||||
log.Printf("Deleting old file from temp build dir: %s", path)
|
||||
}
|
||||
return os.Remove(path)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue