From 62aed5a4275565fbb7fd48004fa937ee5d290b16 Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 14 Oct 2024 10:15:05 +0200 Subject: [PATCH] Use the major version of golang at package time --- src/python/pants/backend/go/util_rules/build_pkg.py | 2 +- src/python/pants/backend/go/util_rules/build_pkg_test.py | 2 +- src/python/pants/backend/go/util_rules/goroot.py | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/python/pants/backend/go/util_rules/build_pkg.py b/src/python/pants/backend/go/util_rules/build_pkg.py index ed76338088a4..91ff26fbef3b 100644 --- a/src/python/pants/backend/go/util_rules/build_pkg.py +++ b/src/python/pants/backend/go/util_rules/build_pkg.py @@ -715,7 +715,7 @@ async def build_go_package( # See https://github.com/golang/go/blob/f229e7031a6efb2f23241b5da000c3b3203081d6/src/cmd/go/internal/work/gc.go#L79-L100 # for where this logic comes from. - go_version = request.minimum_go_version or "1.16" + go_version = go_root.major_version(request.minimum_go_version or "1.16") if go_root.is_compatible_version(go_version): compile_args.extend(["-lang", f"go{go_version}"]) diff --git a/src/python/pants/backend/go/util_rules/build_pkg_test.py b/src/python/pants/backend/go/util_rules/build_pkg_test.py index be4d1f7e5dab..e38c638900f3 100644 --- a/src/python/pants/backend/go/util_rules/build_pkg_test.py +++ b/src/python/pants/backend/go/util_rules/build_pkg_test.py @@ -89,7 +89,7 @@ def test_build_pkg(rule_runner: RuleRunner) -> None: ).digest, s_files=(), direct_dependencies=(), - minimum_go_version=None, + minimum_go_version="1.21.2", ) direct_dep = BuildGoPackageRequest( import_path="example.com/foo/dep", diff --git a/src/python/pants/backend/go/util_rules/goroot.py b/src/python/pants/backend/go/util_rules/goroot.py index 5e2cc64b7aa2..5fa9e9707c7a 100644 --- a/src/python/pants/backend/go/util_rules/goroot.py +++ b/src/python/pants/backend/go/util_rules/goroot.py @@ -39,6 +39,11 @@ def is_compatible_version(self, version: str) -> bool: """Can this Go compiler handle the target version?""" return compatible_go_version(compiler_version=self.version, target_version=version) + def major_version(self, version: str) -> str: + _version_components = version.split(".") # e.g. [1, 17] or [1, 17, 1] + major_version = f"{_version_components[0]}.{_version_components[1]}" + return major_version + @property def full_version(self) -> str: return self._raw_metadata["GOVERSION"]