Search in sources :

Example 41 with ProjectViewSet

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

the class KotlinSyncTest method assertViewConfigState.

private void assertViewConfigState(LanguageVersion languageVersion) {
    runBlazeSync(new BlazeSyncParams.Builder("Sync", BlazeSyncParams.SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(getProject()).getProjectViewSet();
    assert projectViewSet != null;
    assertThat(BlazeKotlinLanguageVersionSection.getLanguageLevel(projectViewSet)).isEqualTo(languageVersion);
    // test the compiler reflect the project view.
    CommonCompilerArguments settings = KotlinCommonCompilerArgumentsHolder.Companion.getInstance(getProject()).getSettings();
    assertThat(CommonCompilerArgumentsCompatUtils.getApiVersion(settings)).isEqualTo(languageVersion.getVersionString());
    assertThat(CommonCompilerArgumentsCompatUtils.getLanguageVersion(settings)).isEqualTo(languageVersion.getVersionString());
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) CommonCompilerArguments(org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams)

Example 42 with ProjectViewSet

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

the class ExportRunConfigurationDialog method defaultExportDirectory.

/**
 * Try to find a checked-in project view file. Otherwise, fall back to the workspace root.
 */
@Nullable
private static File defaultExportDirectory(Project project) {
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProjectSafe(project);
    if (workspaceRoot == null) {
        return null;
    }
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet != null) {
        for (ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
            File file = projectViewFile.projectViewFile;
            if (file != null && FileUtil.isAncestor(workspaceRoot.directory(), file, false)) {
                return file.getParentFile();
            }
        }
    }
    return workspaceRoot.directory();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 43 with ProjectViewSet

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

the class BlazeBeforeRunCommandHelper method runBlazeBuild.

/**
 * Kicks off the blaze build task, returning a corresponding {@link ListenableFuture}.
 */
public static ListenableFuture<BuildResult> runBlazeBuild(BlazeCommandRunConfiguration configuration, BuildResultHelper buildResultHelper, List<String> requiredExtraBlazeFlags, List<String> overridableExtraBlazeFlags, String progressMessage) {
    Project project = configuration.getProject();
    BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {

        @Override
        protected BuildResult execute(BlazeContext context) {
            context.push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
            context.output(new StatusOutput(progressMessage));
            BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(configuration.getTarget()).addBlazeFlags(overridableExtraBlazeFlags).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags()).addBlazeFlags(requiredExtraBlazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
            int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            return BuildResult.fromExitCode(exitCode);
        }
    });
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Example 44 with ProjectViewSet

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

the class BlazeConfigurationResolver method buildBlazeConfigurationData.

private void buildBlazeConfigurationData(BlazeContext parentContext, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap, ImmutableMap<File, VirtualFile> headerRoots, ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettings, CompilerInfoCache compilerInfoCache, ExecutionRootPathResolver executionRootPathResolver, BlazeConfigurationResolverResult oldConfigurationData, BlazeConfigurationResolverResult.Builder builder) {
    // Type specification needed to avoid incorrect type inference during command line build.
    Scope.push(parentContext, (ScopedOperation) context -> {
        context.push(new TimingScope("Build C configuration map", EventType.Other));
        ProjectViewTargetImportFilter filter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
        ConcurrentMap<TargetKey, BlazeResolveConfigurationData> targetToData = Maps.newConcurrentMap();
        List<ListenableFuture<?>> targetToDataFutures = blazeProjectData.targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.C).filter(target -> target.kind != Kind.CC_TOOLCHAIN).filter(filter::isSourceTarget).filter(BlazeConfigurationResolver::containsCompiledSources).map(target -> submit(() -> {
            BlazeResolveConfigurationData data = createResolveConfiguration(target, toolchainLookupMap, headerRoots, compilerSettings, compilerInfoCache, executionRootPathResolver);
            if (data != null) {
                targetToData.put(target.key, data);
            }
            return null;
        })).collect(Collectors.toList());
        try {
            Futures.allAsList(targetToDataFutures).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            context.setCancelled();
            return;
        } catch (ExecutionException e) {
            IssueOutput.error("Could not build C resolve configurations: " + e).submit(context);
            logger.error("Could not build C resolve configurations", e);
            return;
        }
        findEquivalenceClasses(context, project, blazeProjectData.workspacePathResolver, targetToData, oldConfigurationData, builder);
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) ExecutionRootPathResolver(com.google.idea.blaze.base.sync.workspace.ExecutionRootPathResolver) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Logger(com.intellij.openapi.diagnostic.Logger) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableMap(com.google.common.collect.ImmutableMap) CompilerInfoCache(com.jetbrains.cidr.toolchains.CompilerInfoCache) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) List(java.util.List) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Queue(java.util.Queue) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Multimap(com.google.common.collect.Multimap) VfsUtils(com.google.idea.blaze.base.io.VfsUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Maps(com.google.common.collect.Maps) File(java.io.File) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) Futures(com.google.common.util.concurrent.Futures) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ArrayDeque(java.util.ArrayDeque) ScopedOperation(com.google.idea.blaze.base.scope.ScopedOperation) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExecutionException(java.util.concurrent.ExecutionException)

Example 45 with ProjectViewSet

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

the class BlazeAndroidTestLaunchTask method perform.

@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    BlazeExecutor executor = BlazeExecutor.getInstance();
    ProcessHandlerLaunchStatus processHandlerLaunchStatus = (ProcessHandlerLaunchStatus) launchStatus;
    final ProcessHandler processHandler = processHandlerLaunchStatus.getProcessHandler();
    blazeResult = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return Scope.root(new ScopedFunction<Boolean>() {

                @Override
                public Boolean execute(@NotNull BlazeContext context) {
                    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
                    if (projectViewSet == null) {
                        IssueOutput.error("Could not load project view. Please resync project.").submit(context);
                        return false;
                    }
                    BlazeCommand.Builder commandBuilder = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.TEST).addTargets(target);
                    // Build flags must match BlazeBeforeRunTask.
                    commandBuilder.addBlazeFlags(buildFlags);
                    // Run the test on the selected local device/emulator.
                    commandBuilder.addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED).addBlazeFlags(testDeviceSerialFlags(device.getSerialNumber())).addBlazeFlags(testFilter.getBlazeFlags());
                    if (debug) {
                        commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
                    }
                    BlazeCommand command = commandBuilder.build();
                    printer.stdout(String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
                    printer.stdout(command + "\n");
                    LineProcessingOutputStream.LineProcessor stdoutLineProcessor = line -> {
                        printer.stdout(line);
                        return true;
                    };
                    LineProcessingOutputStream.LineProcessor stderrLineProcessor = line -> {
                        printer.stderr(line);
                        return true;
                    };
                    SaveUtil.saveAllFiles();
                    int retVal = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command).context(context).stdout(LineProcessingOutputStream.of(stdoutLineProcessor)).stderr(LineProcessingOutputStream.of(stderrLineProcessor)).build().run();
                    FileCaches.refresh(project);
                    if (retVal != 0) {
                        context.setHasError();
                    }
                    return !context.hasErrors();
                }
            });
        }
    });
    blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
    // The debug case is set up in ConnectBlazeTestDebuggerTask
    if (!debug) {
        waitAndSetUpForKillingBlazeOnStop(processHandler, launchStatus);
    }
    return true;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Callable(java.util.concurrent.Callable) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)74 File (java.io.File)30 Test (org.junit.Test)29 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)21 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)17 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)17 ImmutableList (com.google.common.collect.ImmutableList)16 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)16 Project (com.intellij.openapi.project.Project)16 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)15 Nullable (javax.annotation.Nullable)15 List (java.util.List)14 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)12 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)11 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)11 Kind (com.google.idea.blaze.base.model.primitives.Kind)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 Set (java.util.Set)11 Lists (com.google.common.collect.Lists)10 Collectors (java.util.stream.Collectors)10