From 7563479c1e412c1bc83d4cabb11641963f71a312 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Mon, 4 Mar 2024 15:54:33 +0100 Subject: [PATCH] [7.1.0] Backport changes for updating default lockfile used in integration tests. (#21547) - 15d4a057e0a5a290cf0b35a7e82d36e1fcada1f0 - 055e25b75c74d1e2c4c71694a938b6456323facc - 0684707c482fd6a48dd7d2fd34ec786a6554555d --------- Co-authored-by: Googler Co-authored-by: Googler --- .bazelrc | 11 +++++------ MODULE.bazel.lock | 2 +- .../bazel/BlackBoxTestEnvironmentImpl.java | 1 + src/test/py/bazel/BUILD | 4 ++++ src/test/py/bazel/action_temp_test.py | 2 +- src/test/py/bazel/bazel_clean_test.py | 6 +++--- src/test/py/bazel/genrule_test.py | 16 ++++++++-------- src/test/py/bazel/options_test.py | 10 +++++----- src/test/py/bazel/query_test.py | 7 +++++-- src/test/py/bazel/runfiles_sandboxed_test.py | 2 +- src/test/py/bazel/runfiles_test.py | 9 +++++---- src/test/py/bazel/test_base.py | 5 +++++ .../testdata/runfiles_test/MODULE.bazel.mock | 1 + .../bazel/testdata/runfiles_test/WORKSPACE.mock | 12 ------------ .../shell/integration/configured_query_test.sh | 2 +- src/test/shell/testenv.sh.tmpl | 4 +++- src/test/tools/bzlmod/MODULE.bazel.lock | 2 +- .../tools/bzlmod/update_default_lock_file.sh | 10 +++++----- .../tools/bzlmod/verify_default_lock_file.sh | 2 +- 19 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock delete mode 100644 src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock diff --git a/.bazelrc b/.bazelrc index ca3c9c7b4015dc..e126d778de144d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,12 +41,11 @@ build:windows_arm64 --extra_toolchains=@local_config_cc//:cc-toolchain-arm64_win # with the target. build:windows_arm64 --java_runtime_version=remotejdk_11 -# Enable Bzlmod -common:bzlmod --enable_bzlmod -common:bzlmod --check_direct_dependencies=error -common:bzlmod --experimental_downloader_config=bazel_downloader.cfg -common --config=bzlmod -common --lockfile_mode=update +# Check direct Bazel module dependencies are up-to-date +common --check_direct_dependencies=error + +# Add mirrors for certain download URLs +common --experimental_downloader_config=bazel_downloader.cfg # Enable modern C++ features build:linux --cxxopt=-std=c++17 diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index e70b4719d62bf1..2e380bbea3239b 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -2367,7 +2367,7 @@ "general": { "bzlTransitiveDigest": "MO3e2koSmZi0NExoX7q3lkNlyquuSaUeNAzVxet7a1c=", "accumulatedFileDigests": { - "@@//src/test/tools/bzlmod:MODULE.bazel.lock": "bc163e49ce365bd5c857957d149b269a28040f3331a566092243787774ff1df7", + "@@//src/test/tools/bzlmod:MODULE.bazel.lock": "0cae3b3c6186baa47cd8a48fe55530f613f22016845926e7825dce52dd496540", "@@//:MODULE.bazel": "c07897f4cf2ea76f689df2779f50aed06ea638d666542078234ebb0efd3ea5a5" }, "envVariables": {}, diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/BlackBoxTestEnvironmentImpl.java b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/BlackBoxTestEnvironmentImpl.java index f6895171735cda..205b7e6c7c5bc7 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/BlackBoxTestEnvironmentImpl.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/BlackBoxTestEnvironmentImpl.java @@ -42,6 +42,7 @@ public BlackBoxTestContext prepareEnvironment( testName, "bazel", binaryPath, Collections.emptyMap(), executorService); // Any Bazel command requires that workspace is already set up. testContext.write("WORKSPACE", "workspace(name = 'main')", getWorkspaceWithDefaultRepos()); + testContext.write("MODULE.bazel"); Path defaultLockfile = RunfilesUtil.find("io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock"); Files.copy(defaultLockfile, testContext.getWorkDir().resolve("MODULE.bazel.lock")); diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD index 5f818ed0e9f9ca..ea335ac97760ab 100644 --- a/src/test/py/bazel/BUILD +++ b/src/test/py/bazel/BUILD @@ -164,6 +164,9 @@ py_test( timeout = "long", srcs = ["runfiles_test.py"], data = glob(["testdata/runfiles_test/**"]), + tags = [ + "requires-network", + ], deps = [ ":test_base", ], @@ -177,6 +180,7 @@ py_test( tags = [ # Windows does not support sandboxing yet. "no_windows", + "requires-network", ], deps = [":test_base"], ) diff --git a/src/test/py/bazel/action_temp_test.py b/src/test/py/bazel/action_temp_test.py index da4a2be75c2019..75c7f789724d57 100644 --- a/src/test/py/bazel/action_temp_test.py +++ b/src/test/py/bazel/action_temp_test.py @@ -156,7 +156,7 @@ def _CreateWorkspace(self, build_flags=None): 'fi', ] - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/' + toolname, toolsrc, executable=True) self.ScratchFile( 'foo/foo.bzl', diff --git a/src/test/py/bazel/bazel_clean_test.py b/src/test/py/bazel/bazel_clean_test.py index f742c0dd413751..9301b60c3e0e7d 100644 --- a/src/test/py/bazel/bazel_clean_test.py +++ b/src/test/py/bazel/bazel_clean_test.py @@ -22,7 +22,7 @@ class BazelCleanTest(test_base.TestBase): def testBazelClean(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -60,7 +60,7 @@ def testBazelClean(self): @absltest.skipIf(not test_base.TestBase.IsLinux(), 'Async clean only supported on Linux') def testBazelAsyncClean(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') _, _, stderr = self.RunBazel(['clean', '--async']) matcher = self._findMatch(' moved to (.*) for deletion', stderr) self.assertTrue(matcher, stderr) @@ -79,7 +79,7 @@ def testBazelAsyncClean(self): @absltest.skipIf(not test_base.TestBase.IsLinux(), 'Async clean only supported on Linux') def testBazelAsyncCleanWithReadonlyDirectories(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.RunBazel(['build']) _, stdout, _ = self.RunBazel(['info', 'execution_root']) execroot = stdout[0] diff --git a/src/test/py/bazel/genrule_test.py b/src/test/py/bazel/genrule_test.py index a5ced4a330b741..48a2df429d3ece 100644 --- a/src/test/py/bazel/genrule_test.py +++ b/src/test/py/bazel/genrule_test.py @@ -20,7 +20,7 @@ class GenRuleTest(test_base.TestBase): def testCopyWithBashAndBatch(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -42,7 +42,7 @@ def testCopyWithBashAndBatch(self): self.AssertFileContentContains(copied, 'hello world') def testCopyWithBashAndPowershell(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -64,7 +64,7 @@ def testCopyWithBashAndPowershell(self): self.AssertFileContentContains(copied, 'hello world') def testShOptionOverridesDefault(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -85,7 +85,7 @@ def testShOptionOverridesDefault(self): def testScriptFileIsUsedWithBatch(self): if not self.IsWindows(): return - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -110,7 +110,7 @@ def testScriptFileIsUsedWithBatch(self): def testScriptFileIsUsedWithPowershell(self): if not self.IsWindows(): return - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -135,7 +135,7 @@ def testScriptFileIsUsedWithPowershell(self): def testCommandFailsEagerlyInPowershell(self): if not self.IsWindows(): return - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -155,7 +155,7 @@ def testCommandFailsEagerlyInPowershell(self): def testCopyWithSpacesWithBatch(self): if not self.IsWindows(): return - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', @@ -178,7 +178,7 @@ def testCopyWithSpacesWithBatch(self): def testCopyWithSpacesWithPowershell(self): if not self.IsWindows(): return - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'genrule(', ' name = "x",', diff --git a/src/test/py/bazel/options_test.py b/src/test/py/bazel/options_test.py index c8e1c37a96827a..074e5de65b3bc0 100644 --- a/src/test/py/bazel/options_test.py +++ b/src/test/py/bazel/options_test.py @@ -19,7 +19,7 @@ class OptionsTest(test_base.TestBase): def testCanOverrideStarlarkFlagInBazelrcConfigStanza(self): - self.ScratchFile("WORKSPACE.bazel") + self.ScratchFile("MODULE.bazel") self.ScratchFile( "bazelrc", [ @@ -84,7 +84,7 @@ def testCanOverrideStarlarkFlagInBazelrcConfigStanza(self): ) def testCommonPseudoCommand(self): - self.ScratchFile("WORKSPACE.bazel") + self.ScratchFile("MODULE.bazel") self.ScratchFile( ".bazelrc", [ @@ -183,7 +183,7 @@ def testCommonPseudoCommand(self): ) def testCommonPseudoCommand_singleLineParsesUnambiguously(self): - self.ScratchFile("WORKSPACE.bazel") + self.ScratchFile("MODULE.bazel") self.ScratchFile( ".bazelrc", [ @@ -225,7 +225,7 @@ def testCommonPseudoCommand_singleLineParsesUnambiguously(self): ) def testCommonPseudoCommand_unsupportedOptionValue(self): - self.ScratchFile("WORKSPACE.bazel") + self.ScratchFile("MODULE.bazel") self.ScratchFile( ".bazelrc", [ @@ -271,7 +271,7 @@ def testCommonPseudoCommand_unsupportedOptionValue(self): def testCommonPseudoCommand_allowResidueFalseCommandIgnoresStarlarkOptions( self, ): - self.ScratchFile("WORKSPACE.bazel") + self.ScratchFile("MODULE.bazel") self.ScratchFile( ".bazelrc", [ diff --git a/src/test/py/bazel/query_test.py b/src/test/py/bazel/query_test.py index 152732a1101d87..0af495e1281fb5 100644 --- a/src/test/py/bazel/query_test.py +++ b/src/test/py/bazel/query_test.py @@ -20,7 +20,7 @@ class QueryTest(test_base.TestBase): def testSimpleQuery(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self.ScratchFile('foo/BUILD', [ 'exports_files(["exported.txt"])', 'filegroup(name = "top-rule", srcs = [":dep-rule"])', @@ -39,13 +39,14 @@ def testSimpleQuery(self): '//foo:dep-rule') def testQueryFilesUsedByRepositoryRules(self): - self.ScratchFile('WORKSPACE') + self.ScratchFile('MODULE.bazel') self._AssertQueryOutputContains( "kind('source file', deps(//external:*))", '@bazel_tools//tools/genrule:genrule-setup.sh', ) def testBuildFilesForExternalRepos_Simple(self): + self.ScratchFile('MODULE.bazel') self.ScratchFile('WORKSPACE', [ 'load("//:deps.bzl", "repos")', 'repos()', @@ -64,6 +65,7 @@ def testBuildFilesForExternalRepos_Simple(self): '//:BUILD.bazel') def testBuildFilesForExternalRepos_IndirectLoads(self): + self.ScratchFile('MODULE.bazel') self.ScratchFile('WORKSPACE', [ 'load("//:deps.bzl", "repos")', 'repos()', @@ -94,6 +96,7 @@ def testBuildFilesForExternalRepos_IndirectLoads(self): '//:deps.bzl', '//:private_deps.bzl', '//:BUILD.bazel') def testBuildFilesForExternalRepos_NoDuplicates(self): + self.ScratchFile('MODULE.bazel') self.ScratchFile('WORKSPACE', [ 'load("//:deps.bzl", "repos")', 'repos()', diff --git a/src/test/py/bazel/runfiles_sandboxed_test.py b/src/test/py/bazel/runfiles_sandboxed_test.py index c0c28dfb173ee7..28c073f5d480be 100644 --- a/src/test/py/bazel/runfiles_sandboxed_test.py +++ b/src/test/py/bazel/runfiles_sandboxed_test.py @@ -25,7 +25,7 @@ def _FailWithContents(self, msg, contents): def testRunfilesLibrariesFindRunfilesWithoutEnvvars(self): for s, t, exe in [ - ("WORKSPACE.mock", "WORKSPACE", False), + ("MODULE.bazel.mock", "MODULE.bazel", False), ("bar/BUILD.mock", "bar/BUILD", False), ("bar/bar.py", "bar/bar.py", True), ("bar/bar-py-data.txt", "bar/bar-py-data.txt", False), diff --git a/src/test/py/bazel/runfiles_test.py b/src/test/py/bazel/runfiles_test.py index c4e4d977ed82ef..0719e70a4ad82f 100644 --- a/src/test/py/bazel/runfiles_test.py +++ b/src/test/py/bazel/runfiles_test.py @@ -21,7 +21,7 @@ class RunfilesTest(test_base.TestBase): def _AssertRunfilesLibraryInBazelToolsRepo(self, family, lang_name): - for s, t, exe in [("WORKSPACE.mock", "WORKSPACE", + for s, t, exe in [("MODULE.bazel.mock", "MODULE.bazel", False), ("foo/BUILD.mock", "foo/BUILD", False), ("foo/foo.py", "foo/foo.py", True), ("foo/Foo.java", "foo/Foo.java", @@ -101,7 +101,7 @@ def testCppRunfilesLibraryInBazelToolsRepo(self): def testRunfilesLibrariesFindRunfilesWithoutEnvvars(self): for s, t, exe in [ - ("WORKSPACE.mock", "WORKSPACE", False), + ("MODULE.bazel.mock", "MODULE.bazel", False), ("bar/BUILD.mock", "bar/BUILD", False), ("bar/bar.py", "bar/bar.py", True), ("bar/bar-py-data.txt", "bar/bar-py-data.txt", False), @@ -161,7 +161,7 @@ def testRunfilesLibrariesFindRunfilesWithoutEnvvars(self): def testRunfilesLibrariesFindRunfilesWithRunfilesManifestEnvvar(self): for s, t, exe in [ - ("WORKSPACE.mock", "WORKSPACE", False), + ("MODULE.bazel.mock", "MODULE.bazel", False), ("bar/BUILD.mock", "bar/BUILD", False), # Note: do not test Python here, because py_binary always needs a # runfiles tree, even on Windows, because it needs __init__.py files in @@ -305,9 +305,10 @@ def testLegacyExternalRunfilesOption(self): def testRunfilesLibrariesFindRlocationpathExpansion(self): self.ScratchDir("A") - self.ScratchFile("A/WORKSPACE") + self.ScratchFile("A/REPO.bazel") self.ScratchFile("A/p/BUILD", ["exports_files(['foo.txt'])"]) self.ScratchFile("A/p/foo.txt", ["Hello, World!"]) + self.ScratchFile("MODULE.bazel") self.ScratchFile("WORKSPACE", ["local_repository(name = 'A', path='A')"]) self.ScratchFile("pkg/BUILD", [ "py_binary(", diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index dd860cf021415e..dfa5db18055ee6 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -217,6 +217,11 @@ def CreateWorkspaceWithDefaultRepos(self, path, lines=None): if lines: rule_definition.extend(lines) self.ScratchFile(path, rule_definition) + self.ScratchFile( + path.replace('WORKSPACE.bazel', 'MODULE.bazel').replace( + 'WORKSPACE', 'MODULE.bazel' + ) + ) def GetDefaultRepoRules(self): with open( diff --git a/src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock b/src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock new file mode 100644 index 00000000000000..9b0be5f92553b3 --- /dev/null +++ b/src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock @@ -0,0 +1 @@ +bazel_dep(name = "rules_cc", version = "0.0.9") diff --git a/src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock b/src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock deleted file mode 100644 index f1da87a58cccf1..00000000000000 --- a/src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock +++ /dev/null @@ -1,12 +0,0 @@ -workspace(name = "foo_ws") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_cc", - sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf", - urls = [ - "https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz", - ], - strip_prefix = "rules_cc-0.0.9", -) diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index 9a9cb52c26d8b5..28574831742268 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -1383,7 +1383,7 @@ function test_external_repo_scope() { local -r dir=$FUNCNAME mkdir -p $dir/repo - touch $dir/repo/WORKSPACE + touch $dir/repo/REPO.bazel cat > $dir/repo/BUILD <&2; exit 1; } function test_verify_lock_file() { - touch WORKSPACE rm -f MODULE.bazel + touch MODULE.bazel cp $(rlocation io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock) MODULE.bazel.lock echo "Running: bazel mod deps --lockfile_mode=error" >& "$TEST_log" bazel mod deps --lockfile_mode=error >& "$TEST_log" || 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\""