Search in sources :

Example 1 with TargetNotFoundException

use of com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetNotFoundException in project bazel by bazelbuild.

the class BlazeTargetAccessor method getLabelListAttr.

@Override
public List<Target> getLabelListAttr(QueryExpression caller, Target target, String attrName, String errorMsgPrefix) throws QueryException, InterruptedException {
    Preconditions.checkArgument(target instanceof Rule);
    List<Target> result = new ArrayList<>();
    Rule rule = (Rule) target;
    AggregatingAttributeMapper attrMap = AggregatingAttributeMapper.of(rule);
    Type<?> attrType = attrMap.getAttributeType(attrName);
    if (attrType == null) {
        // Return an empty list if the attribute isn't defined for this rule.
        return ImmutableList.of();
    }
    for (Label label : attrMap.getReachableLabels(attrName, false)) {
        try {
            result.add(queryEnvironment.getTarget(label));
        } catch (TargetNotFoundException e) {
            queryEnvironment.reportBuildFileError(caller, errorMsgPrefix + e.getMessage());
        }
    }
    return result;
}
Also used : Target(com.google.devtools.build.lib.packages.Target) TargetNotFoundException(com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetNotFoundException) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule) AggregatingAttributeMapper(com.google.devtools.build.lib.packages.AggregatingAttributeMapper)

Aggregations

Label (com.google.devtools.build.lib.cmdline.Label)1 AggregatingAttributeMapper (com.google.devtools.build.lib.packages.AggregatingAttributeMapper)1 Rule (com.google.devtools.build.lib.packages.Rule)1 Target (com.google.devtools.build.lib.packages.Target)1 TargetNotFoundException (com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetNotFoundException)1 ArrayList (java.util.ArrayList)1