aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-06-19 17:43:40 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-06-23 08:58:23 +0000
commite39be2031d2929b32df539b146fb0cb19e54098a (patch)
tree317b9aa0ead4fe7139aaa070db44e8a7a7e6cba6
parent2fa2c1e4e7fcffe94be1272ca7e0b917e84170ce (diff)
Skylark: Fix crash when computed attribute has the wrong type
-- MOS_MIGRATED_REVID=96417471
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
index 1000c3e40f..0dfc6ed374 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
@@ -345,8 +345,11 @@ public abstract class DependencyResolver {
}
}
- private void resolveLateBoundAttributes(Rule rule, BuildConfiguration configuration,
- AttributeMap attributeMap, Iterable<Attribute> attributes,
+ private void resolveLateBoundAttributes(
+ Rule rule,
+ BuildConfiguration configuration,
+ AttributeMap attributeMap,
+ Iterable<Attribute> attributes,
ImmutableSortedKeyListMultimap.Builder<Attribute, LabelAndConfiguration> builder)
throws EvalException {
for (Attribute attribute : attributes) {
@@ -385,17 +388,28 @@ public abstract class DependencyResolver {
if (EvalUtils.isNullOrNone(actualValue)) {
continue;
}
- if (attribute.getType() == Type.LABEL) {
- Label label;
- label = Type.LABEL.cast(actualValue);
- builder.put(attribute, LabelAndConfiguration.of(label, actualConfig));
- } else if (attribute.getType() == Type.LABEL_LIST) {
- for (Label label : Type.LABEL_LIST.cast(actualValue)) {
+ try {
+ if (attribute.getType() == Type.LABEL) {
+ Label label = Type.LABEL.cast(actualValue);
builder.put(attribute, LabelAndConfiguration.of(label, actualConfig));
+ } else if (attribute.getType() == Type.LABEL_LIST) {
+ for (Label label : Type.LABEL_LIST.cast(actualValue)) {
+ builder.put(attribute, LabelAndConfiguration.of(label, actualConfig));
+ }
+ } else {
+ throw new IllegalStateException(
+ String.format(
+ "Late bound attribute '%s' is not a label or a label list",
+ attribute.getName()));
}
- } else {
- throw new IllegalStateException(String.format(
- "Late bound attribute '%s' is not a label or a label list", attribute.getName()));
+ } catch (ClassCastException e) {
+ throw new EvalException(
+ rule.getLocation(),
+ String.format(
+ "When computing the default value of %s, expected '%s', got '%s'",
+ attribute.getName(),
+ attribute.getType(),
+ EvalUtils.getDataTypeName(actualValue, true)));
}
}
}