From e075e0591d555d3e657858f5186627f412dd500f Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 23 May 2023 15:18:34 +0200 Subject: 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. --- compiler/compiler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 6b5fbe13c..9675c4028 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -29,7 +29,7 @@ func TestCompiler(t *testing.T) { t.Parallel() // Determine Go minor version (e.g. 16 in go1.16.3). - _, goMinor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) + _, goMinor, err := goenv.GetGorootVersion() if err != nil { t.Fatal("could not read Go version:", err) } -- cgit v1.2.3