Skip to content

Commit 73f7823

Browse files
committed
Improve consistency by prefering bazel_dep over Go
Letting the bazel_dep and Go dependency participate equally in the version resolution is creating various inconsistencies. This can lead to to a root module having to either use `inject_repo` or `use_repo` and `override_repo`. Resolve this by consistently preferring the `bazel_dep` over the Go dependency. Keep the existing code that warns (or can fail) if the dependencies are at different versions. Example MODULE.bazel: ``` module( name = "bazel_dep_should_win", ) bazel_dep(name = "rules_go", version = "0.53.0") bazel_dep(name = "gazelle", version = "0.42.0") bazel_dep(name = "circl", version = "1.3.8") go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") ``` And the go.mod referring to a newer version. Fixes #2060
1 parent ba7eba9 commit 73f7823

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

internal/bzlmod/go_deps.bzl

+2-7
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,8 @@ def _go_deps_impl(module_ctx):
566566

567567
bazel_dep_is_older = path in module_resolutions and bazel_dep.version < module_resolutions[path].version
568568

569-
# Version mismatches between the Go module and the bazel_dep can confuse Go tooling. If the bazel_dep version
570-
# is lower, it won't be used, which can result in unexpected builds and should thus always be reported, even for
571-
# indirect deps. Explicitly overridden modules are not reported as this requires manual action.
569+
# Version mismatches between the Go module and the bazel_dep are problematic. For consistency always
570+
# prefer the bazel_dep version and report any mismatch to the user.
572571
if (path in module_resolutions and
573572
bazel_dep.version != module_resolutions[path].version and
574573
bazel_dep.version != _HIGHEST_VERSION_SENTINEL and
@@ -620,10 +619,6 @@ Mismatch between versions requested for Go module {module}:
620619
go_module_version = go_module_version,
621620
), *remediation)
622621

623-
# Only use the Bazel module if it is at least as high as the required Go module version.
624-
if bazel_dep_is_older:
625-
continue
626-
627622
# TODO: We should update root_versions if the bazel_dep is a direct dependency of the root
628623
# module. However, we currently don't have a way to determine that.
629624
module_resolutions[path] = bazel_dep

tests/bcr/go_mod/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/bazelbuild/rules_go v0.39.1
1414
// NOTE: keep <4.7.0 to test the 'replace'
1515
github.com/bmatcuk/doublestar/v4 v4.6.0
16-
github.com/cloudflare/circl v1.3.7
16+
github.com/cloudflare/circl v1.6.1
1717
github.com/envoyproxy/protoc-gen-validate v1.0.1
1818
github.com/fmeum/dep_on_gazelle v1.0.0
1919
github.com/google/go-jsonnet v0.20.0

tests/bcr/go_mod/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
1717
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1818
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
1919
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
20+
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
21+
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
2022
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2123
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2224
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

tests/bcr/go_work/pkg/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/bazelbuild/rules_go v0.44.0
1010
// NOTE: keep <4.7.0 to test the 'replace'
1111
github.com/bmatcuk/doublestar/v4 v4.6.1
12-
github.com/cloudflare/circl v1.3.7
12+
github.com/cloudflare/circl v1.6.1
1313
github.com/envoyproxy/protoc-gen-validate v1.0.4
1414
github.com/fmeum/dep_on_gazelle v1.0.0
1515
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f

tests/bcr/go_work/pkg/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
1717
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1818
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
1919
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
20+
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
21+
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
2022
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2123
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2224
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)