From ebfb529a78978c3cfd1d93141c7762f908698df9 Mon Sep 17 00:00:00 2001 From: John Cater Date: Mon, 10 Apr 2023 16:04:03 -0400 Subject: [PATCH] Add attribute validation to IncompatibleTargetChecker. This causes errors with configurable `target_compatible_with` to be reported as errors, rather than causing a Bazel crash. Fixes #18021. --- .../IncompatibleTargetChecker.java | 16 +++++++-- .../TopLevelConstraintSemantics.java | 2 +- .../packages/ConfiguredAttributeMapper.java | 6 ++-- .../google/devtools/build/lib/skyframe/BUILD | 1 + .../lib/skyframe/PrerequisiteProducer.java | 36 +++++++++++++++++-- .../target_compatible_with_test.sh | 27 ++++++++++++++ 6 files changed, 79 insertions(+), 9 deletions(-) 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 0519a1f0f897f9..1f49e9a7be74e4 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 @@ -45,6 +45,7 @@ import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper; +import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper.ValidationException; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.PackageSpecification; import com.google.devtools.build.lib.packages.PackageSpecification.PackageGroupContents; @@ -56,6 +57,7 @@ import com.google.devtools.build.lib.util.OrderedSetMultimap; import com.google.devtools.build.skyframe.SkyValue; import com.google.devtools.build.skyframe.state.StateMachine; +import java.util.List; import java.util.Optional; import java.util.function.Consumer; import javax.annotation.Nullable; @@ -115,6 +117,8 @@ public static class IncompatibleTargetProducer implements StateMachine, Consumer /** Sink for the output of this state machine. */ public interface ResultSink { void accept(Optional incompatibleTarget); + + void acceptValidationException(ValidationException e); } public IncompatibleTargetProducer( @@ -148,8 +152,16 @@ public StateMachine step(Tasks tasks, ExtendedEventHandler listener) { return DONE; } - // Resolves the constraint labels. - for (Label label : attrs.get("target_compatible_with", BuildType.LABEL_LIST)) { + // Resolves the constraint labels, checking for invalid configured attributes. + List