use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testLabelDepsOnTwoLabels.
@Test
public void testLabelDepsOnTwoLabels() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l2").addDependency("//l:l3")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").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:l2")), TargetKey.forPlainTarget(Label.create("//l:l1")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l1")));
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class TransitiveDependencyMapTest method testGetChainDependencies.
@Test
public void testGetChainDependencies() {
TargetKey chainA = TargetKey.forPlainTarget(Label.create("//com/google/example/chain:a"));
TargetKey chainB = TargetKey.forPlainTarget(Label.create("//com/google/example/chain:b"));
TargetKey chainC = TargetKey.forPlainTarget(Label.create("//com/google/example/chain:c"));
TargetKey chainD = TargetKey.forPlainTarget(Label.create("//com/google/example/chain:d"));
assertThat(transitiveDependencyMap.getTransitiveDependencies(chainA)).containsExactly(chainB, chainC, chainD);
assertThat(transitiveDependencyMap.getTransitiveDependencies(chainB)).containsExactly(chainC, chainD);
assertThat(transitiveDependencyMap.getTransitiveDependencies(chainC)).containsExactly(chainD);
assertThat(transitiveDependencyMap.getTransitiveDependencies(chainD)).isEmpty();
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class DuplicateSourceDetector method reportDuplicates.
public void reportDuplicates(BlazeContext context) {
List<Duplicate> duplicates = Lists.newArrayList();
for (ArtifactLocation key : artifacts.keySet()) {
Collection<TargetKey> labels = artifacts.get(key);
if (labels.size() > 1) {
// Workaround for aspect bug. Can be removed after the next blaze release, as of May 27 2016
Set<TargetKey> labelSet = Sets.newHashSet(labels);
if (labelSet.size() > 1) {
duplicates.add(new Duplicate(key, labelSet));
}
}
}
if (duplicates.isEmpty()) {
return;
}
duplicates.sort(Comparator.comparing(lhs -> lhs.artifactLocation.getRelativePath()));
context.output(new PerformanceWarning("Duplicate sources detected:"));
for (Duplicate duplicate : duplicates) {
ArtifactLocation artifactLocation = duplicate.artifactLocation;
context.output(new PerformanceWarning(" Source: " + artifactLocation.getRelativePath()));
context.output(new PerformanceWarning(" Consumed by rules:"));
for (TargetKey targetKey : duplicate.targets) {
context.output(new PerformanceWarning(" " + targetKey.label));
}
// Newline
context.output(new PerformanceWarning(""));
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey 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.TargetKey in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDeps.
private void addProtoLegacyLibrariesFromDirectDeps(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, Map<LibraryKey, BlazeJarLibrary> result) {
List<TargetKey> version1Targets = Lists.newArrayList();
List<TargetKey> immutableTargets = Lists.newArrayList();
List<TargetKey> mutableTargets = Lists.newArrayList();
for (TargetKey targetKey : workspaceBuilder.directDeps) {
TargetIdeInfo target = targetMap.get(targetKey);
if (target == null) {
continue;
}
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
switch(protoLibraryLegacyInfo.apiFlavor) {
case VERSION_1:
version1Targets.add(targetKey);
break;
case IMMUTABLE:
immutableTargets.add(targetKey);
break;
case MUTABLE:
mutableTargets.add(targetKey);
break;
case BOTH:
mutableTargets.add(targetKey);
immutableTargets.add(targetKey);
break;
default:
// Can't happen
break;
}
}
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1, version1Targets, result);
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE, immutableTargets, result);
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.MUTABLE, mutableTargets, result);
}
Aggregations