From a689d673abadf80f1efaf8ddaeee92d56fc2847b Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 3 Dec 2020 06:09:52 -0800 Subject: [PATCH] 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 --- .../build/lib/analysis/test/TestStrategy.java | 2 +- src/test/shell/bazel/bazel_test_test.sh | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) 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 a3b10768902ec2..8c3f20624b6051 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 @@ -195,7 +195,7 @@ private static void addRunUnderArgs( TestRunnerAction testAction, List 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 2d61777296621e..662b27bdc8e44d 100755 --- a/src/test/shell/bazel/bazel_test_test.sh +++ b/src/test/shell/bazel/bazel_test_test.sh @@ -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 < $run_repo/BUILD +exports_files(["under.sh"]) +EOF + cat < $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 < WORKSPACE +local_repository( + name = "run", + path = "../run", +) +EOF + + mkdir -p testing || fail "mkdir testing failed" + + cat < testing/BUILD +sh_test( + name = "passing_test" , + srcs = [ "passing_test.sh" ]) +EOF + cat < 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