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 builds for filegroup targets with incompatible dependencies #12601

Closed
wants to merge 1 commit into from
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 @@ -854,12 +854,9 @@ public static ConfiguredTarget incompatibleConfiguredTarget(
RuleContext ruleContext,
OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> prerequisiteMap)
throws ActionConflictException, InterruptedException {
if (!ruleContext.getRule().getRuleClassObject().useToolchainResolution()) {
return null;
}

// This is incompatible if explicitly specified to be.
if (ruleContext.attributes().has("target_compatible_with")) {
if (ruleContext.getRule().getRuleClassObject().useToolchainResolution() &&
ruleContext.attributes().has("target_compatible_with")) {
ImmutableList<ConstraintValueInfo> invalidConstraintValues =
stream(
PlatformProviderUtils.constraintValues(
Expand Down
45 changes: 45 additions & 0 deletions src/test/shell/integration/target_compatible_with_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,51 @@ function test_console_log_for_tests() {
expect_log '^//target_skipping:pass_on_foo1_bar2 * PASSED in'
}

# Validates that filegroups (i.e. a rule that doesn't use toolchain resolution)
# is correctly skipped when it depends on an incomaptible target. This is a
# regression test for https://github.com/bazelbuild/bazel/issues/12582.
function test_filegroup() {
cat > target_skipping/binary.cc <<EOF
#include <cstdio>
int main() {
return 0;
}
EOF

cat >> target_skipping/BUILD <<EOF
cc_binary(
name = "binary",
srcs = ["binary.cc"],
target_compatible_with = [
":foo3",
],
)

filegroup(
name = "filegroup",
srcs = [
":binary",
],
)
EOF

cd target_skipping || fail "couldn't cd into workspace"

bazel build \
--show_result=10 \
--host_platform=@//target_skipping:foo1_bar1_platform \
--platforms=@//target_skipping:foo1_bar1_platform \
:all &> "${TEST_log}" || fail "Bazel failed unexpectedly."
expect_log 'Target //target_skipping:filegroup was skipped'

bazel build \
--show_result=10 \
--host_platform=@//target_skipping:foo1_bar1_platform \
--platforms=@//target_skipping:foo1_bar1_platform \
:filegroup &> "${TEST_log}" && fail "Bazel passed unexpectedly."
expect_log 'Target //target_skipping:filegroup is incompatible and cannot be built'
}

# Validates that incompatible target skipping errors behave nicely with
# --keep_going. In other words, even if there's an error in the target skipping
# (e.g. because the user explicitly requested an incompatible target) we still
Expand Down