Skip to content

Commit d1af16b

Browse files
committed
Make extensions reproducible, add lock files
Returns `module_ctx.extension_metadata(reproducible = True)` from module extensions and checks in `MODULE.bazel.lock` files. Adds `--lockfile_mode=error` to the top level `.bazelrc`, and adds `--lockfile_mode=update` where necessary to ensure tests don't break. Also: - Bumps `rules_go` to 0.58.2, which resolves bazel-contrib/rules_go#4480, and removes the temporary `git_override`. - Bumps Go to 1.25.3 in `WORKSPACE` (missed in bazel-contrib#1778). - Updates the `.bazelversion` files in nested repos to match the top-level `.bazelversion` file (missed in bazel-contrib#1778). - Removes unnecessary `scala_deps.scala()` tags from the `dt_patches/test_dt_patches{,_user_srcjar}` and `test/compiler_sources_integrity` modules. This makes the resulting `MODULE.bazel.lock` files for the latter two modules much smaller. - Removes `bazel shutdown` commands to speed up several tests, notably `dt_patches/dt_patch_test.sh` and `test/shell/test_examples.sh`. Running ```txt $ git diff --stat HEAD^ ':!:**.bazelversion' ':!:**MODULE.bazel.lock' .bazelci/presubmit.yml | 5 +++++ .bazelrc | 5 +++++ .bcr/presubmit.yml | 4 ++++ .gitignore | 5 ++--- MODULE.bazel | 13 ++----------- WORKSPACE | 8 ++++---- dt_patches/dt_patch_test.sh | 5 ++++- dt_patches/test_dt_patches/.bazelrc | 3 +++ dt_patches/test_dt_patches/MODULE.bazel | 1 - dt_patches/test_dt_patches_user_srcjar/.bazelrc | 3 +++ dt_patches/test_dt_patches_user_srcjar/MODULE.bazel | 1 - dt_patches/test_dt_patches_user_srcjar/extensions.bzl | 4 +++- scala/extensions/config.bzl | 1 + scala/extensions/deps.bzl | 22 ++++++++++++++++++---- scala/extensions/protoc.bzl | 3 +++ scala/private/extensions/dev_deps.bzl | 1 + test/compiler_sources_integrity/.bazelrc | 4 ++++ test/compiler_sources_integrity/MODULE.bazel | 1 - test/shell/test_examples.sh | 6 +++++- test_version.sh | 4 +++- 20 files changed, 70 insertions(+), 29 deletions(-) ``` --- At @jayconrod's suggestion, it seems worth revisiting the `MODULE.bazel.lock` mechanism. The format appears to have stabilized (especially in newer Bazels), and it seems explicitly marking extensions as reproducible helps shrink lock files dramatically. While I've yet to notice (or measure) performance benefits, the stability and security benefits appear worth the effort. Before marking `scala_deps` as reproducible, the `MODULE.bazel.lock` file was 30892 lines long. This dramatic effect on our own lock file suggests that this change will potentially help consumers maintain smaller lock files as well. The only time any of the extensions are nonreproducible is when a `scala_deps.compiler_srcjar` tag contains no `label`, `sha256`, or `integrity` attribute. This should prove so limited a case as to be nonexistent in practice. Even so, the extension makes sure to indicate that it's _not_ reproducible in that case. Diffing `dt_patches/test_dt_patches{,_user_srcjar}/MODULE.bazel.lock` shows what happens when a `compiler_srcjar` tag lacks those attributes. Finally, `--lockfile_mode=error` is useful to detect lock file updates when building with the default `.bazelversion`. However, running tests with newer versions of Bazel in this mode will break. The `.bazelrc` line introducing the `--lockfile_mode` flag has a comment suggesting that users comment it out when testing other Bazel versions.
1 parent 752b305 commit d1af16b

File tree

54 files changed

+4810
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4810
-46
lines changed

.bazelci/presubmit.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tasks:
4141
shell_commands:
4242
# Install xmllint
4343
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
44+
- echo "common --lockfile_mode=update" >>.bazelrc
4445
- "./test_rules_scala.sh"
4546
soft_fail:
4647
- exit_status: "*"
@@ -150,8 +151,12 @@ tasks:
150151
working_directory: "examples/crossbuild"
151152
platform: ${{ bcr_platform }}
152153
bazel: ${{ bcr_bazel }}
154+
build_flags:
155+
- "--lockfile_mode=update"
153156
build_targets:
154157
- "//..."
158+
test_flags:
159+
- "--lockfile_mode=update"
155160
test_targets:
156161
- "//..."
157162
soft_fail:

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Remove once Bazel 8 becomes the minimum supported version.
22
common --noenable_workspace --incompatible_use_plus_in_repo_names
33

