Skip to content

Commit ec2ebba

Browse files
committed
Disable --legacy_external_runfiles in Bazel tests
Prepares for the flip (bazelbuild#12821) by ensuring that Bazel itself doesn't regress.
1 parent 29318bb commit ec2ebba

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl

+1-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jv
251251
launch_info.add(main_class, format = "java_start_class=%s")
252252
launch_info.add_joined(classpath, map_each = _short_path, join_with = ";", format_joined = "classpath=%s", omit_if_empty = False)
253253
launch_info.add_joined(jvm_flags_for_launcher, join_with = "\t", format_joined = "jvm_flags=%s", omit_if_empty = False)
254-
jar_bin_path = semantics.find_java_runtime_toolchain(ctx).java_home + "/bin/jar.exe"
255-
launch_info.add(jar_bin_path, format = "jar_bin_path=%s")
254+
launch_info.add(semantics.find_java_runtime_toolchain(ctx).java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe")
256255

257256
# TODO(b/295221112): Change to use the "launcher" attribute (only windows use a fixed _launcher attribute)
258257
launcher_artifact = ctx.executable._launcher

src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderIntegrationTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void otherPathExpansion() throws Exception {
155155
}
156156

157157
@Test
158-
public void otherPathExternalExpansion() throws Exception {
158+
public void otherPathExternalExpansionLegacyExternalRunfiles() throws Exception {
159159
scratch.file(
160160
"expansion/BUILD",
161161
"sh_library(name='lib', srcs=['@r//p:foo'])");
@@ -171,6 +171,7 @@ public void otherPathExternalExpansion() throws Exception {
171171
scratch.file("/r/WORKSPACE", "workspace(name = 'r')");
172172
scratch.file("/r/p/BUILD", "genrule(name='foo', outs=['foo.txt'], cmd='never executed')");
173173

174+
useConfiguration("--legacy_external_runfiles");
174175
LocationExpander expander = makeExpander("//expansion:lib");
175176
assertThat(expander.expand("foo $(execpath @r//p:foo) bar"))
176177
.matches("foo .*-out/.*/external/r/p/foo\\.txt bar");

src/test/java/com/google/devtools/build/lib/analysis/RunfilesRepoMappingManifestTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ public void hasMappingForSymlinks() throws Exception {
371371
.map(PathFragment::getPathString)
372372
.collect(toImmutableList());
373373
assertThat(runfilesPaths)
374-
.containsExactly(
374+
.containsAtLeast(
375375
"aaa~1.0/aaa",
376-
getRuleClassProvider().getRunfilesPrefix() + "/external/aaa~1.0/aaa",
377376
getRuleClassProvider().getRunfilesPrefix() + "/path/to/pkg/symlink",
378377
"symlinks~1.0/path/to/pkg/root_symlink",
379378
"_repo_mapping");

src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public enum Flag {
128128
// Flags from TestConstants.PRODUCT_SPECIFIC_FLAGS.
129129
PRODUCT_SPECIFIC_FLAGS,
130130
// The --enable_bzlmod flags.
131-
ENABLE_BZLMOD
131+
ENABLE_BZLMOD,
132+
// The --nolegacy_external_runfiles flag.
133+
NO_LEGACY_EXTERNAL_RUNFILES
132134
}
133135

134136
/** Helper class to make it easy to enable and disable flags. */
@@ -350,6 +352,9 @@ public void useConfiguration(String... args) throws Exception {
350352
} else {
351353
optionsParser.parse("--noenable_bzlmod");
352354
}
355+
if (defaultFlags().contains(Flag.NO_LEGACY_EXTERNAL_RUNFILES)) {
356+
optionsParser.parse("--nolegacy_external_runfiles");
357+
}
353358
optionsParser.parse(args);
354359

355360
buildOptions =
@@ -360,7 +365,8 @@ protected FlagBuilder defaultFlags() {
360365
return new FlagBuilder()
361366
.with(Flag.PUBLIC_VISIBILITY)
362367
.with(Flag.CPU_K8)
363-
.with(Flag.PRODUCT_SPECIFIC_FLAGS);
368+
.with(Flag.PRODUCT_SPECIFIC_FLAGS)
369+
.with(Flag.NO_LEGACY_EXTERNAL_RUNFILES);
364370
}
365371

366372
protected Action getGeneratingAction(Artifact artifact) {

src/test/py/bazel/test_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def setUp(self):
115115
self._test_cwd = tempfile.mkdtemp(dir=self._tests_root)
116116
self._test_bazelrc = os.path.join(self._temp, 'test_bazelrc')
117117
with open(self._test_bazelrc, 'wt') as f:
118+
f.write('common --nolegacy_external_runfiles\n')
118119
shared_repo_home = os.environ.get('TEST_REPOSITORY_HOME')
119120
if shared_repo_home and os.path.exists(shared_repo_home):
120121
for repo in self._SHARED_REPOS:

src/test/shell/bazel/bazel_java_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ EOF
15761576
chmod +x "${pkg}"/run.sh
15771577

15781578
bazel test //"${pkg}":bar --test_output=all --verbose_failures >& "$TEST_log" \
1579+
--legacy_external_runfiles \
15791580
|| fail "Expected success"
15801581
}
15811582

src/test/shell/bazel/external_integration_test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ genrule(
624624
name = "test_sh",
625625
outs = ["test.sh"],
626626
srcs = ["@toto//file"],
627-
cmd = "echo '#!/bin/sh' > $@ && echo $(location @toto//file) >> $@",
627+
cmd = "echo '#!/bin/sh' > $@ && echo $(rootpath @toto//file) >> $@",
628628
)
629629
EOF
630630

@@ -682,7 +682,7 @@ genrule(
682682
name = "test_sh",
683683
outs = ["test.sh"],
684684
srcs = ["@toto//file"],
685-
cmd = "echo '#!/bin/sh' > $@ && echo cat $(location @toto//file) >> $@",
685+
cmd = "echo '#!/bin/sh' > $@ && echo cat $(rootpath @toto//file) >> $@",
686686
)
687687
EOF
688688

src/test/shell/testenv.sh.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ build --incompatible_use_toolchain_resolution_for_java_rules
267267
# Enable Bzlmod in all shell integration tests
268268
common --enable_bzlmod
269269
270+
# Verify compatibility before the flip (https://github.com/bazelbuild/bazel/issues/12821)
271+
common --nolegacy_external_runfiles
272+
270273
${EXTRA_BAZELRC:-}
271274
EOF
272275

0 commit comments

Comments
 (0)