From 38349f4226beed5873dbeaeb17093ea1887707b8 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 27 Feb 2023 21:04:38 -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 Closes #17590. Change-Id: If5960a6abb08f8fe4f2643af6249c8528b7a2c51 PiperOrigin-RevId: 512820070 --- .../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 350541aee2ad63..6c85fd43b93db5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -2252,6 +2252,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 234ac30a38fdcc..ca7c90d0609167 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 '^FAILED: 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() {