From d054d4d5123d4ecc5c691ab103a4062513a90b51 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 19 Jan 2022 13:11:38 +0100 Subject: [PATCH] loader: respect $GOROOT when running `go list` This makes it possible to select the Go version using GOROOT, and works even if the `go` binary is not in $PATH. --- loader/list.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loader/list.go b/loader/list.go index e33f34e4..3c8226ea 100644 --- a/loader/list.go +++ b/loader/list.go @@ -3,9 +3,11 @@ package loader import ( "os" "os/exec" + "path/filepath" "strings" "github.com/tinygo-org/tinygo/compileopts" + "github.com/tinygo-org/tinygo/goenv" ) // List returns a ready-to-run *exec.Cmd for running the `go list` command with @@ -24,7 +26,7 @@ func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, erro if config.CgoEnabled() { cgoEnabled = "1" } - cmd := exec.Command("go", args...) + cmd := exec.Command(filepath.Join(goenv.Get("GOROOT"), "bin", "go"), args...) cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled) return cmd, nil }