Skip to content

Commit ab35040

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 ab35040

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

script/tools.sh

Lines changed: 17 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,26 @@ 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+
toolfile=$gomod
38+
39+
if [[ "$GOWORK" != "off" ]] && [ -f "$GOWORK" ]; then
40+
toolfile=$GOWORK
41+
fi
42+
43+
gotoolchain=$(grep -E '^toolchain go[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n')
44+
goversion=$(grep -E '^go [0-9]{1,}.[0-9]{1,}(.[0-9]{1,})?$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n')
45+
46+
if [[ ${gotoolchain} == "" ]]; then
47+
gotoolchain=$goversion
48+
fi
3849

3950
if [[ ${gotoolchain} == "" ]]; then
4051
# determine go toolchain from go version in go.mod
4152
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
53+
local_goversion=$(env -i HOME=$HOME GOTOOLCHAIN=local $SHELL -l -c "go version | cut -d ' ' -f 3 | sed 's/go*//' | tr -d '\n'")
54+
if ! [[ $($SEMVER compare "v$local_goversion" v"$goversion") -ge 0 ]]; then
4455
goversion=$local_goversion
4556
else
4657
local_goversion=
@@ -54,7 +65,7 @@ function get_gotoolchain() {
5465
if [[ $goversion != "" ]] && [[ $($SEMVER compare "v$goversion" v1.21.0) -ge 0 ]]; then
5566
gotoolchain=go${goversion}
5667
else
57-
gotoolchain=go$(grep -E '^go [0-9]{1,}.[0-9]{1,}$' <"$gomod" | cut -d ' ' -f 2 | tr -d '\n').0
68+
gotoolchain=go$(grep -E '^go [0-9]{1,}.[0-9]{1,}$' <"$toolfile" | cut -d ' ' -f 2 | tr -d '\n').0
5869
fi
5970
fi
6071

0 commit comments

Comments
 (0)