use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency 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();
}
Aggregations