Fix ctr.rule.attr possibly returning a ComputedDefault object instead of its Starlark value.
The Starlark code is now closer to that of DependencyResolver.
@@ -59,6 +59,7 @@ import com.google.devtools.build.lib.collect.nestedset.Depset;
import com.google.devtools.build.lib.packages.Aspect;
import com.google.devtools.build.lib.packages.AspectDescriptor;
import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.Attribute.ComputedDefault;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.StarlarkImplicitOutputsFunction;
@@ -229,7 +230,11 @@ public final class StarlarkRuleContext implements StarlarkRuleContextApi<Constra
StarlarkAttributesCollection.Builder aspectBuilder =
StarlarkAttributesCollection.builder(this);
for (Attribute attribute : attributes) {
- aspectBuilder.addAttribute(attribute, attribute.getDefaultValue(ruleContext.getRule()));
+ Object defaultValue = attribute.getDefaultValue(ruleContext.getRule());
+ if (defaultValue instanceof ComputedDefault) {
+ defaultValue = ((ComputedDefault) defaultValue).getDefault(ruleContext.attributes());
+ }
+ aspectBuilder.addAttribute(attribute, defaultValue);
}
this.attributesCollection = aspectBuilder.build();
@@ -246,7 +251,11 @@ public final class StarlarkRuleContext implements StarlarkRuleContextApi<Constra
continue;
}
for (Attribute attribute : aspect.getDefinition().getAttributes().values()) {
- ruleBuilder.addAttribute(attribute, attribute.getDefaultValue(ruleContext.getRule()));
+ Object defaultValue = attribute.getDefaultValue(ruleContext.getRule());
+ if (defaultValue instanceof ComputedDefault) {
+ defaultValue = ((ComputedDefault) defaultValue).getDefault(ruleContext.attributes());
+ }
+ ruleBuilder.addAttribute(attribute, defaultValue);
}
}
