Skip to content

Go version check is not portable #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paralin opened this issue Apr 10, 2021 · 4 comments
Closed

Go version check is not portable #1018

paralin opened this issue Apr 10, 2021 · 4 comments
Labels
NeedsHelp Community contributions are welcome for this feature!

Comments

@paralin
Copy link
Contributor

paralin commented Apr 10, 2021

Running Gentoo, the following version check fails:

GopherJS 1.16.0+go1.16.3 requires a Go 1.16.x distribution, but failed to read its VERSION file: open /usr/lib/go/VERSION: no such file or directory

at compiler/version_check.go:22

The gentoo install doesn't create a VERSION file.

@nevkontakte
Copy link
Member

Thanks for the report.

Unfortunately, I don't have access to Gentoo to investigate a solution myself, but as a workaround you can create a VERSION file with go1.16.3 in it (no new line), assuming that's the Go version you have. If you are interested in contributing a version check that would also work on Gentoo, it would be very welcome.

@nevkontakte nevkontakte added the NeedsHelp Community contributions are welcome for this feature! label Apr 10, 2021
@paralin
Copy link
Contributor Author

paralin commented Apr 10, 2021

I think that this might be better, just assume that they installed GopherJS using the same version of Go as the one they are trying to run:

Subject: [PATCH] compiler: fix version check on gentoo

---
 compiler/version_check.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compiler/version_check.go b/compiler/version_check.go
index cc6e3f3..b9830d8 100644
--- a/compiler/version_check.go
+++ b/compiler/version_check.go
@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"path/filepath"
+	"runtime"
 )
 
 // Version is the GopherJS compiler version string.
@@ -21,7 +22,8 @@ const GoVersion = 16
 func CheckGoVersion(goroot string) error {
 	v, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION"))
 	if err != nil {
-		return fmt.Errorf("GopherJS %s requires a Go 1.16.x distribution, but failed to read its VERSION file: %v", Version, err)
+		v = []byte(runtime.Version())
+		// return fmt.Errorf("GopherJS %s requires a Go 1.16.x distribution, but failed to read its VERSION file: %v", Version, err)
 	}
 	if !bytes.HasPrefix(v, []byte("go1.16")) {
 		return fmt.Errorf("GopherJS %s requires a Go 1.16.x distribution, but found version %s", Version, v)
-- 
2.31.1


@flimzy
Copy link
Member

flimzy commented Apr 11, 2021

I wonder if this solution would break GOPHERJS_GOROOT usage. Maybe a safer solution would be to provide some sort of command-line flag to ignore the version check?

@nevkontakte
Copy link
Member

Yeah, because we now explicitly support building GopherJS tool with a different Go version than the one to be used by GopherJS build itself, this isn't a very safe fallback.

So in my private fork I have this change, which allows to bypass the check by setting an environment variable. This is convenient for GopherJS development, but I think this is not very good for users, who'd have to set yet another variable even if they didn't do anything wrong per se (using your distribution's Go version should be supported).

Probably the safest option would be to to execute $goroot/bin/go version and parse that. This is marginally more code, and is a bit slower than reading a single text file, but such fallback should work with any valid Go install.

@flimzy flimzy closed this as completed in 1c5f51f Sep 18, 2021
dmitshur added a commit that referenced this issue Oct 22, 2023
As of Go 1.21, the VERSION file has additional metadata after the first
line. Use only the text on the first line when reporting the Go version.

For #1018.
dmitshur added a commit that referenced this issue Oct 23, 2023
As of Go 1.21, the VERSION file has additional metadata after the first
line. Use only the text on the first line when reporting the Go version.

For #1018.

GitHub-Pull-Request: #1236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsHelp Community contributions are welcome for this feature!
Projects
None yet
Development

No branches or pull requests

3 participants