Search in sources :

Example 1 with TargetExpressionList

use of com.google.idea.blaze.base.sync.projectview.TargetExpressionList in project intellij by bazelbuild.

the class BlazeBuildTargetSharder method doExpandWildcardTargets.

private static ExpandedTargetsResult doExpandWildcardTargets(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, BlazeBuildParams buildParams, ProjectViewSet projectViewSet, WorkspacePathResolver pathResolver, List<TargetExpression> targets) {
    List<WildcardTargetPattern> includes = getWildcardPatterns(targets);
    if (includes.isEmpty()) {
        return new ExpandedTargetsResult(targets, BuildResult.SUCCESS);
    }
    Map<TargetExpression, List<TargetExpression>> expandedTargets = WildcardTargetExpander.expandToNonRecursiveWildcardTargets(project, context, pathResolver, includes);
    if (expandedTargets == null) {
        return new ExpandedTargetsResult(ImmutableList.of(), BuildResult.FATAL_ERROR);
    }
    // replace original recursive targets with expanded list, retaining relative ordering
    List<TargetExpression> fullList = new ArrayList<>();
    for (TargetExpression target : targets) {
        List<TargetExpression> expanded = expandedTargets.get(target);
        if (expanded == null) {
            fullList.add(target);
        } else {
            fullList.addAll(expanded);
        }
    }
    ExpandedTargetsResult result = WildcardTargetExpander.expandToSingleTargets(project, context, workspaceRoot, buildParams, projectViewSet, fullList);
    // finally add back any explicitly-specified, unexcluded single targets which may have been
    // removed by the query (for example, because they have the 'manual' tag)
    TargetExpressionList helper = TargetExpressionList.create(targets);
    List<TargetExpression> singleTargets = targets.stream().filter(t -> !t.isExcluded()).filter(t -> !isWildcardPattern(t)).filter(t -> t instanceof Label).filter(t -> helper.includesTarget((Label) t)).collect(toImmutableList());
    return ExpandedTargetsResult.merge(result, new ExpandedTargetsResult(singleTargets, result.buildResult));
}
Also used : ExpandedTargetsResult(com.google.idea.blaze.base.sync.sharding.WildcardTargetExpander.ExpandedTargetsResult) TargetShardSizeSection(com.google.idea.blaze.base.projectview.section.sections.TargetShardSizeSection) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) BuildBinaryType(com.google.idea.blaze.base.settings.BuildBinaryType) ArrayList(java.util.ArrayList) ShardBlazeBuildsSection(com.google.idea.blaze.base.projectview.section.sections.ShardBlazeBuildsSection) BlazeBuildParams(com.google.idea.blaze.base.sync.BlazeBuildParams) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Project(com.intellij.openapi.project.Project) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Math.min(java.lang.Math.min) IntExperiment(com.google.idea.common.experiments.IntExperiment) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) WildcardTargetPattern(com.google.idea.blaze.base.model.primitives.WildcardTargetPattern) TargetExpressionList(com.google.idea.blaze.base.sync.projectview.TargetExpressionList) Label(com.google.idea.blaze.base.model.primitives.Label) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ShardStats(com.google.idea.blaze.base.logging.utils.ShardStats) VisibleForTesting(com.google.common.annotations.VisibleForTesting) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) WildcardTargetPattern(com.google.idea.blaze.base.model.primitives.WildcardTargetPattern) ArrayList(java.util.ArrayList) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) TargetExpressionList(com.google.idea.blaze.base.sync.projectview.TargetExpressionList) ExpandedTargetsResult(com.google.idea.blaze.base.sync.sharding.WildcardTargetExpander.ExpandedTargetsResult) TargetExpressionList(com.google.idea.blaze.base.sync.projectview.TargetExpressionList)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 ShardStats (com.google.idea.blaze.base.logging.utils.ShardStats)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)1 WildcardTargetPattern (com.google.idea.blaze.base.model.primitives.WildcardTargetPattern)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 ProjectViewManager (com.google.idea.blaze.base.projectview.ProjectViewManager)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 ShardBlazeBuildsSection (com.google.idea.blaze.base.projectview.section.sections.ShardBlazeBuildsSection)1 TargetShardSizeSection (com.google.idea.blaze.base.projectview.section.sections.TargetShardSizeSection)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 Scope (com.google.idea.blaze.base.scope.Scope)1 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)1 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)1 EventType (com.google.idea.blaze.base.scope.scopes.TimingScope.EventType)1 BuildBinaryType (com.google.idea.blaze.base.settings.BuildBinaryType)1