use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot 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.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeCidrLauncher method createDebugProcess.
@Override
public CidrDebugProcess createDebugProcess(CommandLineState state, XDebugSession session) throws ExecutionException {
TargetExpression target = configuration.getTarget();
if (target == null) {
throw new ExecutionException("Cannot parse run configuration target.");
}
if (runner.executableToDebug == null) {
throw new ExecutionException("No debug binary found.");
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
GeneralCommandLine commandLine = new GeneralCommandLine(runner.executableToDebug.getPath());
File workingDir = workspaceRoot.directory();
commandLine.setWorkDirectory(workingDir);
commandLine.addParameters(handlerState.getExeFlagsState().getExpandedFlags());
EnvironmentVariablesData envState = handlerState.getEnvVarsState().getData();
commandLine.withParentEnvironmentType(envState.isPassParentEnvs() ? ParentEnvironmentType.SYSTEM : ParentEnvironmentType.NONE);
commandLine.getEnvironment().putAll(envState.getEnvs());
if (Kind.CC_TEST.equals(configuration.getTargetKind())) {
convertBlazeTestFilterToExecutableFlag().ifPresent(commandLine::addParameters);
}
TrivialInstaller installer = new TrivialInstaller(commandLine);
ImmutableList<String> startupCommands = getGdbStartupCommands(workingDir);
CLionRunParameters parameters = new CLionRunParameters(new BlazeGDBDriverConfiguration(project, startupCommands, workspaceRoot), installer);
state.setConsoleBuilder(createConsoleBuilder(null));
state.addConsoleFilters(getConsoleFilters().toArray(new Filter[0]));
return new CidrLocalDebugProcess(parameters, session, state.getConsoleBuilder());
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class SourceDirectoryCalculator method calculateJavaSourceDirectories.
/**
* Adds the java source directories.
*/
private void calculateJavaSourceDirectories(BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, WorkspacePath directoryRoot, Collection<SourceArtifact> javaArtifacts, Collection<JavaPackageReader> javaPackageReaders, Collection<BlazeSourceDirectory> result) {
List<SourceRoot> sourceRootsPerFile = Lists.newArrayList();
// Get java sources
List<ListenableFuture<SourceRoot>> sourceRootFutures = Lists.newArrayList();
for (final SourceArtifact sourceArtifact : javaArtifacts) {
ListenableFuture<SourceRoot> future = executorService.submit(() -> sourceRootForJavaSource(context, artifactLocationDecoder, sourceArtifact, javaPackageReaders));
sourceRootFutures.add(future);
}
try {
for (SourceRoot sourceRoot : Futures.allAsList(sourceRootFutures).get()) {
if (sourceRoot != null) {
sourceRootsPerFile.add(sourceRoot);
}
}
} catch (ExecutionException | InterruptedException e) {
logger.error(e);
throw new IllegalStateException("Could not read sources");
}
// Sort source roots into their respective directories
Map<WorkspacePath, Multiset<SourceRoot>> sourceDirectoryToSourceRoots = new HashMap<>();
for (SourceRoot sourceRoot : sourceRootsPerFile) {
sourceDirectoryToSourceRoots.computeIfAbsent(sourceRoot.workspacePath, k -> HashMultiset.create()).add(sourceRoot);
}
// Create a mapping from directory to package prefix
Map<WorkspacePath, SourceRoot> workspacePathToSourceRoot = Maps.newHashMap();
for (WorkspacePath workspacePath : sourceDirectoryToSourceRoots.keySet()) {
Multiset<SourceRoot> sources = sourceDirectoryToSourceRoots.get(workspacePath);
Multiset<String> packages = HashMultiset.create();
for (Multiset.Entry<SourceRoot> entry : sources.entrySet()) {
packages.setCount(entry.getElement().packagePrefix, entry.getCount());
}
final String directoryPackagePrefix;
// Common case -- all source files agree on a single package
if (packages.elementSet().size() == 1) {
directoryPackagePrefix = packages.elementSet().iterator().next();
} else {
String preferredPackagePrefix = PackagePrefixCalculator.packagePrefixOf(workspacePath);
directoryPackagePrefix = pickMostFrequentlyOccurring(packages, preferredPackagePrefix);
}
SourceRoot candidateRoot = new SourceRoot(workspacePath, directoryPackagePrefix);
workspacePathToSourceRoot.put(workspacePath, candidateRoot);
}
// Add content entry base if it doesn't exist
if (!workspacePathToSourceRoot.containsKey(directoryRoot)) {
SourceRoot candidateRoot = new SourceRoot(directoryRoot, PackagePrefixCalculator.packagePrefixOf(directoryRoot));
workspacePathToSourceRoot.put(directoryRoot, candidateRoot);
}
// First, create a graph of the directory structure from root to each source file
Map<WorkspacePath, SourceRootDirectoryNode> sourceRootDirectoryNodeMap = Maps.newHashMap();
SourceRootDirectoryNode rootNode = new SourceRootDirectoryNode(directoryRoot, null);
sourceRootDirectoryNodeMap.put(directoryRoot, rootNode);
for (SourceRoot sourceRoot : workspacePathToSourceRoot.values()) {
final String sourcePathRelativeToDirectoryRoot = sourcePathRelativeToDirectoryRoot(directoryRoot, sourceRoot.workspacePath);
List<String> pathComponents = !Strings.isNullOrEmpty(sourcePathRelativeToDirectoryRoot) ? PATH_SPLITTER.splitToList(sourcePathRelativeToDirectoryRoot) : ImmutableList.of();
SourceRootDirectoryNode previousNode = rootNode;
for (int i = 0; i < pathComponents.size(); ++i) {
final WorkspacePath workspacePath = getWorkspacePathFromPathComponents(directoryRoot, pathComponents, i + 1);
SourceRootDirectoryNode node = sourceRootDirectoryNodeMap.get(workspacePath);
if (node == null) {
node = new SourceRootDirectoryNode(workspacePath, pathComponents.get(i));
sourceRootDirectoryNodeMap.put(workspacePath, node);
previousNode.children.add(node);
}
previousNode = node;
}
}
// Add package prefix votes at each directory node
for (SourceRoot sourceRoot : workspacePathToSourceRoot.values()) {
final String sourcePathRelativeToDirectoryRoot = sourcePathRelativeToDirectoryRoot(directoryRoot, sourceRoot.workspacePath);
List<String> packageComponents = PACKAGE_SPLITTER.splitToList(sourceRoot.packagePrefix);
List<String> pathComponents = !Strings.isNullOrEmpty(sourcePathRelativeToDirectoryRoot) ? PATH_SPLITTER.splitToList(sourcePathRelativeToDirectoryRoot) : ImmutableList.of();
int packageIndex = packageComponents.size();
int pathIndex = pathComponents.size();
while (pathIndex >= 0 && packageIndex >= 0) {
final WorkspacePath workspacePath = getWorkspacePathFromPathComponents(directoryRoot, pathComponents, pathIndex);
SourceRootDirectoryNode node = sourceRootDirectoryNodeMap.get(workspacePath);
String packagePrefix = PACKAGE_JOINER.join(packageComponents.subList(0, packageIndex));
// Otherwise just add a vote
if (sourceRoot.workspacePath.equals(workspacePath)) {
node.forcedPackagePrefix = packagePrefix;
} else {
node.packagePrefixVotes.add(packagePrefix);
}
String pathComponent = pathIndex > 0 ? pathComponents.get(pathIndex - 1) : "";
String packageComponent = packageIndex > 0 ? packageComponents.get(packageIndex - 1) : "";
if (!pathComponent.equals(packageComponent)) {
break;
}
--packageIndex;
--pathIndex;
}
}
Map<WorkspacePath, SourceRoot> sourceRoots = Maps.newHashMap();
SourceRootDirectoryNode root = sourceRootDirectoryNodeMap.get(directoryRoot);
visitDirectoryNode(sourceRoots, root, null);
for (SourceRoot sourceRoot : sourceRoots.values()) {
result.add(BlazeSourceDirectory.builder(workspaceRoot.fileForPath(sourceRoot.workspacePath)).setPackagePrefix(sourceRoot.packagePrefix).setGenerated(false).build());
}
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeApkBuildStepMobileInstall method build.
@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
DeviceFutures deviceFutures = deviceSession.deviceFutures;
assert deviceFutures != null;
IDevice device = resolveDevice(context, deviceFutures);
if (device == null) {
return null;
}
BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
// Redundant, but we need this to get around bug in bazel.
// https://github.com/bazelbuild/bazel/issues/4922
command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
if (USE_SDK_ADB.getValue()) {
File adb = AndroidSdkUtils.getAdb(project);
if (adb != null) {
command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
}
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
FileCaches.refresh(project);
if (retVal != 0) {
context.setHasError();
return null;
}
deployInfo = deployInfoHelper.readDeployInfo(context);
if (deployInfo == null) {
IssueOutput.error("Could not read apk deploy info from build").submit(context);
}
return null;
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
try {
Futures.get(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
return context.shouldContinue();
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class PrefetchServiceImpl method prefetchProjectFiles.
@Override
public ListenableFuture<?> prefetchProjectFiles(Project project, ProjectViewSet projectViewSet, @Nullable BlazeProjectData blazeProjectData) {
BlazeImportSettings importSettings = BlazeImportSettingsManager.getInstance(project).getImportSettings();
if (importSettings == null) {
return Futures.immediateFuture(null);
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
// quick sanity check before trying to prefetch each individual file
return Futures.immediateFuture(null);
}
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, importSettings.getBuildSystem()).add(projectViewSet).build();
Set<File> sourceDirectories = new HashSet<>();
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
sourceDirectories.add(workspaceRoot.fileForPath(workspacePath));
}
Set<File> excludeDirectories = new HashSet<>();
for (WorkspacePath workspacePath : importRoots.excludeDirectories()) {
excludeDirectories.add(workspaceRoot.fileForPath(workspacePath));
}
ListenableFuture<?> sourceFilesFuture = prefetchFiles(project, excludeDirectories, sourceDirectories, /* refetchCachedFiles */
false, /* fetchFileTypes */
true);
Set<File> externalFiles = new HashSet<>();
if (blazeProjectData != null) {
for (PrefetchFileSource fileSource : PrefetchFileSource.EP_NAME.getExtensions()) {
fileSource.addFilesToPrefetch(project, projectViewSet, importRoots, blazeProjectData, externalFiles);
}
}
ListenableFuture<?> externalFilesFuture = prefetchFiles(project, externalFiles, false, false);
return Futures.allAsList(sourceFilesFuture, externalFilesFuture);
}
Aggregations