Search in sources :

Example 11 with TargetKey

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 12 with TargetKey

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));
}
Also used : HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 13 with TargetKey

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();
    });
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with TargetKey

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")));
}
Also used : TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 15 with TargetKey

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")));
}
Also used : TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Aggregations

TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)52 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)25 File (java.io.File)19 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 Nullable (javax.annotation.Nullable)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)11 List (java.util.List)11 Test (org.junit.Test)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)9 Project (com.intellij.openapi.project.Project)9 Map (java.util.Map)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Collection (java.util.Collection)8 Set (java.util.Set)8 Sets (com.google.common.collect.Sets)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)7 ExecutionException (java.util.concurrent.ExecutionException)7