mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 19:23:25 +00:00
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.
This commit is contained in:
+3
-1
@@ -3,9 +3,11 @@ package loader
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tinygo-org/tinygo/compileopts"
|
"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
|
// 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() {
|
if config.CgoEnabled() {
|
||||||
cgoEnabled = "1"
|
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)
|
cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled)
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user