Skip to content

Commit b55240e

Browse files
committed
Add a test to verify the list of expected modules in the default lock file.
This test will help us be more aware of what transitive dependencies are introduced by `@bazel_tools`, we should keep the list of modules as small as possible because they are dependencies of all Bazel users, although fetched lazily. PiperOrigin-RevId: 690616792 Change-Id: I50aec1fce87bae108cb2f6cb315c75c0ef0c7a4c
1 parent 34ef0ce commit b55240e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/tools/bzlmod/verify_default_lock_file.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/
2929
source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
3030
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }
3131

32+
# List of expected modules in the default lock file.
33+
# You may need to update this list if MODULE.tools changes,
34+
# but we should keep the list as small as possible because
35+
# they are tranitive dependencies for all Bazel users (although fetched lazily).
36+
expected_modules=(
37+
abseil-cpp
38+
bazel_features
39+
bazel_skylib
40+
buildozer
41+
googletest
42+
jsoncpp
43+
platforms
44+
protobuf
45+
rules_cc
46+
rules_java
47+
rules_jvm_external
48+
rules_license
49+
rules_pkg
50+
rules_proto
51+
rules_python
52+
rules_shell
53+
stardoc
54+
zlib
55+
)
56+
3257
function test_verify_lock_file() {
3358
rm -f MODULE.bazel
3459
touch MODULE.bazel
@@ -37,6 +62,10 @@ function test_verify_lock_file() {
3762
bazel mod deps --lockfile_mode=update
3863
diff -u $(rlocation io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock) MODULE.bazel.lock || fail "Default lockfile for empty workspace is no longer in sync with MODULE.tools. Please run \"bazel run //src/test/tools/bzlmod:update_default_lock_file\""
3964

65+
# Verify the list of expected modules in the lock file.
66+
grep -o '"https://bcr\.bazel\.build[^"]*source.json"' MODULE.bazel.lock | sed -E 's|.*modules/([^/]+)/.*|\1|' | sort -u > actual_modules
67+
diff -u <(printf '%s\n' "${expected_modules[@]}" | sort) actual_modules || fail "Expected modules in lockfile do not match the actual modules. Please update 'expected_modules' if necessary."
68+
4069
# Verify if python toolchain version matches Bazel's lock file to ensure it's cached in integration tests.
4170
# Check strings like `"default_version": "3.11"`` for default python version.
4271
python_version=$(grep -o '"default_version": "[0-9.]*"' MODULE.bazel.lock | grep -o '[0-9.]*')

0 commit comments

Comments
 (0)