]> Cypherpunks.ru repositories - gostls13.git/commitdiff
make.bash, make.rc: fix GOROOT detection when GOEXPERIMENT is set
authorRuss Cox <rsc@golang.org>
Fri, 9 Dec 2022 20:09:46 +0000 (15:09 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 17 Jan 2023 22:30:56 +0000 (22:30 +0000)
We need to clear GOEXPERIMENT any time we are invoking a bootstrap
toolchain. One line missed the clearing of GOEXPERIMENT.

There were three different lines using different syntaxes and subtly
different sets of variables being cleared, so hoist them into a function
so it's all in one place.

Also quote $GOROOT_BOOTSTRAP consistently.

Change-Id: I6c5a5d70c694c24705bbc61298b28ae906c0cf6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/456635
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>

src/make.bash
src/make.rc

index c07f39bb40adaec419135887766aa34790480cb0..755b3b0b9ea13968be7dce5f0660c0c89705b2f3 100755 (executable)
@@ -162,16 +162,20 @@ if [ -z "$GOROOT_BOOTSTRAP" ]; then
 fi
 export GOROOT_BOOTSTRAP
 
+nogoenv() {
+       GO111MODULE=off GOENV=off GOOS= GOARCH= GOEXPERIMENT= GOFLAGS= "$@"
+}
+
 export GOROOT="$(cd .. && pwd)"
 IFS=$'\n'; for go_exe in $(type -ap go); do
        if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
-               goroot=$(GOROOT='' GOOS='' GOARCH='' "$go_exe" env GOROOT)
+               goroot=$(GOROOT= nogoenv "$go_exe" env GOROOT)
                if [ "$goroot" != "$GOROOT" ]; then
                        if [ "$goroot_bootstrap_set" = "true" ]; then
                                printf 'WARNING: %s does not exist, found %s from env\n' "$GOROOT_BOOTSTRAP/bin/go" "$go_exe" >&2
                                printf 'WARNING: set %s as GOROOT_BOOTSTRAP\n' "$goroot" >&2
                        fi
-                       GOROOT_BOOTSTRAP=$goroot
+                       GOROOT_BOOTSTRAP="$goroot"
                fi
        fi
 done; unset IFS
@@ -183,7 +187,7 @@ fi
 # Get the exact bootstrap toolchain version to help with debugging.
 # We clear GOOS and GOARCH to avoid an ominous but harmless warning if
 # the bootstrap doesn't support them.
-GOROOT_BOOTSTRAP_VERSION=$(GOOS= GOARCH= GOEXPERIMENT= $GOROOT_BOOTSTRAP/bin/go version | sed 's/go version //')
+GOROOT_BOOTSTRAP_VERSION=$(nogoenv "$GOROOT_BOOTSTRAP/bin/go" version | sed 's/go version //')
 echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP. ($GOROOT_BOOTSTRAP_VERSION)"
 if $verbose; then
        echo cmd/dist
@@ -194,7 +198,7 @@ if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then
        exit 1
 fi
 rm -f cmd/dist/dist
-GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" GO111MODULE=off GOEXPERIMENT="" GOENV=off GOFLAGS="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
+GOROOT="$GOROOT_BOOTSTRAP" nogoenv "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
 
 # -e doesn't propagate out of eval, so check success by hand.
 eval $(./cmd/dist/dist env -p || echo FAIL=true)
index e17ee316adf40c824df6425d841b4e0d21390b87..834c1f1ba692a4f5a323319f030ef98074be6048 100755 (executable)
@@ -47,6 +47,10 @@ if(~ $1 -v) {
        shift
 }
 
+fn nogoenv {
+       GO111MODULE=off GOENV=off GOOS=() GOARCH=() GOEXPERIMENT=() GOFLAGS=() $*
+}
+
 bootgo = 1.17.13
 GOROOT = `{cd .. && pwd}
 goroot_bootstrap_set = 'true'
@@ -60,7 +64,7 @@ if(! ~ $#GOROOT_BOOTSTRAP 1){
 for(p in $path){
        if(! test -x $GOROOT_BOOTSTRAP/bin/go){
                if(go_exe = `{path=$p whatis go}){
-                       goroot = `{GOROOT='' $go_exe env GOROOT}
+                       goroot = `{GOROOT=() nogoenv $go_exe env GOROOT}
                        if(! ~ $goroot $GOROOT){
                                if(~ $goroot_bootstrap_set 'true'){
                                        echo 'WARNING: '$GOROOT_BOOTSTRAP'/bin/go does not exist, found '$go_exe' from env' >[1=2]
@@ -85,11 +89,11 @@ if(~ $GOROOT_BOOTSTRAP $GOROOT){
 # Get the exact bootstrap toolchain version to help with debugging.
 # We clear GOOS and GOARCH to avoid an ominous but harmless warning if
 # the bootstrap doesn't support them.
-GOROOT_BOOTSTRAP_VERSION=`{GOOS='' GOARCH='' GOEXPERIMENT='' $GOROOT_BOOTSTRAP/bin/go version | sed 's/go version //'}
+GOROOT_BOOTSTRAP_VERSION=`{nogoenv $GOROOT_BOOTSTRAP/bin/go version | sed 's/go version //'}
 echo 'Building Go cmd/dist using '$GOROOT_BOOTSTRAP'. ('$"GOROOT_BOOTSTRAP_VERSION')'
 if(~ $#vflag 1)
        echo cmd/dist
-GOROOT=$GOROOT_BOOTSTRAP GOOS='' GOARCH='' GOEXPERIMENT='' GO111MODULE=off GOENV=off GOFLAGS='' $GOROOT_BOOTSTRAP/bin/go build -o cmd/dist/dist ./cmd/dist
+GOROOT=$GOROOT_BOOTSTRAP nogoenv $GOROOT_BOOTSTRAP/bin/go build -o cmd/dist/dist ./cmd/dist
 
 eval `{./cmd/dist/dist env -9}
 if(~ $#vflag 1)