From a2ef1953d4070c933ac2d2f6be025ba6df16b9a4 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 8 Sep 2022 16:00:48 -0400 Subject: [PATCH 1/5] Add a version consistency check Extract the version from version.bzl using sed. For MODULE.bazel, we need to use buildifier to avoid confusion between skylib's version and our dependencies' versions. --- MODULE.bazel | 7 +++++++ WORKSPACE | 24 +++++++++++++++++++++++- tests/BUILD | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 698c698b..274c6dac 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -31,3 +31,10 @@ use_repo(go_deps, "com_github_bazelbuild_buildtools") bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.1") bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.5.1") bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.1") + +# needed by buildozer +go_deps.module( + path = "github.com/golang/protobuf", + sum = "h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=", + version = "v1.5.0", +) diff --git a/WORKSPACE b/WORKSPACE index 6a846532..2e71be2c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -80,6 +80,28 @@ http_archive( # Another Gazelle repository hint. # gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") gazelle_dependencies() + +# Buildozer & deps +http_archive( + name = "com_google_protobuf", + sha256 = "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a", + strip_prefix = "protobuf-3.19.2", + urls = [ + "https://github.com/protocolbuffers/protobuf/archive/v3.19.2.tar.gz", + ], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +go_repository( + name = "com_github_bazelbuild_buildtools", + build_naming_convention = "go_default_library", + importpath = "github.com/bazelbuild/buildtools", + sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=", + version = "v0.0.0-20220531122519-a43aed7014c8" +) \ No newline at end of file diff --git a/tests/BUILD b/tests/BUILD index bbab077a..01668468 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -1,4 +1,5 @@ load("//:bzl_library.bzl", "bzl_library") +load("//rules:diff_test.bzl", "diff_test") load(":build_test_tests.bzl", "build_test_test_suite") load(":collections_tests.bzl", "collections_test_suite") load(":dicts_tests.bzl", "dicts_test_suite") @@ -100,3 +101,25 @@ sh_test( name = "shell_spawn_e2e_test", srcs = [":shell_spawn_e2e_test_src"], ) + +genrule( + name = "version_from_module.bazel", + srcs = ["//:MODULE.bazel"], + outs = ["version_from_module.bazel.out"], + cmd = "cat '$<' | $(location @com_github_bazelbuild_buildtools//buildozer) 'print version' '-:bazel_skylib' > '$@'", + tools = ["@com_github_bazelbuild_buildtools//buildozer"], +) + +genrule( + name = "version_from_version.bzl", + srcs = ["//:version.bzl"], + outs = ["version_from_version.bzl.out"], + cmd = "sed -n 's/ *version = \"\\(.*\\)\"/\\1/p' '$<' > '$@'", +) + +diff_test( + name = "bazel_skylib_version_consistency_test", + failure_message = "The values of 'version' in version.bzl and MODULE.bazel do not match", + file1 = ":version_from_module.bazel", + file2 = ":version_from_version.bzl", +) From 79e395304f0df7254c174eef705aa16f2b893bce Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 12 Sep 2022 11:57:29 -0400 Subject: [PATCH 2/5] Update rules_go dep to 0.35.0 to fix bzlmod build --- MODULE.bazel | 2 +- WORKSPACE | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 274c6dac..d4cde2ef 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,7 +14,7 @@ bazel_dep(name = "platforms", version = "0.0.4") ### INTERNAL ONLY - lines after this are not included in the release packaging. # Gazelle extension is experimental -bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.33.0") +bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0") bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.26.0") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") diff --git a/WORKSPACE b/WORKSPACE index 2e71be2c..bd2c091b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,10 +6,10 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") maybe( name = "io_bazel_rules_go", repo_rule = http_archive, - sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369", + sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", ], ) @@ -17,7 +17,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe go_rules_dependencies() -go_register_toolchains(version = "1.17.1") +go_register_toolchains(version = "1.19.1") # Below this line is for documentation generation only, # and should thus not be included by dependencies on @@ -87,7 +87,7 @@ gazelle_dependencies() # Buildozer & deps http_archive( name = "com_google_protobuf", - sha256 = "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a", + sha256 = "4dd35e788944b7686aac898f77df4e9a54da0ca694b8801bd6b2a9ffc1b3085e", strip_prefix = "protobuf-3.19.2", urls = [ "https://github.com/protocolbuffers/protobuf/archive/v3.19.2.tar.gz", @@ -103,5 +103,5 @@ go_repository( build_naming_convention = "go_default_library", importpath = "github.com/bazelbuild/buildtools", sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=", - version = "v0.0.0-20220531122519-a43aed7014c8" -) \ No newline at end of file + version = "v0.0.0-20220531122519-a43aed7014c8", +) From 893077e87793b9a92ee6abd986f8729fd95f6a28 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 12 Sep 2022 13:34:20 -0400 Subject: [PATCH 3/5] Fix the rules_go version, and use a pre-release of gazelle to fix buildtools build --- MODULE.bazel | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index d4cde2ef..45448808 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,8 +14,13 @@ bazel_dep(name = "platforms", version = "0.0.4") ### INTERNAL ONLY - lines after this are not included in the release packaging. # Gazelle extension is experimental -bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0") -bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.26.0") +# Note that io_bazel_rules_go 0.34.0 is currently (2022-09-12) a continuously +# updated version (i.e. >= 0.35.0 in reality), which is what we need for +# buildools. See https://github.com/bazelbuild/bazel-skylib/issues/386#issuecomment-1243958234 +bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.34.0") +# We need https://github.com/bazelbuild/bazel-gazelle/pull/1331 for buildtools +bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.27.0-pre") +git_override(module_name = "gazelle", remote = "https://github.com/bazelbuild/bazel-gazelle", commit="55ba8e3f2aaad0f43d82d02eba90ccf7a7fe9c73") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") @@ -31,10 +36,3 @@ use_repo(go_deps, "com_github_bazelbuild_buildtools") bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.1") bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.5.1") bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.1") - -# needed by buildozer -go_deps.module( - path = "github.com/golang/protobuf", - sum = "h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=", - version = "v1.5.0", -) From 4afd8d281a63581124b6878b30e32f3fc58a5f8e Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 12 Sep 2022 13:36:29 -0400 Subject: [PATCH 4/5] buildifier fixes --- MODULE.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 45448808..66d407e2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -18,9 +18,10 @@ bazel_dep(name = "platforms", version = "0.0.4") # updated version (i.e. >= 0.35.0 in reality), which is what we need for # buildools. See https://github.com/bazelbuild/bazel-skylib/issues/386#issuecomment-1243958234 bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.34.0") + # We need https://github.com/bazelbuild/bazel-gazelle/pull/1331 for buildtools bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.27.0-pre") -git_override(module_name = "gazelle", remote = "https://github.com/bazelbuild/bazel-gazelle", commit="55ba8e3f2aaad0f43d82d02eba90ccf7a7fe9c73") +git_override(module_name = "gazelle", remote = "https://github.com/bazelbuild/bazel-gazelle", commit = "55ba8e3f2aaad0f43d82d02eba90ccf7a7fe9c73") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") From 44e8d9f675e8ba94f8917fc3db2aed004a36423d Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 12 Sep 2022 13:53:07 -0400 Subject: [PATCH 5/5] More buildifier fixes --- MODULE.bazel | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 66d407e2..863a3d6f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -21,7 +21,12 @@ bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.34.0" # We need https://github.com/bazelbuild/bazel-gazelle/pull/1331 for buildtools bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.27.0-pre") -git_override(module_name = "gazelle", remote = "https://github.com/bazelbuild/bazel-gazelle", commit = "55ba8e3f2aaad0f43d82d02eba90ccf7a7fe9c73") + +git_override( + commit = "55ba8e3f2aaad0f43d82d02eba90ccf7a7fe9c73", + module_name = "gazelle", + remote = "https://github.com/bazelbuild/bazel-gazelle", +) go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")