diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/RuleContextConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/RuleContextConstraintSemantics.java index 42a38dd920b399..68697aed40cf8c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/RuleContextConstraintSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/RuleContextConstraintSemantics.java @@ -854,12 +854,9 @@ public static ConfiguredTarget incompatibleConfiguredTarget( RuleContext ruleContext, OrderedSetMultimap 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")) { + // The target (ruleContext) is incompatible if explicitly specified to be. + if (ruleContext.getRule().getRuleClassObject().useToolchainResolution() + && ruleContext.attributes().has("target_compatible_with")) { ImmutableList invalidConstraintValues = stream( PlatformProviderUtils.constraintValues( diff --git a/src/test/shell/integration/target_compatible_with_test.sh b/src/test/shell/integration/target_compatible_with_test.sh index f71ca36d6884da..34e42b83752b69 100755 --- a/src/test/shell/integration/target_compatible_with_test.sh +++ b/src/test/shell/integration/target_compatible_with_test.sh @@ -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 incompatible target. This is a +# regression test for https://github.com/bazelbuild/bazel/issues/12582. +function test_filegroup() { + cat > target_skipping/binary.cc < +int main() { + return 0; +} +EOF + + cat >> target_skipping/BUILD < "${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