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());
}
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();
}
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);
}
});
}
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);
});
}
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;
}
Aggregations