Skip to content

Commit

Permalink
In update_default_lock_file.sh, create a MODULE.bazel instead of a RE…
Browse files Browse the repository at this point in the history
…PO.bazel

... to avoid the "--enable_bzlmod but no MODULE.bazel found" warning message.

PiperOrigin-RevId: 592608824
Change-Id: I140005467977b4fd724eb919ce66f68d83f8ecc2
  • Loading branch information
Wyverald authored and copybara-github committed Dec 20, 2023
1 parent d9169ab commit 055e25b
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
4 changes: 4 additions & 0 deletions src/test/py/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ py_test(
timeout = "long",
srcs = ["runfiles_test.py"],
data = glob(["testdata/runfiles_test/**"]),
tags = [
"requires-network",
],
deps = [
":test_base",
],
Expand All @@ -177,6 +180,7 @@ py_test(
tags = [
# Windows does not support sandboxing yet.
"no_windows",
"requires-network",
],
deps = [":test_base"],
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/action_temp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/test/py/bazel/bazel_clean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",',
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
16 changes: 8 additions & 8 deletions src/test/py/bazel/genrule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand All @@ -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",',
Expand Down
10 changes: 5 additions & 5 deletions src/test/py/bazel/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class OptionsTest(test_base.TestBase):

def testCanOverrideStarlarkFlagInBazelrcConfigStanza(self):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile("MODULE.bazel")
self.ScratchFile(
"bazelrc",
[
Expand Down Expand Up @@ -84,7 +84,7 @@ def testCanOverrideStarlarkFlagInBazelrcConfigStanza(self):
)

def testCommonPseudoCommand(self):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile("MODULE.bazel")
self.ScratchFile(
".bazelrc",
[
Expand Down Expand Up @@ -183,7 +183,7 @@ def testCommonPseudoCommand(self):
)

def testCommonPseudoCommand_singleLineParsesUnambiguously(self):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile("MODULE.bazel")
self.ScratchFile(
".bazelrc",
[
Expand Down Expand Up @@ -225,7 +225,7 @@ def testCommonPseudoCommand_singleLineParsesUnambiguously(self):
)

def testCommonPseudoCommand_unsupportedOptionValue(self):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile("MODULE.bazel")
self.ScratchFile(
".bazelrc",
[
Expand Down Expand Up @@ -271,7 +271,7 @@ def testCommonPseudoCommand_unsupportedOptionValue(self):
def testCommonPseudoCommand_allowResidueFalseCommandIgnoresStarlarkOptions(
self,
):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile("MODULE.bazel")
self.ScratchFile(
".bazelrc",
[
Expand Down
7 changes: 5 additions & 2 deletions src/test/py/bazel/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])',
Expand All @@ -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()',
Expand All @@ -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()',
Expand Down Expand Up @@ -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()',
Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/runfiles_sandboxed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions src/test/py/bazel/runfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(",
Expand Down
5 changes: 5 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def CreateWorkspaceWithDefaultRepos(self, path, lines=None):
')',
])
self.ScratchFile(path, rule_definition)
self.ScratchFile(
path.replace('WORKSPACE.bazel', 'MODULE.bazel').replace(
'WORKSPACE', 'MODULE.bazel'
)
)

def GetDefaultRepoRules(self):
with open(
Expand Down
1 change: 1 addition & 0 deletions src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel_dep(name = "rules_cc", version = "0.0.9")
12 changes: 0 additions & 12 deletions src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,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 <<EOF
sh_library(name='maple', deps=[':japanese'])
sh_library(name='japanese')
Expand Down
4 changes: 3 additions & 1 deletion src/test/shell/testenv.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ EOF

# Set up a lockfile to avoid accessing BCR for tests with a clean workspace.
function write_default_lockfile() {
cp -f $(rlocation io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock) ${1:-MODULE.bazel.lock}
module_lockfile=${1:-MODULE.bazel.lock}
touch "$(dirname ${module_lockfile})/MODULE.bazel"
cp -f $(rlocation io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock) ${module_lockfile}
}

workspaces=()
Expand Down
2 changes: 1 addition & 1 deletion src/test/tools/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/test/tools/bzlmod/update_default_lock_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function generate_lock_file() {
trap 'cleanup $tmpdir' EXIT

cd "${tmpdir}"
touch REPO.bazel
touch MODULE.bazel
bazel=$(rlocation io_bazel/src/bazel)

echo "Running: $bazel mod deps"
Expand Down
2 changes: 1 addition & 1 deletion src/test/tools/bzlmod/verify_default_lock_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

function test_verify_lock_file() {
touch REPO.bazel
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\""
Expand Down

0 comments on commit 055e25b

Please sign in to comment.