Skip to content

Commit

Permalink
Throw an exception when creating the execution transition if no trans…
Browse files Browse the repository at this point in the history
…ition is available.

Fixes #22996.

PiperOrigin-RevId: 656522163
Change-Id: Ibaf96071f23a3ddd060c6e04aebb73ab33ae05ed
  • Loading branch information
katre authored and copybara-github committed Jul 26, 2024
1 parent 66ef8cc commit d08bb13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -79,7 +78,8 @@ public static ExecutionTransitionFactory createFactory(String execGroup) {
Caffeine.newBuilder().weakValues().build();

@Override
public PatchTransition create(AttributeTransitionData dataWithTargetAttributes) {
public PatchTransition create(AttributeTransitionData dataWithTargetAttributes)
throws TransitionCreationException {
// Delete AttributeTransitionData.attributes() so the exec transition doesn't try to read the
// attributes of the target it's attached to. This is for two reasons:
//
Expand All @@ -93,11 +93,13 @@ public PatchTransition create(AttributeTransitionData dataWithTargetAttributes)
.executionPlatform(dataWithTargetAttributes.executionPlatform())
.build();

if (data.analysisData() == null) {
throw new TransitionCreationException(
"expected a Starlark exec transition definition, but was null");
}
@SuppressWarnings("unchecked")
TransitionFactory<AttributeTransitionData> starlarkExecTransitionProvider =
(TransitionFactory<AttributeTransitionData>)
Verify.verifyNotNull(
data.analysisData(), "expected a Starlark exec transition definition");
(TransitionFactory<AttributeTransitionData>) data.analysisData();

return transitionInstanceCache.get(
// A Starlark transition keeps the same instance unless we modify its .bzl file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ public void constraints_overlappingError() throws Exception {
lines.toArray(new String[] {}));
}

@Test
public void constraints_invalidTarget_error() throws Exception {
checkError(
"foo",
"my_platform",
// TODO: https://github.com/bazelbuild/bazel/issues/23126 - Have a better error message.
// Something like "Invalid dependency :lib does not provide ConstraintValueInfo"
"errors encountered while analyzing target",
"""
cc_library(name = "lib")
platform(
name = "my_platform",
constraint_values = [
":lib",
],
)
""");
}

@Test
public void constraints_parent() throws Exception {
constraintBuilder("//foo:setting1").addConstraintValue("value1").write();
Expand Down

0 comments on commit d08bb13

Please sign in to comment.