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();
}
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;
}
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();
});
}
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();
}
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);
}
Aggregations