Search in sources :

Example 6 with QueryBuildTarget

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;
}
Also used : QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 7 with 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(" "));
}
Also used : Path(java.nio.file.Path) Objects(java.util.Objects) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 8 with QueryBuildTarget

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(" "));
}
Also used : BuildRule(com.facebook.buck.rules.BuildRule) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 9 with QueryBuildTarget

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();
}
Also used : QueryTarget(com.facebook.buck.query.QueryTarget) ImmutableSet(com.google.common.collect.ImmutableSet) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 10 with QueryBuildTarget

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);
    }
}
Also used : QueryTarget(com.facebook.buck.query.QueryTarget) QueryException(com.facebook.buck.query.QueryException) BuildTarget(com.facebook.buck.model.BuildTarget) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) QueryExpression(com.facebook.buck.query.QueryExpression) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Aggregations

QueryBuildTarget (com.facebook.buck.query.QueryBuildTarget)11 QueryTarget (com.facebook.buck.query.QueryTarget)7 BuildTarget (com.facebook.buck.model.BuildTarget)6 ImmutableSet (com.google.common.collect.ImmutableSet)4 QueryException (com.facebook.buck.query.QueryException)3 QueryExpression (com.facebook.buck.query.QueryExpression)3 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)3 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)2 BuildRule (com.facebook.buck.rules.BuildRule)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 CellPathResolver (com.facebook.buck.rules.CellPathResolver)2 TargetGraph (com.facebook.buck.rules.TargetGraph)2 Preconditions (com.google.common.base.Preconditions)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2