Skip to content

Commit a689d67

Browse files
Googlercopybara-github
Googler
authored andcommitted
Use getRunfilesPath for run_under executable path generation. getRootRelativePath doesn't return a valid runfiles path for external source files anymore after the recent external source root change. Also, it won't work for external labels either once the --nolegacy_external_runfiles becomes default. This fixes issue #12545.
PiperOrigin-RevId: 345435649
1 parent 41b3ab6 commit a689d67

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/java/com/google/devtools/build/lib/analysis/test/TestStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private static void addRunUnderArgs(
195195
TestRunnerAction testAction, List<String> args, boolean executedOnWindows) {
196196
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
197197
if (execSettings.getRunUnderExecutable() != null) {
198-
args.add(execSettings.getRunUnderExecutable().getRootRelativePath().getCallablePathString());
198+
args.add(execSettings.getRunUnderExecutable().getRunfilesPath().getCallablePathString());
199199
} else {
200200
if (execSettings.needsShell(executedOnWindows)) {
201201
// TestActionBuilder constructs TestRunnerAction with a 'null' shell only when none is

src/test/shell/bazel/bazel_test_test.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,52 @@ EOF
266266
expect_log 'hello script!!! testing/t1'
267267
}
268268

269+
function test_run_under_external_file_with_options() {
270+
# Set up the external repo.
271+
local run_repo=$TEST_TMPDIR/run
272+
mkdir -p $run_repo || fail "mkdir run_repo failed"
273+
touch $run_repo/WORKSPACE
274+
275+
cat <<EOF > $run_repo/BUILD
276+
exports_files(["under.sh"])
277+
EOF
278+
cat <<EOF > $run_repo/under.sh
279+
#!/bin/sh
280+
echo running under @run//:under "\$*"
281+
EOF
282+
chmod u+x $run_repo/under.sh
283+
284+
285+
# Set up the main repo.
286+
cat <<EOF > WORKSPACE
287+
local_repository(
288+
name = "run",
289+
path = "../run",
290+
)
291+
EOF
292+
293+
mkdir -p testing || fail "mkdir testing failed"
294+
295+
cat <<EOF > testing/BUILD
296+
sh_test(
297+
name = "passing_test" ,
298+
srcs = [ "passing_test.sh" ])
299+
EOF
300+
cat <<EOF > testing/passing_test.sh
301+
#!/bin/sh
302+
exit 0
303+
EOF
304+
chmod u+x testing/passing_test.sh
305+
306+
307+
bazel test //testing:passing_test -s --run_under='@run//:under.sh -c' \
308+
--test_output=all >& $TEST_log || fail "Expected success"
309+
310+
expect_log 'running under @run//:under -c testing/passing_test'
311+
expect_log 'passing_test *PASSED'
312+
expect_log '1 test passes.$'
313+
}
314+
269315
function test_test_timeout() {
270316
mkdir -p dir
271317

0 commit comments

Comments
 (0)