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.getBuildSystemName(project) == BuildSystemName.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();
}
use of com.google.idea.blaze.base.sync.SyncScope.SyncFailedException in project intellij by bazelbuild.
the class ProjectStateSyncTask method getProjectState.
private SyncProjectState getProjectState(BlazeContext context) throws SyncFailedException, SyncCanceledException {
if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
IssueOutput.error(String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory())).submit(context);
throw new SyncFailedException();
}
BlazeVcsHandler vcsHandler = BlazeVcsHandler.vcsHandlerForProject(project);
if (vcsHandler == null) {
IssueOutput.error("Could not find a VCS handler").submit(context);
throw new SyncFailedException();
}
ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
WorkspacePathResolverAndProjectView workspacePathResolverAndProjectView = computeWorkspacePathResolverAndProjectView(context, vcsHandler, executor);
if (workspacePathResolverAndProjectView == null) {
throw new SyncFailedException();
}
ProjectViewSet projectViewSet = workspacePathResolverAndProjectView.projectViewSet;
List<String> syncFlags = BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.INFO, context, BlazeInvocationContext.SYNC_CONTEXT);
ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, importSettings.getBuildSystem(), Blaze.getBuildSystemProvider(project).getBinaryPath(project), workspaceRoot, syncFlags);
ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(project, context, workspaceRoot, executor);
BlazeInfo blazeInfo = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(Blaze.buildSystemName(project) + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", Blaze.buildSystemName(project))).onError(String.format("Could not run %s info", Blaze.buildSystemName(project))).run().result();
if (blazeInfo == null) {
throw new SyncFailedException();
}
BlazeVersionData blazeVersionData = BlazeVersionData.build(Blaze.getBuildSystemProvider(project).getBuildSystem(), workspaceRoot, blazeInfo);
if (!BuildSystemVersionChecker.verifyVersionSupported(context, blazeVersionData)) {
throw new SyncFailedException();
}
WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver;
WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
if (!ProjectViewVerifier.verifyProjectView(project, context, workspacePathResolver, projectViewSet, workspaceLanguageSettings)) {
throw new SyncFailedException();
}
WorkingSet workingSet = FutureUtil.waitForFuture(context, workingSetFuture).timed("WorkingSet", EventType.Other).withProgressMessage("Computing VCS working set...").onError("Could not compute working set").run().result();
if (context.isCancelled()) {
throw new SyncCanceledException();
}
if (context.hasErrors()) {
throw new SyncFailedException();
}
if (workingSet != null) {
printWorkingSet(context, workingSet);
}
return SyncProjectState.builder().setProjectViewSet(projectViewSet).setLanguageSettings(workspaceLanguageSettings).setBlazeVersionData(blazeVersionData).setWorkingSet(workingSet).setWorkspacePathResolver(workspacePathResolver).build();
}
Aggregations