use of com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget 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);
}
Aggregations