pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.2k stars 615 forks source link

compile: invalid value "go1.21.7" for -lang: should be something like "go1.12" #20723

Open jasonwbarnett opened 3 months ago

jasonwbarnett commented 3 months ago

Describe the bug When I had the following go.mod

module domain.com/package/path

go 1.21.7

require github.com/pelletier/go-toml v1.9.5

compiling the program via pants failed with this error:

compile: invalid value "go1.21.7" for -lang: should be something like "go1.12"

After updating the go.mod to this it worked:

module domain.com/package/path

go 1.21

require github.com/pelletier/go-toml v1.9.5

Pants version 2.21.0.dev3

OS Mac OS

tgolsson commented 3 months ago

Looked like #20677 but I think this is different. Likely fall-out from that.

tdyas commented 3 months ago

We probably need to make sure we only pass go1.X as a value to the -lang parameter.

tdyas commented 3 months ago

The relevant part of the code is https://github.com/pantsbuild/pants/blob/3200ee3c397ca9b7ed22310f4f77e37933554dc7/src/python/pants/backend/go/util_rules/build_pkg.py#L716-L720.

jasonwbarnett commented 3 months ago

The relevant part of the code is https://github.com/pantsbuild/pants/blob/3200ee3c397ca9b7ed22310f4f77e37933554dc7/src/python/pants/backend/go/util_rules/build_pkg.py#L716-L720.

Thanks. I'll try to post a fix in the next few days.

bndabbs commented 1 month ago

This looks like the error reported in https://github.com/golang/go/issues/66553.

Is it possible that Pants is caching golang.org/x/tools/gopls somewhere? If so then maybe the fix should be to install gopls using the resolved go_version?