Skip to content

Commit a164a2f

Browse files
crvvianlancetaylor
authored andcommitted
build: add go env GOROOT as default GOROOT_BOOTSTRAP value
This change also added the same check in make.bash to make.rc, which makes sure $GOROOT_BOOTSTRAP != $GOROOT. Fixes golang#14339 Change-Id: I2758f4a845bae42ace02492fc6a911f6d6247d26 Reviewed-on: https://go-review.googlesource.com/57753 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 3d62000 commit a164a2f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/make.bash

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ rm -f ./runtime/runtime_defs.go
119119
echo '##### Building Go bootstrap tool.'
120120
echo cmd/dist
121121
export GOROOT="$(cd .. && pwd)"
122-
GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
122+
export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
123+
for go_exe in $(type -ap go); do
124+
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
125+
goroot=$(GOROOT='' $go_exe env GOROOT)
126+
if [ "$goroot" != "$GOROOT" ]; then
127+
GOROOT_BOOTSTRAP=$goroot
128+
fi
129+
fi
130+
done
123131
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
124132
echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
125133
echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2

src/make.rc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,26 @@ echo cmd/dist
4646
GOROOT = `{cd .. && pwd}
4747
if(! ~ $#GOROOT_BOOTSTRAP 1)
4848
GOROOT_BOOTSTRAP = $home/go1.4
49+
for(p in $path){
50+
if(! test -x $GOROOT_BOOTSTRAP/bin/go){
51+
if(go_exe = `{path=$p whatis go}){
52+
goroot = `{GOROOT='' $go_exe env GOROOT}
53+
if(! ~ $goroot $GOROOT){
54+
GOROOT_BOOTSTRAP = $goroot
55+
}
56+
}
57+
}
58+
}
4959
if(! test -x $GOROOT_BOOTSTRAP/bin/go){
5060
echo 'ERROR: Cannot find '$GOROOT_BOOTSTRAP'/bin/go.' >[1=2]
5161
echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.' >[1=2]
5262
exit bootstrap
5363
}
64+
if(~ $GOROOT_BOOTSTRAP $GOROOT){
65+
echo 'ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT' >[1=2]
66+
echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.' >[1=2]
67+
exit bootstrap
68+
}
5469
rm -f cmd/dist/dist
5570
GOROOT=$GOROOT_BOOTSTRAP GOOS='' GOARCH='' $GOROOT_BOOTSTRAP/bin/go build -o cmd/dist/dist ./cmd/dist
5671

0 commit comments

Comments
 (0)