4+
# Ensure that the `MODULE.bazel.lock` files don't change silently.
5+
# Comment out to actually update the lockfiles, and when testing a Bazel version
6+
# different from .bazelversion.
7+
common --lockfile_mode=error
8+
49
# Uncomment to run tests under `WORKSPACE`. Remove once Bazel 9 becomes the
510
# minimum supported version.
611
#common --enable_workspace --noenable_bzlmod

.bcr/presubmit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ bcr_test_module:
99
name: "Build and test the example module"
1010
platform: ${{ platform }}
1111
bazel: ${{ bazel }}
12+
build_flags:
13+
- "--lockfile_mode=update"
1214
build_targets:
1315
- "//..."
16+
test_flags:
17+
- "--lockfile_mode=update"
1418
test_targets:
1519
- "//..."

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ repository-artifacts.json
2020
# From scripts/*.py
2121
**/__pycache__/
2222

23-
# Until it settles down
24-
**/MODULE.bazel.lock
25-
2623
# Used by some tests, but can also be used for local experimentation.
2724
tmp/
2825

2926
# Not required by tests.
3027
deps/latest/.bazelversion
28+
deps/latest/MODULE.bazel.lock
29+
dt_patches/compiler_sources/MODULE.bazel.lock
3130

MODULE.bazel

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module(
44
name = "rules_scala",
5-
version = "7.1.3",
5+
version = "7.1.4",
66
bazel_compatibility = [">=7.1.0"],
77
compatibility_level = 7,
88
)
@@ -257,19 +257,10 @@ bazel_dep(
257257
)
258258
bazel_dep(
259259
name = "rules_go",
260-
version = "0.57.0",
260+
version = "0.58.2",
261261
dev_dependency = True,
262262
repo_name = "io_bazel_rules_go", # for com_github_bazelbuild_buildtools
263263
)
264-
265-
# Temporary workaround until rules_go > 0.57.0 becomes available to resolve:
266-
# https://github.com/bazel-contrib/rules_go/issues/4480
267-
git_override(
268-
module_name = "rules_go",
269-
commit = "74199c92e20399b6ef46684b2c6fdd94b50a7892",
270-
remote = "https://github.com/bazel-contrib/rules_go.git",
271-
)
272-
273264
bazel_dep(name = "gazelle", version = "0.45.0", dev_dependency = True)
274265

275266
go_sdk = use_extension(

MODULE.bazel.lock

Lines changed: 545 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ local_repository(
106106

107107
http_archive(
108108
name = "io_bazel_rules_go",
109-
sha256 = "a729c8ed2447c90fe140077689079ca0acfb7580ec41637f312d650ce9d93d96",
109+
sha256 = "54bbb67a4196170cc60ef3b52a2747ad1759cba4764b4c4752b744080ad99947",
110110
urls = [
111-
"https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.57.0/rules_go-v0.57.0.zip",
112-
"https://github.com/bazel-contrib/rules_go/releases/download/v0.57.0/rules_go-v0.57.0.zip",
111+
"https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.58.2/rules_go-v0.58.2.zip",
112+
"https://github.com/bazel-contrib/rules_go/releases/download/v0.58.2/rules_go-v0.58.2.zip",
113113
],
114114
)
115115

@@ -121,7 +121,7 @@ load(
121121

122122
go_rules_dependencies()
123123

124-
go_register_toolchains(version = "1.25.1")
124+
go_register_toolchains(version = "1.25.3")
125125

126126
http_archive(
127127
name = "bazelci_rules",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.6.1
1+
7.6.2

dt_patches/dt_patch_test.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ run_in_test_repo() {
1616
cd "${dir}/${test_repo}" || return 1
1717
"${test_command[@]}" || response_code=$?
1818

19-
bazel shutdown
2019
cd ../..
2120
return $response_code
2221
}
@@ -120,6 +119,8 @@ $runner test_compiler_patch 3.5.2
120119
$runner test_compiler_patch 3.6.4
121120
$runner test_compiler_patch 3.7.3
122121

122+
run_in_test_repo 'test_dt_patches' bazel shutdown
123+
123124
$runner test_compiler_srcjar_error 2.12.11
124125
$runner test_compiler_srcjar_error 2.12.12
125126
$runner test_compiler_srcjar_error 2.12.13
@@ -152,3 +153,5 @@ $runner test_compiler_srcjar 3.4.3
152153
$runner test_compiler_srcjar_nonhermetic 3.5.2
153154
$runner test_compiler_srcjar_nonhermetic 3.6.4
154155
$runner test_compiler_srcjar_nonhermetic 3.7.3
156+
157+
run_in_test_repo 'test_dt_patches_user_srcjar' bazel shutdown
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
import ../../.bazelrc
2+
3+
# The `--repo_env` flags cause `MODULE.bazel.lock` updates.
4+
common --lockfile_mode=update

0 commit comments

Comments
 (0)