Search in sources :

Example 1 with CToolchainIdeInfo

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

the class IdeInfoFromProtobuf method makeCToolchainIdeInfo.

private static CToolchainIdeInfo makeCToolchainIdeInfo(IntellijIdeInfo.CToolchainIdeInfo cToolchainIdeInfo) {
    Collection<ExecutionRootPath> builtInIncludeDirectories = makeExecutionRootPathList(cToolchainIdeInfo.getBuiltInIncludeDirectoryList());
    ExecutionRootPath cppExecutable = new ExecutionRootPath(cToolchainIdeInfo.getCppExecutable());
    UnfilteredCompilerOptions compilerOptions = UnfilteredCompilerOptions.builder().registerSingleOrSplitOption("-isystem").build(cToolchainIdeInfo.getUnfilteredCompilerOptionList());
    CToolchainIdeInfo.Builder builder = CToolchainIdeInfo.builder().addBaseCompilerOptions(cToolchainIdeInfo.getBaseCompilerOptionList()).addCCompilerOptions(cToolchainIdeInfo.getCOptionList()).addCppCompilerOptions(cToolchainIdeInfo.getCppOptionList()).addBuiltInIncludeDirectories(builtInIncludeDirectories).setCppExecutable(cppExecutable).setTargetName(cToolchainIdeInfo.getTargetName()).addUnfilteredCompilerOptions(compilerOptions.getUninterpretedOptions()).addUnfilteredToolchainSystemIncludes(makeExecutionRootPathList(compilerOptions.getExtractedOptionValues("-isystem")));
    return builder.build();
}
Also used : CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath)

Example 2 with CToolchainIdeInfo

use of com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo 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 3 with CToolchainIdeInfo

use of com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo 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 4 with CToolchainIdeInfo

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

the class BlazeConfigurationToolchainResolver method doBuildCompilerSettingsMap.

private static ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> doBuildCompilerSettingsMap(BlazeContext context, Project project, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap, ExecutionRootPathResolver executionRootPathResolver, CompilerInfoCache compilerInfoCache, ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> oldCompilerSettings) {
    Set<CToolchainIdeInfo> toolchains = toolchainLookupMap.values().stream().distinct().collect(Collectors.toSet());
    List<ListenableFuture<Map.Entry<CToolchainIdeInfo, BlazeCompilerSettings>>> compilerSettingsFutures = new ArrayList<>();
    for (CToolchainIdeInfo toolchain : toolchains) {
        compilerSettingsFutures.add(submit(() -> {
            File cppExecutable = executionRootPathResolver.resolveExecutionRootPath(toolchain.cppExecutable);
            if (cppExecutable == null) {
                IssueOutput.error("Unable to find compiler executable: " + toolchain.cppExecutable).submit(context);
                return null;
            }
            String compilerVersion = CompilerVersionChecker.getInstance().checkCompilerVersion(executionRootPathResolver.getExecutionRoot(), cppExecutable);
            if (compilerVersion == null) {
                IssueOutput.error("Unable to determine version of compiler " + cppExecutable).submit(context);
                return null;
            }
            BlazeCompilerSettings oldSettings = oldCompilerSettings.get(toolchain);
            if (oldSettings != null && oldSettings.getCompilerVersion().equals(compilerVersion)) {
                return new SimpleImmutableEntry<>(toolchain, oldSettings);
            }
            BlazeCompilerSettings settings = createBlazeCompilerSettings(project, toolchain, executionRootPathResolver.getExecutionRoot(), cppExecutable, compilerVersion, compilerInfoCache);
            if (settings == null) {
                IssueOutput.error("Unable to create compiler wrapper for: " + cppExecutable).submit(context);
                return null;
            }
            return new SimpleImmutableEntry<>(toolchain, settings);
        }));
    }
    ImmutableMap.Builder<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettingsMap = ImmutableMap.builder();
    try {
        List<Map.Entry<CToolchainIdeInfo, BlazeCompilerSettings>> createdSettings = Futures.allAsList(compilerSettingsFutures).get();
        for (Map.Entry<CToolchainIdeInfo, BlazeCompilerSettings> createdSetting : createdSettings) {
            if (createdSetting != null) {
                compilerSettingsMap.put(createdSetting);
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        context.setCancelled();
    } catch (ExecutionException e) {
        IssueOutput.error("Could not build C compiler settings map: " + e).submit(context);
    }
    return compilerSettingsMap.build();
}
Also used : ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) File(java.io.File)

Example 5 with CToolchainIdeInfo

use of com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo 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)

Aggregations

CToolchainIdeInfo (com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo)8 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)5 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 CIdeInfo (com.google.idea.blaze.base.ideinfo.CIdeInfo)3 ExecutionRootPath (com.google.idea.blaze.base.model.primitives.ExecutionRootPath)3 File (java.io.File)3 Nullable (javax.annotation.Nullable)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2 ExecutionRootPathResolver (com.google.idea.blaze.base.sync.workspace.ExecutionRootPathResolver)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CompilerInfoCache (com.jetbrains.cidr.toolchains.CompilerInfoCache)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1