Search in sources :

Example 6 with QueryException

use of com.facebook.buck.query.QueryException 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)

Example 7 with QueryException

use of com.facebook.buck.query.QueryException 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();
    });
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ImmutableSet(com.google.common.collect.ImmutableSet) CellPathResolver(com.facebook.buck.rules.CellPathResolver) QueryException(com.facebook.buck.query.QueryException) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) BuildRule(com.facebook.buck.rules.BuildRule) List(java.util.List) BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) Stream(java.util.stream.Stream) QueryExpression(com.facebook.buck.query.QueryExpression) BuildTargetPatternParser(com.facebook.buck.parser.BuildTargetPatternParser) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget) QueryTarget(com.facebook.buck.query.QueryTarget) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ArrayList(java.util.ArrayList) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) QueryExpression(com.facebook.buck.query.QueryExpression) QueryException(com.facebook.buck.query.QueryException) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Aggregations

QueryException (com.facebook.buck.query.QueryException)7 BuildTarget (com.facebook.buck.model.BuildTarget)4 QueryExpression (com.facebook.buck.query.QueryExpression)4 QueryTarget (com.facebook.buck.query.QueryTarget)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)4 QueryBuildTarget (com.facebook.buck.query.QueryBuildTarget)3 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)2 BuildTargetPattern (com.facebook.buck.model.BuildTargetPattern)2 MacroException (com.facebook.buck.model.MacroException)2 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 CellPathResolver (com.facebook.buck.rules.CellPathResolver)2 TargetGraph (com.facebook.buck.rules.TargetGraph)2 GraphEnhancementQueryEnvironment (com.facebook.buck.rules.query.GraphEnhancementQueryEnvironment)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 Optional (java.util.Optional)2 Set (java.util.Set)2