From 558ea80610e1bd62a548bda941c00940acd53954 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 24 Feb 2023 11:47:01 -0800 Subject: [PATCH] Fix Bazel 6.0 crash regression. Stop crashes when incompatible target skipping mixes with ---auto_cpu_environment_group. Fixes https://github.com/bazelbuild/bazel/issues/17561. PiperOrigin-RevId: 512125121 Change-Id: If5960a6abb08f8fe4f2643af6249c8528b7a2c51 --- .../google/devtools/build/lib/analysis/BUILD | 2 ++ .../IncompatibleTargetChecker.java | 6 +++- .../target_compatible_with_test.sh | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index 0b2ed995ded177..def0888963071f 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -2245,6 +2245,8 @@ java_library( srcs = ["constraints/IncompatibleTargetChecker.java"], deps = [ ":analysis_cluster", + ":constraints/environment_collection", + ":constraints/supported_environments", ":file_provider", ":incompatible_platform_provider", ":test/test_configuration", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/IncompatibleTargetChecker.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/IncompatibleTargetChecker.java index 29e7c78179bc63..2f4bb040daf303 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/IncompatibleTargetChecker.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/IncompatibleTargetChecker.java @@ -18,6 +18,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.ConfiguredTargetValue; @@ -234,7 +235,10 @@ private static RuleConfiguredTargetValue createIncompatibleRuleConfiguredTarget( .put(incompatiblePlatformProvider) .add(RunfilesProvider.simple(Runfiles.EMPTY)) .add(fileProvider) - .add(filesToRunProvider); + .add(filesToRunProvider) + .add( + new SupportedEnvironments( + EnvironmentCollection.EMPTY, EnvironmentCollection.EMPTY, ImmutableMap.of())); if (configuration.hasFragment(TestConfiguration.class)) { // Create a dummy TestProvider instance so that other parts of the code base stay happy. Even // though this test will never execute, some code still expects the provider. diff --git a/src/test/shell/integration/target_compatible_with_test.sh b/src/test/shell/integration/target_compatible_with_test.sh index 93da0d05e75265..765892526c1ce5 100755 --- a/src/test/shell/integration/target_compatible_with_test.sh +++ b/src/test/shell/integration/target_compatible_with_test.sh @@ -475,6 +475,38 @@ function test_failure_on_incompatible_top_level_target() { expect_log '^ERROR: Build did NOT complete successfully' } +# https://github.com/bazelbuild/bazel/issues/17561 regression test: incompatible +# target skipping doesn't crash with --auto_cpu_environment_group. +function test_failure_on_incompatible_top_level_target_and_auto_cpu_environment_group() { + cat >> target_skipping/BUILD <> buildenv/cpus/BUILD < "${TEST_log}" \ + || fail "Bazel failed unexpectedly." + + expect_log 'Target //target_skipping:always_incompatible build was skipped' +} + # Crudely validates that the build event protocol contains useful information # when targets are skipped due to incompatibilities. function test_build_event_protocol() {