Search in sources :

Example 6 with 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.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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) File(java.io.File)

Example 7 with SyncFailedException

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();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BlazeVersionData(com.google.idea.blaze.base.model.BlazeVersionData) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Aggregations

SyncFailedException (com.google.idea.blaze.base.sync.SyncScope.SyncFailedException)7 SyncCanceledException (com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException)6 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)5 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)4 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)4 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 BuildInvoker (com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker)2 SyncStrategy (com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy)2 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)2 EventType (com.google.idea.blaze.base.scope.scopes.TimingScope.EventType)2 Blaze (com.google.idea.blaze.base.settings.Blaze)2 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)2 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)2 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)2 Project (com.intellij.openapi.project.Project)2 List (java.util.List)2