Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Incompatible Target Skipping for test args #13219

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ public static RunfilesSupport withExecutable(
computeActionEnvironment(ruleContext));
}

/**
* Creates and returns a {@link RunfilesSupport} object for the given rule and executable. This
* version discards all arguments. Only use this for
* <a href="https://docs.bazel.build/versions/master/platforms.html#skipping-incompatible-targets">Incompatible Target Skipping</a>.
*/
public static RunfilesSupport withExecutableButNoArgs(
RuleContext ruleContext, Runfiles runfiles, Artifact executable) {
return RunfilesSupport.create(
ruleContext,
executable,
runfiles,
CommandLine.EMPTY,
computeActionEnvironment(ruleContext));
}

private static CommandLine computeArgs(RuleContext ruleContext, CommandLine additionalArgs) {
if (!ruleContext.getRule().isAttrDefined("args", Type.STRING_LIST)) {
// Some non-_binary rules create RunfilesSupport instances; it is fine to not have an args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ private static ConfiguredTarget createIncompatibleConfiguredTarget(
if (!outputArtifacts.isEmpty()) {
Artifact executable = outputArtifacts.get(0);
RunfilesSupport runfilesSupport =
RunfilesSupport.withExecutable(ruleContext, runfiles, executable);
RunfilesSupport.withExecutableButNoArgs(ruleContext, runfiles, executable);
builder.setRunfilesSupport(runfilesSupport, executable);

ruleContext.registerAction(
Expand Down
22 changes: 21 additions & 1 deletion src/test/shell/integration/target_compatible_with_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ function atest_build_event_protocol() {
# incompatible targets are themselves deemed incompatible and should therefore
# not be built.
function test_non_top_level_skipping() {
cat >> target_skipping/BUILD <<EOF
touch target_skipping/foo_test.sh
chmod +x target_skipping/foo_test.sh

cat >> target_skipping/BUILD <<'EOF'
genrule(
name = "genrule_foo1",
target_compatible_with = [":foo1"],
Expand All @@ -383,6 +386,15 @@ sh_binary(
srcs = ["foo1.sh"],
target_compatible_with = [":foo2"],
)

# Make sure that using an incompatible target in Make variable substitution
# doesn't produce an unexpected error.
sh_test(
name = "foo_test",
srcs = ["foo_test.sh"],
data = [":some_foo3_target"],
args = ["$(location :some_foo3_target)"],
)
EOF

cd target_skipping || fail "couldn't cd into workspace"
Expand All @@ -394,6 +406,14 @@ EOF
//target_skipping:sh_foo2 &> "${TEST_log}" && fail "Bazel passed unexpectedly."
expect_log 'ERROR: Target //target_skipping:sh_foo2 is incompatible and cannot be built, but was explicitly requested'
expect_log 'FAILED: Build did NOT complete successfully'

bazel build \
--show_result=10 \
--host_platform=@//target_skipping:foo2_bar1_platform \
--platforms=@//target_skipping:foo2_bar1_platform \
//target_skipping:foo_test &> "${TEST_log}" && fail "Bazel passed unexpectedly."
expect_log 'ERROR: Target //target_skipping:foo_test is incompatible and cannot be built, but was explicitly requested'
expect_log 'FAILED: Build did NOT complete successfully'
}

# Validate that targets are skipped when the implementation is in Starlark
Expand Down