Search in sources :

Example 31 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporter method importWorkspace.

public BlazeScalaImportResult importWorkspace() {
    ProjectViewTargetImportFilter importFilter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
    Collection<Kind> scalaKinds = Kind.allKindsForLanguage(LanguageClass.SCALA);
    List<TargetKey> scalaSourceTargets = targetMap.targets().stream().filter(target -> target.javaIdeInfo != null).filter(target -> target.kindIsOneOf(scalaKinds)).filter(importFilter::isSourceTarget).map(target -> target.key).collect(Collectors.toList());
    Map<LibraryKey, BlazeJarLibrary> libraries = Maps.newHashMap();
    // but since they'll all merged into one set, we will end up with exactly one of each.
    for (TargetKey dependency : TransitiveDependencyMap.getTransitiveDependencies(scalaSourceTargets, targetMap)) {
        TargetIdeInfo target = targetMap.get(dependency);
        if (target == null) {
            continue;
        }
        // Except source targets.
        if (JavaSourceFilter.importAsSource(importFilter, target)) {
            continue;
        }
        if (target.javaIdeInfo != null) {
            target.javaIdeInfo.jars.stream().map(BlazeJarLibrary::new).forEach(library -> libraries.putIfAbsent(library.key, library));
        }
    }
    return new BlazeScalaImportResult(ImmutableMap.copyOf(libraries));
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) List(java.util.List) Map(java.util.Map) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)

Example 32 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeConfigurationResolver method createResolveConfiguration.

@Nullable
private BlazeResolveConfigurationData createResolveConfiguration(TargetIdeInfo target, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap, ImmutableMap<File, VirtualFile> headerRoots, ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettingsMap, CompilerInfoCache compilerInfoCache, ExecutionRootPathResolver executionRootPathResolver) {
    TargetKey targetKey = target.key;
    CIdeInfo cIdeInfo = target.cIdeInfo;
    if (cIdeInfo == null) {
        return null;
    }
    CToolchainIdeInfo toolchainIdeInfo = toolchainLookupMap.get(targetKey);
    if (toolchainIdeInfo == null) {
        return null;
    }
    BlazeCompilerSettings compilerSettings = compilerSettingsMap.get(toolchainIdeInfo);
    if (compilerSettings == null) {
        return null;
    }
    return BlazeResolveConfigurationData.create(project, executionRootPathResolver, headerRoots, cIdeInfo, toolchainIdeInfo, compilerSettings, compilerInfoCache);
}
Also used : CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Nullable(javax.annotation.Nullable)

Example 33 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeConfigurationResolver method update.

public BlazeConfigurationResolverResult update(BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, BlazeConfigurationResolverResult oldResult) {
    ExecutionRootPathResolver executionRootPathResolver = new ExecutionRootPathResolver(Blaze.getBuildSystem(project), WorkspaceRoot.fromProject(project), blazeProjectData.blazeInfo.getExecutionRoot(), blazeProjectData.workspacePathResolver);
    ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap = BlazeConfigurationToolchainResolver.buildToolchainLookupMap(context, blazeProjectData.targetMap);
    ImmutableMap<File, VirtualFile> headerRoots = collectHeaderRoots(context, blazeProjectData, toolchainLookupMap, executionRootPathResolver);
    CompilerInfoCache compilerInfoCache = new CompilerInfoCache();
    ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettings = BlazeConfigurationToolchainResolver.buildCompilerSettingsMap(context, project, toolchainLookupMap, executionRootPathResolver, compilerInfoCache, oldResult.compilerSettings);
    BlazeConfigurationResolverResult.Builder builder = BlazeConfigurationResolverResult.builder(project);
    buildBlazeConfigurationData(context, workspaceRoot, projectViewSet, blazeProjectData, toolchainLookupMap, headerRoots, compilerSettings, compilerInfoCache, executionRootPathResolver, oldResult, builder);
    builder.setCompilerSettings(compilerSettings);
    return builder.build();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionRootPathResolver(com.google.idea.blaze.base.sync.workspace.ExecutionRootPathResolver) CompilerInfoCache(com.jetbrains.cidr.toolchains.CompilerInfoCache) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 34 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeConfigurationResolver method buildBlazeConfigurationData.

private void buildBlazeConfigurationData(BlazeContext parentContext, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap, ImmutableMap<File, VirtualFile> headerRoots, ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettings, CompilerInfoCache compilerInfoCache, ExecutionRootPathResolver executionRootPathResolver, BlazeConfigurationResolverResult oldConfigurationData, BlazeConfigurationResolverResult.Builder builder) {
    // Type specification needed to avoid incorrect type inference during command line build.
    Scope.push(parentContext, (ScopedOperation) context -> {
        context.push(new TimingScope("Build C configuration map", EventType.Other));
        ProjectViewTargetImportFilter filter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
        ConcurrentMap<TargetKey, BlazeResolveConfigurationData> targetToData = Maps.newConcurrentMap();
        List<ListenableFuture<?>> targetToDataFutures = blazeProjectData.targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.C).filter(target -> target.kind != Kind.CC_TOOLCHAIN).filter(filter::isSourceTarget).filter(BlazeConfigurationResolver::containsCompiledSources).map(target -> submit(() -> {
            BlazeResolveConfigurationData data = createResolveConfiguration(target, toolchainLookupMap, headerRoots, compilerSettings, compilerInfoCache, executionRootPathResolver);
            if (data != null) {
                targetToData.put(target.key, data);
            }
            return null;
        })).collect(Collectors.toList());
        try {
            Futures.allAsList(targetToDataFutures).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            context.setCancelled();
            return;
        } catch (ExecutionException e) {
            IssueOutput.error("Could not build C resolve configurations: " + e).submit(context);
            logger.error("Could not build C resolve configurations", e);
            return;
        }
        findEquivalenceClasses(context, project, blazeProjectData.workspacePathResolver, targetToData, oldConfigurationData, builder);
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) ExecutionRootPathResolver(com.google.idea.blaze.base.sync.workspace.ExecutionRootPathResolver) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Logger(com.intellij.openapi.diagnostic.Logger) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableMap(com.google.common.collect.ImmutableMap) CompilerInfoCache(com.jetbrains.cidr.toolchains.CompilerInfoCache) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) List(java.util.List) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Queue(java.util.Queue) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Multimap(com.google.common.collect.Multimap) VfsUtils(com.google.idea.blaze.base.io.VfsUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Maps(com.google.common.collect.Maps) File(java.io.File) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) Futures(com.google.common.util.concurrent.Futures) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ArrayDeque(java.util.ArrayDeque) ScopedOperation(com.google.idea.blaze.base.scope.ScopedOperation) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeConfigurationResolverResult method getConfigurationForFile.

@Nullable
OCResolveConfiguration getConfigurationForFile(VirtualFile sourceFile) {
    SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
    ImmutableCollection<TargetKey> targetsForSourceFile = sourceToTargetMap.getRulesForSourceFile(VfsUtilCore.virtualToIoFile(sourceFile));
    if (targetsForSourceFile.isEmpty()) {
        return null;
    }
    // If a source file is in two different targets, we can't possibly show how it will be
    // interpreted in both contexts at the same time in the IDE, so just pick the "first" target.
    TargetKey targetKey = targetsForSourceFile.stream().min(TargetKey::compareTo).orElse(null);
    Preconditions.checkNotNull(targetKey);
    return configurationMap.get(targetKey);
}
Also used : SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Nullable(javax.annotation.Nullable)

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