build: for default bootstrap, use Go 1.17 if present, falling back to Go 1.4

Preparation for #44505, but safe for Go 1.18.
Also fixes the default build on Macs, at least for
people who have a $HOME/go1.17 or have run

	go install golang.org/dl/go1.17@latest
	go1.17 download

Replay of CL 369914 after revert in CL 370138.
Only change is adding 'export GOROOT_BOOTSTRAP' in make.bash.

Change-Id: I8ced4e87a9dc0f05cc49095578b401ae6212ac85
Reviewed-on: https://go-review.googlesource.com/c/go/+/370274
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2021-12-06 13:36:42 -05:00
parent 46db6aa157
commit f5b5939c28
4 changed files with 27 additions and 2 deletions

View File

@ -93,10 +93,21 @@ var ignoreSuffixes = []string{
"_test.go", "_test.go",
} }
var tryDirs = []string{
"sdk/go1.17",
"go1.17",
}
func bootstrapBuildTools() { func bootstrapBuildTools() {
goroot_bootstrap := os.Getenv("GOROOT_BOOTSTRAP") goroot_bootstrap := os.Getenv("GOROOT_BOOTSTRAP")
if goroot_bootstrap == "" { if goroot_bootstrap == "" {
goroot_bootstrap = pathf("%s/go1.4", os.Getenv("HOME")) home := os.Getenv("HOME")
goroot_bootstrap = pathf("%s/go1.4", home)
for _, d := range tryDirs {
if p := pathf("%s/%s", home, d); isdir(p) {
goroot_bootstrap = p
}
}
} }
xprintf("Building Go toolchain1 using %s.\n", goroot_bootstrap) xprintf("Building Go toolchain1 using %s.\n", goroot_bootstrap)

View File

@ -153,7 +153,16 @@ if [ "$1" = "-v" ]; then
fi fi
goroot_bootstrap_set=${GOROOT_BOOTSTRAP+"true"} goroot_bootstrap_set=${GOROOT_BOOTSTRAP+"true"}
export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4} if [ -z "$GOROOT_BOOTSTRAP" ]; then
GOROOT_BOOTSTRAP="$HOME/go1.4"
for d in sdk/go1.17 go1.17; do
if [ -d "$HOME/$d" ]; then
GOROOT_BOOTSTRAP="$HOME/$d"
fi
done
fi
export GOROOT_BOOTSTRAP
export GOROOT="$(cd .. && pwd)" export GOROOT="$(cd .. && pwd)"
IFS=$'\n'; for go_exe in $(type -ap go); do IFS=$'\n'; for go_exe in $(type -ap go); do
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then

View File

@ -83,6 +83,8 @@ for /f "tokens=*" %%g in ('where go 2^>nul') do (
) )
) )
) )
if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\go1.17" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\go1.17
if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\sdk\go1.17" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\sdk\go1.17
if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4 if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4
:bootstrapset :bootstrapset

View File

@ -55,6 +55,9 @@ goroot_bootstrap_set = 'true'
if(! ~ $#GOROOT_BOOTSTRAP 1){ if(! ~ $#GOROOT_BOOTSTRAP 1){
goroot_bootstrap_set = 'false' goroot_bootstrap_set = 'false'
GOROOT_BOOTSTRAP = $home/go1.4 GOROOT_BOOTSTRAP = $home/go1.4
for(d in sdk/go1.17 go1.17)
if(test -d $home/$d)
GOROOT_BOOTSTRAP = $home/$d
} }
for(p in $path){ for(p in $path){
if(! test -x $GOROOT_BOOTSTRAP/bin/go){ if(! test -x $GOROOT_BOOTSTRAP/bin/go){