Search in sources :

Example 21 with TargetIdeInfo

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

Example 22 with TargetIdeInfo

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) LinkedHashSet(java.util.LinkedHashSet) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath)

Example 23 with TargetIdeInfo

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();
    });
}
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 24 with TargetIdeInfo

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);
}
Also used : ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 25 with TargetIdeInfo

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);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) SourceDirectoryCalculator(com.google.idea.blaze.java.sync.source.SourceDirectoryCalculator)

Aggregations

TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)57 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)28 File (java.io.File)20 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)19 Nullable (javax.annotation.Nullable)16 Kind (com.google.idea.blaze.base.model.primitives.Kind)15 ImmutableList (com.google.common.collect.ImmutableList)14 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)14 Project (com.intellij.openapi.project.Project)14 List (java.util.List)12 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)11 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)10 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)10 Collection (java.util.Collection)10 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)9 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 Set (java.util.Set)9