use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class BuckQueryEnvironment method getFwdDeps.
@Override
public ImmutableSet<QueryTarget> getFwdDeps(Iterable<QueryTarget> targets) throws QueryException, InterruptedException {
ImmutableSet.Builder<QueryTarget> result = new ImmutableSet.Builder<>();
for (QueryTarget target : targets) {
TargetNode<?, ?> node = getNode(target);
result.addAll(getTargetsFromTargetNodes(graph.getOutgoingNodesFor(node)));
}
return result.build();
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class GraphEnhancementQueryEnvironment method getFwdDeps.
@Override
public ImmutableSet<QueryTarget> getFwdDeps(Iterable<QueryTarget> targets) throws QueryException, InterruptedException {
ImmutableSet.Builder<QueryTarget> builder = ImmutableSet.builder();
for (QueryTarget target : targets) {
List<QueryBuildTarget> deps = getNode(target).getDeps().stream().map(QueryBuildTarget::of).collect(Collectors.toList());
builder.addAll(deps);
}
return builder.build();
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class QueryUtils method resolveDepQuery.
public static Stream<BuildRule> resolveDepQuery(BuildRuleParams params, Query query, BuildRuleResolver resolver, TargetGraph targetGraph) {
BuildTarget target = params.getBuildTarget();
Set<BuildTarget> declaredDeps = params.getDeclaredDeps().get().stream().map(BuildRule::getBuildTarget).collect(Collectors.toSet());
GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.of(resolver), Optional.of(targetGraph), params.getCellRoots(), BuildTargetPatternParser.forBaseName(target.getBaseName()), declaredDeps);
ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
try {
QueryExpression parsedExp = QueryExpression.parse(query.getQuery(), env);
Set<QueryTarget> queryTargets = parsedExp.eval(env, executorService);
return queryTargets.stream().map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget());
});
} catch (QueryException e) {
throw new RuntimeException("Error parsing/executing query from deps for " + target, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Error executing query from deps for " + target, e);
}
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class QueryUtils method extractBuildTargets.
public static Stream<BuildTarget> extractBuildTargets(CellPathResolver cellPathResolver, BuildTargetPatternParser<BuildTargetPattern> parserPattern, Query query) throws QueryException {
GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.empty(), Optional.empty(), cellPathResolver, parserPattern, ImmutableSet.of());
ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
QueryExpression parsedExp = QueryExpression.parse(query.getQuery(), env);
List<String> targetLiterals = new ArrayList<>();
parsedExp.collectTargetPatterns(targetLiterals);
return targetLiterals.stream().flatMap(pattern -> {
try {
return env.getTargetsMatchingPattern(pattern, executorService).stream();
} catch (Exception e) {
throw new RuntimeException("Error parsing target expression", e);
}
}).map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return ((QueryBuildTarget) queryTarget).getBuildTarget();
});
}
Aggregations