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 321f7cde50fd23..848514028d1712 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 @@ -43,6 +43,7 @@ import com.google.devtools.build.lib.analysis.constraints.SupportedEnvironmentsProvider.RemovedEnvironmentCulprit; import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo; import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils; +import com.google.devtools.build.lib.analysis.test.AnalysisTestResultInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -968,6 +969,16 @@ private static ConfiguredTarget createIncompatibleConfiguredTarget( "Both violatedConstraints and targetsResponsibleForIncompatibility are null"); } + // If this is an analysis test, RuleConfiguredTargetBuilder performs some additional sanity + // checks. Satisfy them with an appropriate provider. + if (ruleContext.getRule().isAnalysisTest()) { + builder.addNativeDeclaredProvider( + new AnalysisTestResultInfo( + /*success=*/ false, + "This test is incompatible and should not have been run. Please file a bug" + + " upstream.")); + } + builder.add(RunfilesProvider.class, RunfilesProvider.simple(runfiles)); if (!outputArtifacts.isEmpty()) { Artifact executable = outputArtifacts.get(0); diff --git a/src/test/shell/integration/target_compatible_with_test.sh b/src/test/shell/integration/target_compatible_with_test.sh index c89eb111a69af8..f71ca36d6884da 100755 --- a/src/test/shell/integration/target_compatible_with_test.sh +++ b/src/test/shell/integration/target_compatible_with_test.sh @@ -653,6 +653,49 @@ EOF expect_log '^Hello World$' } +# Validates that we successfully skip analysistest rule targets when they +# depend on incompatible targets. +function test_analysistest() { + setup_skylib_support + + cat > target_skipping/analysistest.bzl <> target_skipping/BUILD < "${TEST_log}" \ + || fail "Bazel failed unexpectedly." + expect_log '^//target_skipping:foo3_analysistest_test * PASSED in' + + bazel test --show_result=10 \ + --host_platform=@//target_skipping:foo1_bar1_platform \ + --platforms=@//target_skipping:foo1_bar1_platform \ + //target_skipping:all &> "${TEST_log}" \ + || fail "Bazel failed unexpectedly." + expect_log '^Target //target_skipping:foo3_analysistest_test was skipped' +} + function write_query_test_targets() { cat >> target_skipping/BUILD <