use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class FilteredTargetMap method targetsForSourceFileImpl.
private Collection<TargetIdeInfo> targetsForSourceFileImpl(ImmutableMultimap<TargetKey, TargetKey> rdepsMap, File sourceFile) {
List<TargetIdeInfo> result = Lists.newArrayList();
Collection<TargetKey> roots = rootsMap.get(sourceFile);
Queue<TargetKey> todo = Queues.newArrayDeque();
todo.addAll(roots);
Set<TargetKey> seen = Sets.newHashSet();
while (!todo.isEmpty()) {
TargetKey targetKey = todo.remove();
if (!seen.add(targetKey)) {
continue;
}
TargetIdeInfo target = targetMap.get(targetKey);
if (filter.test(target)) {
result.add(target);
}
todo.addAll(rdepsMap.get(targetKey));
}
return result;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeConfigurationResolver method collectExecutionRootPaths.
private static Set<ExecutionRootPath> collectExecutionRootPaths(TargetMap targetMap, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap) {
Set<ExecutionRootPath> paths = Sets.newHashSet();
for (TargetIdeInfo target : targetMap.targets()) {
if (target.cIdeInfo != null) {
paths.addAll(target.cIdeInfo.localIncludeDirectories);
paths.addAll(target.cIdeInfo.transitiveSystemIncludeDirectories);
paths.addAll(target.cIdeInfo.transitiveIncludeDirectories);
paths.addAll(target.cIdeInfo.transitiveQuoteIncludeDirectories);
}
}
Set<CToolchainIdeInfo> toolchains = new LinkedHashSet<>(toolchainLookupMap.values());
for (CToolchainIdeInfo toolchain : toolchains) {
paths.addAll(toolchain.builtInIncludeDirectories);
paths.addAll(toolchain.unfilteredToolchainSystemIncludes);
}
return paths;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeConfigurationToolchainResolver method buildToolchainLookupMap.
/**
* Returns the toolchain used by each target
*/
static ImmutableMap<TargetKey, CToolchainIdeInfo> buildToolchainLookupMap(BlazeContext context, TargetMap targetMap) {
return Scope.push(context, childContext -> {
childContext.push(new TimingScope("Build toolchain lookup map", EventType.Other));
Map<TargetKey, CToolchainIdeInfo> toolchains = Maps.newLinkedHashMap();
for (TargetIdeInfo target : targetMap.targets()) {
CToolchainIdeInfo cToolchainIdeInfo = target.cToolchainIdeInfo;
if (cToolchainIdeInfo != null) {
toolchains.put(target.key, cToolchainIdeInfo);
}
}
ImmutableMap.Builder<TargetKey, CToolchainIdeInfo> lookupTable = ImmutableMap.builder();
for (TargetIdeInfo target : targetMap.targets()) {
if (target.kind.languageClass != LanguageClass.C || target.kind == Kind.CC_TOOLCHAIN) {
continue;
}
List<TargetKey> toolchainDeps = target.dependencies.stream().map(dep -> dep.targetKey).filter(toolchains::containsKey).collect(Collectors.toList());
if (toolchainDeps.size() != 1) {
issueToolchainWarning(context, target, toolchainDeps);
}
if (!toolchainDeps.isEmpty()) {
TargetKey toolchainKey = toolchainDeps.get(0);
CToolchainIdeInfo toolchainInfo = toolchains.get(toolchainKey);
lookupTable.put(target.key, toolchainInfo);
} else {
CToolchainIdeInfo arbitraryToolchain = Iterables.getFirst(toolchains.values(), null);
if (arbitraryToolchain != null) {
lookupTable.put(target.key, arbitraryToolchain);
}
}
}
return lookupTable.build();
});
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method buildLibraries.
private ImmutableMap<LibraryKey, BlazeJarLibrary> buildLibraries(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, List<TargetIdeInfo> libraryTargets, List<TargetIdeInfo> protoLibraries) {
// Build library maps
Multimap<TargetKey, BlazeJarLibrary> targetKeyToLibrary = ArrayListMultimap.create();
Map<String, BlazeJarLibrary> jdepsPathToLibrary = Maps.newHashMap();
// Add any output jars from source rules
for (TargetKey key : workspaceBuilder.outputJarsFromSourceTargets.keySet()) {
Collection<BlazeJarLibrary> jars = workspaceBuilder.outputJarsFromSourceTargets.get(key);
targetKeyToLibrary.putAll(key, jars);
for (BlazeJarLibrary library : jars) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
for (TargetIdeInfo target : libraryTargets) {
JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
if (javaIdeInfo == null) {
continue;
}
List<LibraryArtifact> allJars = Lists.newArrayList();
allJars.addAll(javaIdeInfo.jars);
Collection<BlazeJarLibrary> libraries = allJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList());
targetKeyToLibrary.putAll(target.key, libraries);
for (BlazeJarLibrary library : libraries) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
// proto legacy jdeps support
for (TargetIdeInfo target : protoLibraries) {
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
for (LibraryArtifact libraryArtifact : Iterables.concat(protoLibraryLegacyInfo.jarsV1, protoLibraryLegacyInfo.jarsMutable, protoLibraryLegacyInfo.jarsImmutable)) {
addLibraryToJdeps(jdepsPathToLibrary, new BlazeJarLibrary(libraryArtifact));
}
}
Map<LibraryKey, BlazeJarLibrary> result = Maps.newHashMap();
// Collect jars from jdep references
for (String jdepsPath : workspaceBuilder.jdeps) {
if (sourceFilter.jdepsPathsForExcludedJars.contains(jdepsPath)) {
continue;
}
BlazeJarLibrary library = jdepsPathToLibrary.get(jdepsPath);
if (library == null) {
// It's in the target's jdeps, but our aspect never attached to the target building it
// Perhaps it's an implicit dependency, or not referenced in an attribute we propagate along
// Or it could be that this is a multi-configuration project, and jdeps refers to a
// configuration different from the one we picked for the TargetMap.
// Make a best-effort attempt to add it to the project anyway.
ExecutionPathFragmentAndRelativePath split = ExecutionPathFragmentAndRelativePath.split(jdepsPath);
ArtifactLocation location = ArtifactLocation.builder().setIsSource(false).setRootExecutionPathFragment(split.rootExecutionPathFragment).setRelativePath(split.relativePath).build();
library = new BlazeJarLibrary(new LibraryArtifact(location, null, ImmutableList.of()));
}
result.put(library.key, library);
}
// Collect jars referenced by direct deps from your working set
for (TargetKey deps : workspaceBuilder.directDeps) {
for (BlazeJarLibrary library : targetKeyToLibrary.get(deps)) {
result.put(library.key, library);
}
}
// Collect legacy proto libraries from direct deps
addProtoLegacyLibrariesFromDirectDeps(workspaceBuilder, targetMap, result);
// Collect generated jars from source rules
for (BlazeJarLibrary library : workspaceBuilder.generatedJarsFromSourceTargets) {
result.put(library.key, library);
}
return ImmutableMap.copyOf(result);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method importWorkspace.
public BlazeJavaImportResult importWorkspace(BlazeContext context) {
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceFilter.sourceTargets) {
addTargetAsSource(workspaceBuilder, target, sourceFilter.targetToJavaSources.get(target.key));
}
SourceDirectoryCalculator sourceDirectoryCalculator = new SourceDirectoryCalculator();
ImmutableList<BlazeContentEntry> contentEntries = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, artifactLocationDecoder, importRoots, workspaceBuilder.sourceArtifacts, workspaceBuilder.javaPackageManifests);
int totalContentEntryCount = 0;
for (BlazeContentEntry contentEntry : contentEntries) {
totalContentEntryCount += contentEntry.sources.size();
}
context.output(PrintOutput.log("Java content entry count: " + totalContentEntryCount));
ImmutableMap<LibraryKey, BlazeJarLibrary> libraries = buildLibraries(workspaceBuilder, targetMap, sourceFilter.libraryTargets, sourceFilter.protoLibraries);
duplicateSourceDetector.reportDuplicates(context);
String sourceVersion = findSourceVersion(targetMap);
return new BlazeJavaImportResult(contentEntries, libraries, ImmutableList.copyOf(workspaceBuilder.buildOutputJars.stream().sorted().collect(Collectors.toList())), ImmutableSet.copyOf(workspaceBuilder.addedSourceFiles), sourceVersion);
}
Aggregations