use of com.facebook.buck.query.QueryBuildTarget in project buck by facebook.
the class BuckQueryEnvironment method getOrCreateQueryBuildTarget.
private QueryTarget getOrCreateQueryBuildTarget(BuildTarget buildTarget) {
if (buildTargetToQueryTarget.containsKey(buildTarget)) {
return buildTargetToQueryTarget.get(buildTarget);
}
QueryBuildTarget queryBuildTarget = QueryBuildTarget.of(buildTarget);
buildTargetToQueryTarget.put(buildTarget, queryBuildTarget);
return queryBuildTarget;
}
use of com.facebook.buck.query.QueryBuildTarget in project buck by facebook.
the class QueryOutputsMacroExpander method expandFrom.
@Override
public String expandFrom(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver resolver, QueryOutputsMacro input) throws MacroException {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.getQuery().getQuery());
return resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget());
}).map(BuildRule::getSourcePathToOutput).filter(Objects::nonNull).map(pathResolver::getAbsolutePath).map(Path::toString).sorted().collect(Collectors.joining(" "));
}
use of com.facebook.buck.query.QueryBuildTarget in project buck by facebook.
the class QueryTargetsMacroExpander method expandFrom.
@Override
public String expandFrom(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver resolver, QueryTargetsMacro input) throws MacroException {
String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.getQuery().getQuery());
return resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
BuildRule rule = resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget());
return rule.getBuildTarget().toString();
}).sorted().collect(Collectors.joining(" "));
}
use of com.facebook.buck.query.QueryBuildTarget 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.QueryBuildTarget 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);
}
}
Aggregations