use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException 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));
BlazeBuildParams buildParams = BlazeBuildParams.fromProject(project);
ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, buildParams, viewSet, projectState.getWorkspacePathResolver(), targets);
if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
throw new SyncFailedException();
}
ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
buildStats.setSyncSharded(shardedTargets.shardCount() > 1).setShardCount(shardedTargets.shardCount()).setShardStats(shardedTargets.shardStats()).setParallelBuilds(buildParams.parallelizeBuilds());
BlazeBuildOutputs blazeBuildResult = getBlazeBuildResult(context, viewSet, shardedTargets);
resultBuilder.setBuildResult(blazeBuildResult);
buildStats.setBuildResult(blazeBuildResult.buildResult).setBuildIds(blazeBuildResult.buildIds);
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));
}
use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException in project intellij by bazelbuild.
the class SyncPhaseCoordinator method updateProjectAndFinishSync.
private void updateProjectAndFinishSync(UpdatePhaseTask updateTask, BlazeContext context) {
SyncStats.Builder stats = SyncStats.builder();
SyncResult syncResult = updateTask.syncResult();
try {
fillInBuildStats(stats, updateTask.projectState(), updateTask.buildResult());
if (!syncResult.successful() || !updateTask.buildResult().isValid()) {
return;
}
List<TimedEvent> timedEvents = SyncScope.runWithTiming(context, childContext -> {
ProjectTargetData targetData = updateTargetData(updateTask, childContext);
if (targetData == null) {
childContext.setHasError();
throw new SyncFailedException();
}
ProjectUpdateSyncTask.runProjectUpdatePhase(project, updateTask.syncParams().syncMode(), updateTask.projectState(), targetData, childContext);
}, new TimingScope("Project update phase", EventType.Other));
stats.addTimedEvents(timedEvents);
if (!context.shouldContinue()) {
syncResult = context.isCancelled() ? SyncResult.CANCELLED : SyncResult.FAILURE;
}
} catch (Throwable e) {
logSyncError(context, e);
syncResult = SyncResult.FAILURE;
} finally {
SyncProjectState projectState = updateTask.projectState();
finishSync(updateTask.syncParams(), updateTask.startTime(), context, projectState != null ? projectState.getProjectViewSet() : null, updateTask.buildIds(), syncResult, stats);
}
}
use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException in project intellij by bazelbuild.
the class SyncProjectTargetsHelper method deriveTargetsFromDirectories.
private static ImmutableList<TargetExpression> deriveTargetsFromDirectories(Project project, BlazeContext context, ProjectViewSet projectViewSet, WorkspacePathResolver pathResolver, WorkspaceLanguageSettings languageSettings) throws SyncFailedException, SyncCanceledException {
String fileBugSuggestion = Blaze.getBuildSystem(project) == BuildSystem.Bazel ? "" : " Please run 'Blaze > File a Bug'";
if (!DirectoryToTargetProvider.hasProvider()) {
IssueOutput.error("Can't derive targets from project directories: no query provider available." + fileBugSuggestion).submit(context);
throw new SyncFailedException();
}
ImportRoots importRoots = ImportRoots.builder(project).add(projectViewSet).build();
if (importRoots.rootDirectories().isEmpty()) {
return ImmutableList.of();
}
List<TargetInfo> targets = Scope.push(context, childContext -> {
childContext.push(new TimingScope("QueryDirectoryTargets", EventType.BlazeInvocation));
childContext.output(new StatusOutput("Querying targets in project directories..."));
// We don't want blaze build errors to fail the whole sync
childContext.setPropagatesErrors(false);
return DirectoryToTargetProvider.expandDirectoryTargets(project, importRoots, pathResolver, childContext);
});
if (context.isCancelled()) {
throw new SyncCanceledException();
}
if (targets == null) {
IssueOutput.error("Deriving targets from project directories failed." + fileBugSuggestion).submit(context);
throw new SyncFailedException();
}
ImmutableList<TargetExpression> retained = SourceToTargetFilteringStrategy.filterTargets(targets).stream().filter(t -> t.getKind() != null && t.getKind().getLanguageClasses().stream().anyMatch(languageSettings::isLanguageActive)).map(t -> t.label).collect(toImmutableList());
context.output(PrintOutput.log(String.format("%d targets found under project directories; syncing %d of them.", targets.size(), retained.size())));
return retained;
}
use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException in project intellij by bazelbuild.
the class ProjectUpdateSyncTask method run.
private void run(BlazeContext context) throws SyncCanceledException, SyncFailedException {
TargetMap targetMap = targetData.targetMap;
RemoteOutputArtifacts oldRemoteState = RemoteOutputArtifacts.fromProjectData(oldProjectData);
RemoteOutputArtifacts newRemoteState = targetData.remoteOutputs;
ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(projectState.getBlazeInfo(), projectState.getWorkspacePathResolver(), newRemoteState);
Scope.push(context, childContext -> {
childContext.push(new TimingScope("UpdateRemoteOutputsCache", EventType.Prefetching));
RemoteOutputsCache.getInstance(project).updateCache(context, targetMap, projectState.getLanguageSettings(), newRemoteState, oldRemoteState, /* clearCache= */
syncMode == SyncMode.FULL);
});
SyncState.Builder syncStateBuilder = new SyncState.Builder();
Scope.push(context, childContext -> {
childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectState.getProjectViewSet(), projectState.getLanguageSettings(), projectState.getBlazeVersionData(), projectState.getWorkingSet(), artifactLocationDecoder, targetMap, syncStateBuilder, oldProjectData != null ? oldProjectData.getSyncState() : null, syncMode);
}
});
if (context.isCancelled()) {
throw new SyncCanceledException();
}
if (context.hasErrors()) {
throw new SyncFailedException();
}
BlazeProjectData newProjectData = new BlazeProjectData(targetData, projectState.getBlazeInfo(), projectState.getBlazeVersionData(), projectState.getWorkspacePathResolver(), artifactLocationDecoder, projectState.getLanguageSettings(), syncStateBuilder.build());
FileCaches.onSync(project, context, projectState.getProjectViewSet(), newProjectData, oldProjectData, syncMode);
ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectState.getProjectViewSet(), newProjectData);
FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectState.getProjectViewSet());
refreshVirtualFileSystem(context, project, newProjectData);
DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
if (directoryStructure == null) {
throw new SyncFailedException();
}
boolean success = updateProject(context, projectState.getProjectViewSet(), projectState.getBlazeVersionData(), directoryStructure, oldProjectData, newProjectData);
if (!success) {
throw new SyncFailedException();
}
}
use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException in project intellij by bazelbuild.
the class BuildPhaseSyncTask method findTargetsBuildingSourceFiles.
/**
* Finds the list of targets to sync for the given source files. Ignores directories, and sources
* not covered by the .bazelproject directories.
*/
private ImmutableList<TargetExpression> findTargetsBuildingSourceFiles(Collection<WorkspacePath> sources, BlazeContext context) throws SyncCanceledException, SyncFailedException {
ImportRoots importRoots = getImportRoots();
ImmutableList.Builder<TargetExpression> targets = ImmutableList.builder();
ImmutableList.Builder<WorkspacePath> pathsToQuery = ImmutableList.builder();
for (WorkspacePath source : sources) {
File file = projectState.getWorkspacePathResolver().resolveToFile(source);
if (FileOperationProvider.getInstance().isDirectory(file)) {
continue;
}
if (!importRoots.containsWorkspacePath(source)) {
continue;
}
if (Blaze.getBuildSystemProvider(project).isBuildFile(file.getName())) {
targets.add(TargetExpression.allFromPackageNonRecursive(source.getParent()));
continue;
}
pathsToQuery.add(source);
}
List<TargetInfo> result = Scope.push(context, childContext -> {
childContext.push(new TimingScope("QuerySourceTargets", EventType.BlazeInvocation));
childContext.output(new StatusOutput("Querying targets building source files..."));
// We don't want blaze build errors to fail the whole sync
childContext.setPropagatesErrors(false);
return BlazeQuerySourceToTargetProvider.getTargetsBuildingSourceFiles(project, pathsToQuery.build(), childContext, ContextType.Sync);
});
if (context.isCancelled()) {
throw new SyncCanceledException();
}
if (result == null) {
String fileBugSuggestion = Blaze.getBuildSystem(project) == BuildSystem.Bazel ? "" : " Please run 'Blaze > File a Bug'";
IssueOutput.error("Querying blaze targets building project source files failed." + fileBugSuggestion).submit(context);
throw new SyncFailedException();
}
targets.addAll(result.stream().map(t -> t.label).collect(toImmutableList()));
return targets.build();
}
Aggregations