use of com.google.idea.blaze.base.ideinfo.TargetKey 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.TargetKey in project intellij by bazelbuild.
the class BlazeConfigurationResolver method findEquivalenceClasses.
private static void findEquivalenceClasses(BlazeContext context, Project project, WorkspacePathResolver workspacePathResolver, Map<TargetKey, BlazeResolveConfigurationData> targetToData, BlazeConfigurationResolverResult oldConfigurationData, BlazeConfigurationResolverResult.Builder builder) {
Map<BlazeResolveConfigurationData, BlazeResolveConfiguration> dataToConfiguration = new HashMap<>();
Multimap<BlazeResolveConfigurationData, TargetKey> dataEquivalenceClasses = ArrayListMultimap.create();
int reused = 0;
for (Map.Entry<TargetKey, BlazeResolveConfigurationData> entry : targetToData.entrySet()) {
TargetKey target = entry.getKey();
BlazeResolveConfigurationData data = entry.getValue();
if (!dataToConfiguration.containsKey(data)) {
BlazeResolveConfiguration configuration;
if (oldConfigurationData.uniqueResolveConfigurations.containsKey(data)) {
configuration = oldConfigurationData.uniqueResolveConfigurations.get(data);
reused++;
} else {
configuration = BlazeResolveConfiguration.createForTargets(project, workspacePathResolver, data, ImmutableList.of(target));
}
dataToConfiguration.put(data, configuration);
}
dataEquivalenceClasses.put(data, target);
}
ImmutableMap.Builder<TargetKey, BlazeResolveConfiguration> targetToConfiguration = ImmutableMap.builder();
for (Map.Entry<BlazeResolveConfigurationData, Collection<TargetKey>> entry : dataEquivalenceClasses.asMap().entrySet()) {
BlazeResolveConfigurationData data = entry.getKey();
Collection<TargetKey> targets = entry.getValue();
BlazeResolveConfiguration configuration = dataToConfiguration.get(data);
configuration.representMultipleTargets(targets);
for (TargetKey targetKey : targets) {
targetToConfiguration.put(targetKey, configuration);
}
}
context.output(PrintOutput.log(String.format("%s unique C configurations (%s reused), %s C targets", dataEquivalenceClasses.keySet().size(), reused, dataEquivalenceClasses.size())));
builder.setConfigurationMap(targetToConfiguration.build());
builder.setUniqueConfigurations(ImmutableMap.copyOf(dataToConfiguration));
}
use of com.google.idea.blaze.base.ideinfo.TargetKey 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.TargetKey in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testSingleDep.
@Test
public void testSingleDep() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l2")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l2")), TargetKey.forPlainTarget(Label.create("//l:l1")));
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testTwoLabelsDepOnSameLabel.
@Test
public void testTwoLabelsDepOnSameLabel() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l3")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").addDependency("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l3").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l1")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l2")));
}
Aggregations