aboutsummaryrefslogtreecommitdiffhomepage
path: root/loader/list.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-01-19 13:11:38 +0100
committerNia <[email protected]>2022-01-19 12:44:07 -0500
commitd054d4d5123d4ecc5c691ab103a4062513a90b51 (patch)
treec0f70c1e171475da86129592c855d17f4e61d3df /loader/list.go
parente7e1b755c977d01ae71a34a3dfc0e017303c124d (diff)
downloadtinygo-d054d4d5123d4ecc5c691ab103a4062513a90b51.tar.gz
tinygo-d054d4d5123d4ecc5c691ab103a4062513a90b51.zip
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.
Diffstat (limited to 'loader/list.go')
-rw-r--r--loader/list.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/loader/list.go b/loader/list.go
index e33f34e4e..3c8226eaf 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
}