Skip to content

Commit dc3b35c

Browse files
committed
build: set gotoolchain to goversion when first is missing in go.mod
Signed-off-by: Artur Troian <[email protected]>
1 parent 89f33c4 commit dc3b35c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

script/tools.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macos_deps=(
1414

1515
debian_deps=(
1616
"make"
17-
"build-essentials"
17+
"build-essential"
1818
"direnv"
1919
"unzip"
2020
"wget"
@@ -32,15 +32,28 @@ function get_gotoolchain() {
3232
local gotoolchain
3333
local goversion
3434
local local_goversion
35+
local toolfile
3536

36-
gotoolchain=$(grep -E '^toolchain go[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$' <"$gomod" | cut -d ' ' -f 2 | tr -d '\n')
37-
goversion=$(grep -E '^go [0-9]{1,}.[0-9]{1,}(.[0-9]{1,})?$' <"$gomod" | cut -d ' ' -f 2 | tr -d '\n')
37+
set -x
38+
39+
toolfile=$gomod
40+
41+
if [[ "$GOWORK" != "off" ]]; then
42+
toolfile=$GOWORK
43+
fi
44+
45+
gotoolchain=$(grep -E '^toolchain go[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n')
46+
goversion=$(grep -E '^go [0-9]{1,}.[0-9]{1,}(.[0-9]{1,})?$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n')
47+
48+
if [[ ${gotoolchain} == "" ]]; then
49+
gotoolchain=$goversion
50+
fi
3851

3952
if [[ ${gotoolchain} == "" ]]; then
4053
# determine go toolchain from go version in go.mod
4154
if which go >/dev/null 2>&1; then
42-
local_goversion=$(GOTOOLCHAIN=local go version | cut -d ' ' -f 3 | sed 's/go*//' | tr -d '\n')
43-
if [[ $($SEMVER compare "v$local_goversion" v"$goversion") -ge 0 ]]; then
55+
local_goversion=$(env -i HOME=$HOME GOTOOLCHAIN=local $SHELL -l -c "go version | cut -d ' ' -f 3 | sed 's/go*//' | tr -d '\n'")
56+
if ! [[ $($SEMVER compare "v$local_goversion" v"$goversion") -ge 0 ]]; then
4457
goversion=$local_goversion
4558
else
4659
local_goversion=
@@ -54,7 +67,7 @@ function get_gotoolchain() {
5467
if [[ $goversion != "" ]] && [[ $($SEMVER compare "v$goversion" v1.21.0) -ge 0 ]]; then
5568
gotoolchain=go${goversion}
5669
else
57-
gotoolchain=go$(grep -E '^go [0-9]{1,}.[0-9]{1,}$' <"$gomod" | cut -d ' ' -f 2 | tr -d '\n').0
70+
gotoolchain=go$(grep -E '^go [0-9]{1,}.[0-9]{1,}$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n').0
5871
fi
5972
fi
6073

0 commit comments

Comments
 (0)