Search in sources :

Example 1 with ProjectTargets

use of com.google.idea.blaze.base.sync.SyncProjectTargetsHelper.ProjectTargets in project intellij by bazelbuild.

the class BuildPhaseSyncTask method doRun.

private void doRun(BlazeContext context) throws SyncFailedException, SyncCanceledException {
    List<TargetExpression> targets = Lists.newArrayList();
    ProjectViewSet viewSet = projectState.getProjectViewSet();
    if (syncParams.addWorkingSet() && projectState.getWorkingSet() != null) {
        Collection<TargetExpression> workingSetTargets = getWorkingSetTargets(context);
        if (!workingSetTargets.isEmpty()) {
            targets.addAll(workingSetTargets);
            printTargets(context, "working set", workingSetTargets);
        }
    }
    if (syncParams.addProjectViewTargets()) {
        ProjectTargets projectTargets = SyncProjectTargetsHelper.getProjectTargets(project, context, viewSet, projectState.getWorkspacePathResolver(), projectState.getLanguageSettings());
        if (!projectTargets.derivedTargets.isEmpty()) {
            buildStats.setTargetsDerivedFromDirectories(true);
            printTargets(context, "project view directories", projectTargets.derivedTargets);
        }
        if (!projectTargets.explicitTargets.isEmpty()) {
            printTargets(context, "project view targets", projectTargets.explicitTargets);
        }
        targets.addAll(projectTargets.getTargetsToSync());
    }
    if (!syncParams.sourceFilesToSync().isEmpty()) {
        Collection<TargetExpression> targetsFromSources = findTargetsBuildingSourceFiles(syncParams.sourceFilesToSync(), context);
        if (!targetsFromSources.isEmpty()) {
            targets.addAll(targetsFromSources);
            printTargets(context, syncParams.title() + " (targets derived from query)", targetsFromSources);
        }
    }
    if (!syncParams.targetExpressions().isEmpty()) {
        targets.addAll(syncParams.targetExpressions());
        printTargets(context, syncParams.title(), syncParams.targetExpressions());
    }
    buildStats.setTargets(targets);
    notifyBuildStarted(context, syncParams.addProjectViewTargets(), ImmutableList.copyOf(targets));
    BuildInvoker localInvoker = buildSystem.getBuildInvoker(project, context);
    ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, viewSet, projectState.getWorkspacePathResolver(), targets, localInvoker, buildSystem.getSyncStrategy(project));
    if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        throw new SyncFailedException();
    }
    ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
    boolean parallel;
    SyncStrategy strategy = buildSystem.getSyncStrategy(project);
    switch(strategy) {
        case PARALLEL:
            parallel = true;
            break;
        case DECIDE_AUTOMATICALLY:
            parallel = shardedTargets.shardCount() > 1;
            break;
        case SERIAL:
            parallel = false;
            break;
        default:
            throw new IllegalStateException("Invalid sync strategy: " + strategy);
    }
    if (!shardedTargetsResult.shardedTargets.shardStats().shardingApproach().equals(ShardingApproach.PARTITION_WITHOUT_EXPANDING)) {
        int targetCount = shardedTargets.shardStats().actualTargetSizePerShard().stream().mapToInt(Integer::intValue).sum();
        printShardingSummary(context, targetCount, shardedTargets.shardCount(), parallel);
    }
    BuildInvoker syncBuildInvoker = null;
    if (parallel) {
        syncBuildInvoker = buildSystem.getParallelBuildInvoker(project, context).orElse(null);
    }
    if (syncBuildInvoker == null) {
        syncBuildInvoker = localInvoker;
    }
    resultBuilder.setBlazeInfo(syncBuildInvoker.getBlazeInfo());
    buildStats.setSyncSharded(shardedTargets.shardCount() > 1).setShardCount(shardedTargets.shardCount()).setShardStats(shardedTargets.shardStats()).setParallelBuilds(syncBuildInvoker.supportsParallelism());
    BlazeBuildOutputs blazeBuildResult = getBlazeBuildResult(context, viewSet, shardedTargets, syncBuildInvoker);
    resultBuilder.setBuildResult(blazeBuildResult);
    buildStats.setBuildResult(blazeBuildResult.buildResult).setBuildIds(blazeBuildResult.buildIds).setBuildBinaryType(syncBuildInvoker.getType()).setBepBytesConsumed(blazeBuildResult.bepBytesConsumed);
    if (context.isCancelled()) {
        throw new SyncCanceledException();
    }
    String invocationResultMsg = "Build invocation result: " + blazeBuildResult.buildResult.status;
    if (blazeBuildResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (blazeBuildResult.buildResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        context.output(PrintOutput.error(invocationResultMsg));
        throw new SyncFailedException();
    }
    context.output(PrintOutput.log(invocationResultMsg));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) ProjectTargets(com.google.idea.blaze.base.sync.SyncProjectTargetsHelper.ProjectTargets) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) SyncStrategy(com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) BuildInvoker(com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker)

Aggregations

BuildInvoker (com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker)1 SyncStrategy (com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy)1 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 ProjectTargets (com.google.idea.blaze.base.sync.SyncProjectTargetsHelper.ProjectTargets)1 SyncCanceledException (com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException)1 SyncFailedException (com.google.idea.blaze.base.sync.SyncScope.SyncFailedException)1 BlazeBuildOutputs (com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs)1 ShardedTargetsResult (com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult)1 ShardedTargetList (com.google.idea.blaze.base.sync.sharding.ShardedTargetList)1