Skip to content

Commit 546e9e2

Browse files
keertkgregestren
andauthored
Fix Bazel 6.0 crash regression (bazelbuild#17613)
Stop crashes when incompatible target skipping mixes with ---auto_cpu_environment_group. Fixes bazelbuild#17561. PiperOrigin-RevId: 512125121 Change-Id: If5960a6abb08f8fe4f2643af6249c8528b7a2c51 Closes bazelbuild#17590. Change-Id: If5960a6abb08f8fe4f2643af6249c8528b7a2c51 PiperOrigin-RevId: 512820070 Co-authored-by: Googler <[email protected]>
1 parent b3a254d commit 546e9e2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/main/java/com/google/devtools/build/lib/analysis/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,8 @@ java_library(
22522252
srcs = ["constraints/IncompatibleTargetChecker.java"],
22532253
deps = [
22542254
":analysis_cluster",
2255+
":constraints/environment_collection",
2256+
":constraints/supported_environments",
22552257
":file_provider",
22562258
":incompatible_platform_provider",
22572259
":test/test_configuration",

src/main/java/com/google/devtools/build/lib/analysis/constraints/IncompatibleTargetChecker.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.google.common.collect.ImmutableList.toImmutableList;
1919

2020
import com.google.common.collect.ImmutableList;
21+
import com.google.common.collect.ImmutableMap;
2122
import com.google.devtools.build.lib.actions.Artifact;
2223
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
2324
import com.google.devtools.build.lib.analysis.ConfiguredTargetValue;
@@ -234,7 +235,10 @@ private static RuleConfiguredTargetValue createIncompatibleRuleConfiguredTarget(
234235
.put(incompatiblePlatformProvider)
235236
.add(RunfilesProvider.simple(Runfiles.EMPTY))
236237
.add(fileProvider)
237-
.add(filesToRunProvider);
238+
.add(filesToRunProvider)
239+
.add(
240+
new SupportedEnvironments(
241+
EnvironmentCollection.EMPTY, EnvironmentCollection.EMPTY, ImmutableMap.of()));
238242
if (configuration.hasFragment(TestConfiguration.class)) {
239243
// Create a dummy TestProvider instance so that other parts of the code base stay happy. Even
240244
// though this test will never execute, some code still expects the provider.

src/test/shell/integration/target_compatible_with_test.sh

+32
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,38 @@ function test_failure_on_incompatible_top_level_target() {
475475
expect_log '^FAILED: Build did NOT complete successfully'
476476
}
477477

478+
# https://github.com/bazelbuild/bazel/issues/17561 regression test: incompatible
479+
# target skipping doesn't crash with --auto_cpu_environment_group.
480+
function test_failure_on_incompatible_top_level_target_and_auto_cpu_environment_group() {
481+
cat >> target_skipping/BUILD <<EOF
482+
sh_test(
483+
name = "always_incompatible",
484+
srcs = [":pass.sh"],
485+
target_compatible_with = [":not_compatible"],
486+
)
487+
EOF
488+
489+
mkdir -p buildenv/cpus
490+
cat >> buildenv/cpus/BUILD <<EOF
491+
environment(name = "foo_cpu")
492+
environment_group(
493+
name = "cpus",
494+
defaults = [":foo_cpu"],
495+
environments = [":foo_cpu"],
496+
)
497+
EOF
498+
499+
bazel build \
500+
--nobuild \
501+
--cpu=foo_cpu \
502+
--auto_cpu_environment_group=//buildenv/cpus:cpus \
503+
--build_event_text_file=$TEST_log \
504+
//target_skipping:all &> "${TEST_log}" \
505+
|| fail "Bazel failed unexpectedly."
506+
507+
expect_log 'Target //target_skipping:always_incompatible build was skipped'
508+
}
509+
478510
# Crudely validates that the build event protocol contains useful information
479511
# when targets are skipped due to incompatibilities.
480512
function test_build_event_protocol() {

0 commit comments

Comments
 (0)