From 50810b3da7f1b0c5b5187a1ca313fd9e88f53d32 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 30 Oct 2011 12:03:51 -0700 Subject: [PATCH] build: use our own isolated Go build root. now everything is in /build/root. will be necessary for other upcoming build changes. Change-Id: I141c12c4097253d18e69175b6471a7c47430764f --- .gitignore | 1 + .last_go_version | 2 +- build.pl | 51 +++++++++++++++++++++++++++++++++++++- build/print-go-osarch.Make | 7 ++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 build/print-go-osarch.Make diff --git a/.gitignore b/.gitignore index 05a870fca..8acbd3a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ clients/go/camgsinit/camgsinit clients/go/camwebdav/camwebdav .goroot appengine-sdk +build/root diff --git a/.last_go_version b/.last_go_version index 58b83b45b..743e380bd 100644 --- a/.last_go_version +++ b/.last_go_version @@ -1 +1 @@ -6g version release.r60.2 9925 +6g version release.r60.3 9516 diff --git a/build.pl b/build.pl index ef5819719..d921a620b 100755 --- a/build.pl +++ b/build.pl @@ -62,6 +62,7 @@ EOM ; } +my ($GOOS, $GOARCH, $CAMLIROOT, $CAMPKGDIR); # initialized by perform_go_check setup_environment_from_goroot_symlink(); my %built; # target -> bool (was it already built?) @@ -263,6 +264,40 @@ sub perform_go_check() { last; } die "No 6g or 8g found in your \$PATH.\n" unless -x $gc_bin; + + ($GOOS, $GOARCH) = get_os_arch(); + $CAMLIROOT = "$FindBin::Bin/build/root"; + $CAMPKGDIR = "$CAMLIROOT/pkg/${GOOS}_${GOARCH}"; + + mkdir $CAMLIROOT, 0755; + mkdir "$CAMLIROOT/pkg", 0755; + mkdir $CAMPKGDIR, 0755; + my $realroot = "$ENV{GOROOT}/pkg/${GOOS}_${GOARCH}"; + make_symlink("$ENV{GOROOT}/src", "$CAMLIROOT/src"); + if (opendir(my $d, $realroot)) { + my @files = grep { /^\w+(\.a)?$/ } readdir($d); + my @old_cam_files = grep { /^camli/ } @files; + if (@old_cam_files) { + die "Camlistore's build system changed and now uses its own \$GOROOT (build/root/*).\n\n" . + "To proceed, first remove the following old build artifacts in $realroot: @old_cam_files\n\n"; + } + for my $f (@files) { + my $old = "$realroot/$f"; + my $new = "$CAMPKGDIR/$f"; + make_symlink($old, $new); + } + } + + return 1; +} + +sub make_symlink { + my ($old, $new) = @_; + $old =~ s!/+!/!g; + unless (-e $new && readlink($new) eq $old) { + unlink($new); + symlink($old, $new) or die "failed to symlink $old to $new"; + } return 1; } @@ -286,6 +321,8 @@ sub test { my @test_files = grep { /_test\.go$/ } readdir($dh); closedir($dh); if (@test_files) { + local $ENV{GOROOT} = $CAMLIROOT; + if ($target =~ m!\blib/go\b!) { my @quiet = ("--silent"); @quiet = () if $opt_verbose; @@ -495,13 +532,16 @@ sub gen_target_makefile { my $mfc = "\n\n"; $mfc .= "###### NOTE: THIS IS AUTO-GENERATED FROM build.pl IN THE ROOT; DON'T EDIT\n"; $mfc .= "\n\n"; + $mfc .= "TARGDIR=$CAMPKGDIR\n"; + $mfc .= "GCIMPORTS=-I $CAMPKGDIR\n"; + $mfc .= "LDIMPORTS=-L $CAMPKGDIR\n"; $mfc .= "include \$(GOROOT)/src/Make.inc\n"; my $pr = ""; if (@deps) { foreach my $dep (@deps) { my $cam_lib = $dep; $cam_lib =~ s!^lib/go/!!; - $pr .= '$(QUOTED_GOROOT)/pkg/$(GOOS)_$(GOARCH)/' . $cam_lib . ".a\\\n\t"; + $pr .= $CAMPKGDIR . '/' . $cam_lib . ".a\\\n\t"; } chop $pr; chop $pr; chop $pr; } @@ -639,6 +679,15 @@ sub setup_environment_from_goroot_symlink { } $ENV{"GOROOT"} = $root; $ENV{"PATH"} = "$root/bin:$ENV{PATH}"; + perform_go_check(); +} + +sub get_os_arch { + my $out = `make -f $FindBin::Bin/build/print-go-osarch.Make`; + die "Failed to find GOOS and GOARCH." unless $out; + my ($os) = $out =~ /GOOS=(.+)/ or die "didn't find GOOS"; + my ($arch) = $out =~ /GOARCH=(.+)/ or die "didn't find GOARCH"; + return ($os, $arch) } __DATA__ diff --git a/build/print-go-osarch.Make b/build/print-go-osarch.Make new file mode 100644 index 000000000..e3c9c96aa --- /dev/null +++ b/build/print-go-osarch.Make @@ -0,0 +1,7 @@ + +include $(GOROOT)/src/Make.inc + +all: + @echo "GOOS=$(GOOS)" + @echo "GOARCH=$(GOARCH)" +