Search in sources :

Example 6 with CToolchainIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method makeCToolchainIdeInfo.

private static CToolchainIdeInfo makeCToolchainIdeInfo(RuleContext ruleContext, CppConfiguration cppConfiguration) {
    CToolchainIdeInfo.Builder builder = CToolchainIdeInfo.newBuilder();
    ImmutableSet<String> features = ruleContext.getFeatures();
    builder.setTargetName(cppConfiguration.getTargetGnuSystemName());
    builder.addAllBaseCompilerOption(cppConfiguration.getCompilerOptions(features));
    builder.addAllCOption(cppConfiguration.getCOptions());
    builder.addAllCppOption(cppConfiguration.getCxxOptions(features));
    builder.addAllLinkOption(cppConfiguration.getLinkOptions());
    // This includes options such as system includes from toolchains.
    builder.addAllUnfilteredCompilerOption(cppConfiguration.getUnfilteredCompilerOptions(features));
    builder.setPreprocessorExecutable(cppConfiguration.getCpreprocessorExecutable().getSafePathString());
    builder.setCppExecutable(cppConfiguration.getCppExecutable().getSafePathString());
    List<PathFragment> builtInIncludeDirectories = cppConfiguration.getBuiltInIncludeDirectories();
    for (PathFragment builtInIncludeDirectory : builtInIncludeDirectories) {
        builder.addBuiltInIncludeDirectory(builtInIncludeDirectory.getSafePathString());
    }
    return builder.build();
}
Also used : CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 7 with CToolchainIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo in project intellij by bazelbuild.

the class CcLibraryTest method testCcLibraryHasToolchain.

@Test
public void testCcLibraryHasToolchain() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
    List<TargetIdeInfo> toolchains = testFixture.getTargetsList().stream().filter(target -> target.getKindString().equals("cc_toolchain")).collect(Collectors.toList());
    TargetIdeInfo toolchainTarget = Iterables.getOnlyElement(toolchains);
    assertThat(toolchainTarget.hasCToolchainIdeInfo()).isTrue();
    // Only cc_toolchain has toolchains
    TargetIdeInfo target = findTarget(testFixture, ":simple");
    assertThat(target.hasCToolchainIdeInfo()).isFalse();
    // Check that the library target deps on the toolchain.
    List<TargetIdeInfo> nativeToolchainDeps = dependenciesForTarget(target).stream().map(Dependency::getTarget).map(targetKey -> findTarget(testFixture, targetKey.getLabel())).filter(Objects::nonNull).filter(TargetIdeInfo::hasCToolchainIdeInfo).collect(toList());
    assertThat(toolchains).containsExactlyElementsIn(nativeToolchainDeps);
    CToolchainIdeInfo toolchainIdeInfo = toolchainTarget.getCToolchainIdeInfo();
    assertThat(toolchainIdeInfo.getCppExecutable()).isNotEmpty();
    // Should at least know the -std level (from some list of flags) to avoid b/70223102, unless the
    // default is sufficient.
    assertThat(toolchainIdeInfo.getCppOptionList().stream().anyMatch(option -> option.startsWith("-std="))).isTrue();
    // There should be several include directories, including:
    // - from compiler (for xmmintrin.h, etc.) (gcc/.../include, or clang/.../include)
    // - libc (currently something without gcc or clang and ends with "include",
    // which is a bit of a weak check)
    // - c++ library (usual several directories)
    // - if libstdc++, something like .../x86_64-vendor-linux-gnu/include/c++/<version>
    // - if libcxx, something like .../include/c++/<version>
    // This is assuming gcc or clang.
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList()).isNotEmpty();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> (dir.contains("gcc/") || dir.contains("clang/")) && dir.endsWith("include"))).isTrue();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> !dir.contains("gcc/") && !dir.contains("clang/") && dir.endsWith("include"))).isTrue();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> dir.contains("c++"))).isTrue();
    // Check that we have *some* options. Not everything is portable, so it's hard to be strict.
    assertThat(toolchainIdeInfo.getBaseCompilerOptionList()).isNotEmpty();
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) Iterables(com.google.common.collect.Iterables) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest) Collectors(java.util.stream.Collectors) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) Dependency(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) Objects(java.util.Objects) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) Dependency(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Aggregations

CToolchainIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo)7 CIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo)6 TargetIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo)6 Test (org.junit.Test)5 ByteString (com.google.protobuf.ByteString)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 Iterables (com.google.common.collect.Iterables)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 AndroidIdeInfoProvider (com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider)1 CcToolchainProvider (com.google.devtools.build.lib.rules.cpp.CcToolchainProvider)1 CppCompilationContext (com.google.devtools.build.lib.rules.cpp.CppCompilationContext)1 CppConfiguration (com.google.devtools.build.lib.rules.cpp.CppConfiguration)1 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)1 JavaToolchainProvider (com.google.devtools.build.lib.rules.java.JavaToolchainProvider)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 IntellijAspectTestFixture (com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture)1 Dependency (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency)1 JavaIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)1 LibraryArtifact (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)1