use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class AspectDefinitionTest method testAspectWithImplicitOrLateboundAttribute_AddsToAttributeMap.
@Test
public void testAspectWithImplicitOrLateboundAttribute_AddsToAttributeMap() throws Exception {
Attribute implicit = attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time")).build();
LateBoundLabel<String> latebound = new LateBoundLabel<String>() {
@Override
public Label resolve(Rule rule, AttributeMap attributes, String configuration) {
return Label.parseAbsoluteUnchecked("//run:away");
}
};
AspectDefinition simple = new AspectDefinition.Builder(TEST_ASPECT_CLASS).add(implicit).add(attr(":latebound", BuildType.LABEL).value(latebound)).build();
assertThat(simple.getAttributes()).containsEntry("$runtime", implicit);
assertThat(simple.getAttributes()).containsKey(":latebound");
assertThat(simple.getAttributes().get(":latebound").getLateBoundDefault()).isEqualTo(latebound);
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class BuildRuleWithDefaultsBuilder method populateAttributes.
public BuildRuleWithDefaultsBuilder populateAttributes(String rulePkg, boolean heuristics) {
for (Attribute attribute : ruleClass.getAttributes()) {
if (attribute.isMandatory()) {
if (BuildType.isLabelType(attribute.getType())) {
// TODO(bazel-team): actually an empty list would be fine in the case where
// attribute instanceof ListType && !attribute.isNonEmpty(), but BuildRuleBuilder
// doesn't support that, and it makes little sense anyway
populateLabelAttribute(rulePkg, attribute);
} else {
// Non label type attributes
if (attribute.getAllowedValues() instanceof AllowedValueSet) {
Collection<Object> allowedValues = ((AllowedValueSet) attribute.getAllowedValues()).getAllowedValues();
setSingleValueAttribute(attribute.getName(), allowedValues.iterator().next());
} else if (attribute.getType() == Type.STRING) {
populateStringAttribute(attribute);
} else if (attribute.getType() == Type.BOOLEAN) {
populateBooleanAttribute(attribute);
} else if (attribute.getType() == Type.INTEGER) {
populateIntegerAttribute(attribute);
} else if (attribute.getType() == Type.STRING_LIST) {
populateStringListAttribute(attribute);
}
}
// TODO(bazel-team): populate for other data types
} else if (heuristics) {
populateAttributesHeuristics(rulePkg, attribute);
}
}
return this;
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class PostConfiguredTargetFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
ImmutableMap<ActionAnalysisMetadata, ConflictException> badActions = PrecomputedValue.BAD_ACTIONS.get(env);
ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key((ConfiguredTargetKey) skyKey.argument()));
if (env.valuesMissing()) {
return null;
}
for (ActionAnalysisMetadata action : ctValue.getActions()) {
if (badActions.containsKey(action)) {
throw new ActionConflictFunctionException(badActions.get(action));
}
}
ConfiguredTarget ct = ctValue.getConfiguredTarget();
TargetAndConfiguration ctgValue = new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
ImmutableMap<Label, ConfigMatchingProvider> configConditions = getConfigurableAttributeConditions(ctgValue, env);
if (configConditions == null) {
return null;
}
OrderedSetMultimap<Attribute, Dependency> deps;
try {
BuildConfiguration hostConfiguration = buildViewProvider.getSkyframeBuildView().getHostConfiguration(ct.getConfiguration());
SkyframeDependencyResolver resolver = buildViewProvider.getSkyframeBuildView().createDependencyResolver(env);
// We don't track root causes here - this function is only invoked for successfully analyzed
// targets - as long as we redo the exact same steps here as in ConfiguredTargetFunction, this
// can never fail.
deps = resolver.dependentNodeMap(ctgValue, hostConfiguration, /*aspect=*/
null, configConditions);
if (ct.getConfiguration() != null && ct.getConfiguration().useDynamicConfigurations()) {
deps = ConfiguredTargetFunction.getDynamicConfigurations(env, ctgValue, deps, hostConfiguration, ruleClassProvider);
}
} catch (EvalException | ConfiguredTargetFunction.DependencyEvaluationException | InvalidConfigurationException | InconsistentAspectOrderException e) {
throw new PostConfiguredTargetFunctionException(e);
}
env.getValues(Iterables.transform(deps.values(), TO_KEYS));
if (env.valuesMissing()) {
return null;
}
return new PostConfiguredTargetValue(ct);
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class ConstraintSemantics method getConstraintCheckedDependencies.
/**
* Returns all dependencies that should be constraint-checked against the current rule,
* including both "uncoditional" deps (outside selects) and deps that only appear in selects.
*/
private static DepsToCheck getConstraintCheckedDependencies(RuleContext ruleContext) {
Set<TransitiveInfoCollection> depsToCheck = new LinkedHashSet<>();
Set<TransitiveInfoCollection> selectOnlyDeps = new LinkedHashSet<>();
Set<TransitiveInfoCollection> depsOutsideSelects = new LinkedHashSet<>();
AttributeMap attributes = ruleContext.attributes();
for (String attr : attributes.getAttributeNames()) {
Attribute attrDef = attributes.getAttributeDefinition(attr);
if (attrDef.getType().getLabelClass() != LabelClass.DEPENDENCY || attrDef.skipConstraintsOverride()) {
continue;
}
if (!attrDef.checkConstraintsOverride()) {
// determine exactly which rules need to be constraint-annotated for depot migrations.
if (!DependencyFilter.NO_IMPLICIT_DEPS.apply(ruleContext.getRule(), attrDef) || // because --nodistinct_host_configuration subverts that call.
attrDef.getConfigurationTransition() == Attribute.ConfigurationTransition.HOST) {
continue;
}
}
Set<Label> selectOnlyDepsForThisAttribute = getDepsOnlyInSelects(ruleContext, attr, attributes.getAttributeType(attr));
for (TransitiveInfoCollection dep : ruleContext.getPrerequisites(attr, RuleConfiguredTarget.Mode.DONT_CHECK)) {
// Output files inherit the environment spec of their generating rule.
if (dep instanceof OutputFileConfiguredTarget) {
// Note this reassignment means constraint violation errors reference the generating
// rule, not the file. This makes the source of the environmental mismatch more clear.
dep = ((OutputFileConfiguredTarget) dep).getGeneratingRule();
}
// checking, but for now just pass them by.
if (dep.getProvider(SupportedEnvironmentsProvider.class) != null) {
depsToCheck.add(dep);
if (!selectOnlyDepsForThisAttribute.contains(dep.getLabel())) {
depsOutsideSelects.add(dep);
}
}
}
}
for (TransitiveInfoCollection dep : depsToCheck) {
if (!depsOutsideSelects.contains(dep)) {
selectOnlyDeps.add(dep);
}
}
return new DepsToCheck(depsToCheck, selectOnlyDeps);
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class RuleDocumentationAttributeTest method testSynopsisForIntegerAttribute.
@Test
public void testSynopsisForIntegerAttribute() {
final int defaultValue = 384;
Attribute attribute = Attribute.attr("bar_limit", Type.INTEGER).value(defaultValue).build();
RuleDocumentationAttribute attributeDoc = RuleDocumentationAttribute.create(TestRule.class, "testrule", "", 0, "", NO_FLAGS);
attributeDoc.setAttribute(attribute);
String doc = attributeDoc.getSynopsis();
assertEquals("Integer; optional; default is " + defaultValue, doc);
}
Aggregations