aboutsummaryrefslogtreecommitdiffhomepage
path: root/builder
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-05-23 15:18:34 +0200
committerRon Evans <[email protected]>2023-07-07 16:55:59 +0200
commite075e0591d555d3e657858f5186627f412dd500f (patch)
treeab94fd1e066c033ab93c88120b271b326336dee6 /builder
parent46d2696363271dc3ca11d0672b255b25d72afbc2 (diff)
downloadtinygo-e075e0591d555d3e657858f5186627f412dd500f.tar.gz
tinygo-e075e0591d555d3e657858f5186627f412dd500f.zip
main: use `go env` instead of doing all detection manually
This replaces our own manual detection of various variables (GOROOT, GOPATH, Go version) with a simple call to `go env`. If the `go` command is not found: error: could not find 'go' command: executable file not found in $PATH If the Go version is too old: error: requires go version 1.18 through 1.20, got go1.17 If the Go tool itself outputs an error (using GOROOT=foobar here): go: cannot find GOROOT directory: foobar This does break the case where `go` wasn't available in $PATH but we would detect it anyway (via some hardcoded OS-dependent paths). I'm not sure we want to fix that: I think it's better to tell users "make sure `go version` prints the right value" than to do some automagic detection of Go binary locations.
Diffstat (limited to 'builder')
-rw-r--r--builder/config.go10
1 files changed, 2 insertions, 8 deletions
diff --git a/builder/config.go b/builder/config.go
index f9fe715b7..1ca3aa641 100644
--- a/builder/config.go
+++ b/builder/config.go
@@ -1,7 +1,6 @@
package builder
import (
- "errors"
"fmt"
"github.com/tinygo-org/tinygo/compileopts"
@@ -24,14 +23,9 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
spec.OpenOCDCommands = options.OpenOCDCommands
}
- goroot := goenv.Get("GOROOT")
- if goroot == "" {
- return nil, errors.New("cannot locate $GOROOT, please set it manually")
- }
-
- major, minor, err := goenv.GetGorootVersion(goroot)
+ major, minor, err := goenv.GetGorootVersion()
if err != nil {
- return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err)
+ return nil, err
}
if major != 1 || minor < 18 || minor > 20 {
// Note: when this gets updated, also update the Go compatibility matrix: