Search in sources :

Example 1 with RuleTypeAndLabel

use of com.google.idea.blaze.base.sync.sharding.QueryResultLineProcessor.RuleTypeAndLabel in project intellij by bazelbuild.

the class WildcardTargetExpander method queryIndividualTargets.

/**
 * Runs a blaze query to expand the input target patterns to individual blaze targets.
 */
private static ExpandedTargetsResult queryIndividualTargets(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ImmutableSet<String> handledRuleTypes, List<TargetExpression> targetPatterns) {
    String query = queryString(targetPatterns);
    if (query.isEmpty()) {
        // will be empty if there are no non-excluded targets
        return new ExpandedTargetsResult(ImmutableList.of(), BuildResult.SUCCESS);
    }
    BlazeCommand.Builder builder = BlazeCommand.builder(getBinaryPath(project), BlazeCommandName.QUERY).addBlazeFlags(BlazeFlags.KEEP_GOING).addBlazeFlags("--output=label_kind").addBlazeFlags(queryString(targetPatterns));
    ImmutableList.Builder<TargetExpression> output = ImmutableList.builder();
    // it's fine to include wildcards here; they're guaranteed not to clash with actual labels.
    Set<String> explicitTargets = targetPatterns.stream().map(TargetExpression::toString).collect(Collectors.toSet());
    Predicate<RuleTypeAndLabel> filter = !filterByRuleType.getValue() ? t -> true : t -> handledRuleTypes.contains(t.ruleType) || explicitTargets.contains(t.label);
    int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(builder.build()).context(context).stdout(LineProcessingOutputStream.of(new QueryResultLineProcessor(output, filter))).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
    BuildResult buildResult = BuildResult.fromExitCode(retVal);
    return new ExpandedTargetsResult(output.build(), buildResult);
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ImmutableList(com.google.common.collect.ImmutableList) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) RuleTypeAndLabel(com.google.idea.blaze.base.sync.sharding.QueryResultLineProcessor.RuleTypeAndLabel) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)1 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)1 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)1 RuleTypeAndLabel (com.google.idea.blaze.base.sync.sharding.QueryResultLineProcessor.RuleTypeAndLabel)1