Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bazel 6.0 crash regression #17613

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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