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
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestStrategy.java index f98b7d5..cb8f913 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestStrategy.java
@@ -194,7 +194,7 @@ TestRunnerAction testAction, List<String> args, boolean executedOnWindows) { TestTargetExecutionSettings execSettings = testAction.getExecutionSettings(); if (execSettings.getRunUnderExecutable() != null) { - args.add(execSettings.getRunUnderExecutable().getRootRelativePath().getCallablePathString()); + args.add(execSettings.getRunUnderExecutable().getRunfilesPath().getCallablePathString()); } else { if (execSettings.needsShell(executedOnWindows)) { // TestActionBuilder constructs TestRunnerAction with a 'null' shell only when none is
diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh index 2d61777..662b27b 100755 --- a/src/test/shell/bazel/bazel_test_test.sh +++ b/src/test/shell/bazel/bazel_test_test.sh
@@ -266,6 +266,52 @@ expect_log 'hello script!!! testing/t1' } +function test_run_under_external_file_with_options() { + # Set up the external repo. + local run_repo=$TEST_TMPDIR/run + mkdir -p $run_repo || fail "mkdir run_repo failed" + touch $run_repo/WORKSPACE + + cat <<EOF > $run_repo/BUILD +exports_files(["under.sh"]) +EOF + cat <<EOF > $run_repo/under.sh +#!/bin/sh +echo running under @run//:under "\$*" +EOF + chmod u+x $run_repo/under.sh + + + # Set up the main repo. + cat <<EOF > WORKSPACE +local_repository( + name = "run", + path = "../run", +) +EOF + + mkdir -p testing || fail "mkdir testing failed" + + cat <<EOF > testing/BUILD +sh_test( + name = "passing_test" , + srcs = [ "passing_test.sh" ]) +EOF + cat <<EOF > testing/passing_test.sh +#!/bin/sh +exit 0 +EOF + chmod u+x testing/passing_test.sh + + + bazel test //testing:passing_test -s --run_under='@run//:under.sh -c' \ + --test_output=all >& $TEST_log || fail "Expected success" + + expect_log 'running under @run//:under -c testing/passing_test' + expect_log 'passing_test *PASSED' + expect_log '1 test passes.$' +} + function test_test_timeout() { mkdir -p dir