Search in sources :

Example 1 with OutputFileConfiguredTarget

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AttributeMap(com.google.devtools.build.lib.packages.AttributeMap) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) OutputFileConfiguredTarget(com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)

Aggregations

OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 Label (com.google.devtools.build.lib.cmdline.Label)1 Attribute (com.google.devtools.build.lib.packages.Attribute)1 AttributeMap (com.google.devtools.build.lib.packages.AttributeMap)1 LinkedHashSet (java.util.LinkedHashSet)1