Skip to content

Commit

Permalink
Fix Bazel 6.0 crash regression (bazelbuild#17613)
Browse files Browse the repository at this point in the history
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 <gregce@google.com>
  • Loading branch information
keertk and gregestren authored Feb 28, 2023
1 parent b3a254d commit 546e9e2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions src/test/shell/integration/target_compatible_with_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
sh_test(
name = "always_incompatible",
srcs = [":pass.sh"],
target_compatible_with = [":not_compatible"],
)
EOF

mkdir -p buildenv/cpus
cat >> buildenv/cpus/BUILD <<EOF
environment(name = "foo_cpu")
environment_group(
name = "cpus",
defaults = [":foo_cpu"],
environments = [":foo_cpu"],
)
EOF

bazel build \
--nobuild \
--cpu=foo_cpu \
--auto_cpu_environment_group=//buildenv/cpus:cpus \
--build_event_text_file=$TEST_log \
//target_skipping:all &> "${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() {
Expand Down

0 comments on commit 546e9e2

Please sign in to comment.