Skip to content

Commit

Permalink
Use getRunfilesPath for run_under executable path generation. getRoot…
Browse files Browse the repository at this point in the history
…RelativePath 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 bazelbuild#12545.

PiperOrigin-RevId: 345435649
  • Loading branch information
Googler authored and copybara-github committed Dec 3, 2020
1 parent 41b3ab6 commit a689d67
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static void addRunUnderArgs(
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
Expand Down
46 changes: 46 additions & 0 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,52 @@ EOF
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

Expand Down

0 comments on commit a689d67

Please sign in to comment.