use of com.google.idea.blaze.base.model.primitives.ExecutionRootPath in project intellij by bazelbuild.
the class AndroidSyncTest method testMultipleToolchainsNoIssue.
@Test
public void testMultipleToolchainsNoIssue() {
// Test what happens if there are multiple toolchains in the target map
// (e.g., from --fat_apk_cpu)
setProjectView("directories:", " java/com/google", "targets:", " //java/com/google:app", "additional_languages:", " c", "android_sdk_platform: android-25");
workspace.createDirectory(new WorkspacePath("java/com/google"));
workspace.createFile(new WorkspacePath("java/com/google/Source.java"), "package com.google;", "public class Source {}");
workspace.createFile(new WorkspacePath("java/com/google/Other.java"), "package com.google;", "public class Other {}");
workspace.createFile(new WorkspacePath("java/com/google/jni/native.cc"), "void foo() {}");
workspace.createFile(new WorkspacePath("java/com/google/jni/native2.cc"), "void bar() {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("android_ndk_linux/toolchains/BUILD")).setLabel("//android_ndk_linux/toolchains:armv7a").setKind(Kind.CC_TOOLCHAIN).setCToolchainInfo(CToolchainIdeInfo.builder().setTargetName("arm-linux-androideabi").setCppExecutable(new ExecutionRootPath("bin/arm-linux-androideabi-gcc")).addBaseCompilerOptions(ImmutableList.of("-DOS_ANDROID", "-mbionic", "-ffunction-sections", "-march=armv7-a", "-mfpu=vfpv3-d16")).addCppCompilerOptions(ImmutableList.of("-std=gnu++11")).addBuiltInIncludeDirectories(ImmutableList.of(new ExecutionRootPath("lib/gcc/arm-linux-androideabi/4.8/include"))).addUnfilteredCompilerOptions(ImmutableList.of("--sysroot=android_ndk_linux/platforms/android-18/arch-arm")).addUnfilteredToolchainSystemIncludes(ImmutableList.of(new ExecutionRootPath("android_ndk_linux/sources/llvm-libc++/libcxx/include"))))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("android_ndk_linux/toolchains/BUILD")).setLabel("//android_ndk_linux/toolchains:aarch64").setKind(Kind.CC_TOOLCHAIN).setCToolchainInfo(CToolchainIdeInfo.builder().setTargetName("aarch64-linux-android").setCppExecutable(new ExecutionRootPath("prebuilt/bin/aarch64-linux-android-gcc")).addBaseCompilerOptions(ImmutableList.of("-DOS_ANDROID", "-mbionic", "-ffunction-sections")).addCppCompilerOptions(ImmutableList.of("-std=gnu++11")).addBuiltInIncludeDirectories(ImmutableList.of(new ExecutionRootPath("lib/gcc/aarch64-linux-android/4.9/include"))).addUnfilteredCompilerOptions(ImmutableList.of("--sysroot=android_ndk_linux/platforms/android-21/arch-arm64")).addUnfilteredToolchainSystemIncludes(ImmutableList.of(new ExecutionRootPath("android_ndk_linux/sources/llvm-libc++/libcxx/include"))))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(sourceRoot("java/com/google/AndroidManifest.xml")).addResource(sourceRoot("java/com/google/res/values/strings.xml")).setResourceJavaPackage("com.google").setGenerateResourceClass(true)).addSource(sourceRoot("java/com/google/Other.java"))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:native_lib").setKind("cc_library").setCInfo(CIdeInfo.builder().addTransitiveQuoteIncludeDirectories(ImmutableList.of(new ExecutionRootPath("."), new ExecutionRootPath("blaze-out/android-aarch64-etc/genfiles"), new ExecutionRootPath("blaze-out/android-aarch64-etc/genfiles/third_party/java"))).addTransitiveSystemIncludeDirectories(ImmutableList.of(new ExecutionRootPath("third_party/stl/gcc3"), new ExecutionRootPath("third_party/java/jdk/include"))).addSource(sourceRoot("java/com/google/jni/native.cc"))).addSource(sourceRoot("java/com/google/jni/native.cc")).addDependency("//android_ndk_linux/toolchains:aarch64")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:native_lib2").setKind("cc_library").setCInfo(CIdeInfo.builder().addTransitiveQuoteIncludeDirectories(ImmutableList.of(new ExecutionRootPath("."), new ExecutionRootPath("blaze-out/android-aarch64-etc/genfiles"), new ExecutionRootPath("blaze-out/android-aarch64-etc/genfiles/third_party/java"))).addTransitiveSystemIncludeDirectories(ImmutableList.of(new ExecutionRootPath("third_party/stl/gcc3"), new ExecutionRootPath("third_party/java/jdk/include"))).addSource(sourceRoot("java/com/google/jni/native2.cc"))).addSource(sourceRoot("java/com/google/jni/native2.cc")).addDependency("//java/com/google:native_lib").addDependency("//android_ndk_linux/toolchains:armv7a")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:app").setKind("android_binary").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(sourceRoot("java/com/google/AndroidManifest.xml")).setResourceJavaPackage("com.google").setGenerateResourceClass(true)).addSource(sourceRoot("java/com/google/Source.java")).addDependency("//tools/jdk:toolchain").addDependency("//android_ndk_linux/toolchains:armv7a").addDependency("//java/com/google:lib").addDependency("//java/com/google:native_lib").addDependency("//java/com/google:native_lib2")).build();
setTargetMap(targetMap);
runBlazeSync(new BlazeSyncParams.Builder("Sync", SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
errorCollector.assertNoIssues();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.ANDROID);
assertThat(blazeProjectData.workspaceLanguageSettings.isLanguageActive(LanguageClass.C)).isTrue();
// Check that the workspace is set to android
Module workspaceModule = ModuleFinder.getInstance(getProject()).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
assertThat(workspaceModule).isNotNull();
assertThat(AndroidFacet.getInstance(workspaceModule)).isNotNull();
// Check resolve configurations for the native code match the toolchain that was in
// the library's deps (not switched for some reason).
VirtualFile nativeCc = fileSystem.findFile(workspaceRoot.fileForPath(new WorkspacePath("java/com/google/jni/native.cc")).getPath());
VirtualFile nativeCc2 = fileSystem.findFile(workspaceRoot.fileForPath(new WorkspacePath("java/com/google/jni/native2.cc")).getPath());
List<? extends OCResolveConfiguration> resolveConfigurations = OCWorkspaceManager.getWorkspace(getProject()).getConfigurationsForFile(nativeCc);
assertThat(resolveConfigurations).hasSize(1);
OCCompilerSettings compilerSettings = resolveConfigurations.get(0).getCompilerSettings();
List<String> compilerSwitches = CidrCompilerSwitchesAdapter.getCommandLineArgs(compilerSettings.getCompilerSwitches(OCLanguageKind.CPP, nativeCc));
assertThat(compilerSwitches).contains("--sysroot=android_ndk_linux/platforms/android-21/arch-arm64");
resolveConfigurations = OCWorkspaceManager.getWorkspace(getProject()).getConfigurationsForFile(nativeCc2);
assertThat(resolveConfigurations).hasSize(1);
compilerSettings = resolveConfigurations.get(0).getCompilerSettings();
compilerSwitches = CidrCompilerSwitchesAdapter.getCommandLineArgs(compilerSettings.getCompilerSwitches(OCLanguageKind.CPP, nativeCc));
assertThat(compilerSwitches).contains("--sysroot=android_ndk_linux/platforms/android-18/arch-arm");
}
use of com.google.idea.blaze.base.model.primitives.ExecutionRootPath in project intellij by bazelbuild.
the class BlazeConfigurationResolver method doCollectHeaderRoots.
private static ImmutableMap<File, VirtualFile> doCollectHeaderRoots(BlazeContext context, BlazeProjectData projectData, Set<ExecutionRootPath> rootPaths, ExecutionRootPathResolver pathResolver) {
ConcurrentMap<File, VirtualFile> rootsMap = Maps.newConcurrentMap();
List<ListenableFuture<Void>> futures = Lists.newArrayListWithCapacity(rootPaths.size());
AtomicInteger genRootsWithHeaders = new AtomicInteger();
AtomicInteger genRootsWithoutHeaders = new AtomicInteger();
for (ExecutionRootPath path : rootPaths) {
futures.add(submit(() -> {
ImmutableList<File> possibleDirectories = pathResolver.resolveToIncludeDirectories(path);
if (possibleDirectories.isEmpty()) {
logger.info(String.format("Couldn't resolve include root: %s", path));
}
for (File file : possibleDirectories) {
VirtualFile vf = VfsUtils.resolveVirtualFile(file);
if (vf != null) {
// other random generated files (like .s, .cc, or module maps).
if (!isOutputArtifact(projectData.blazeInfo, path)) {
rootsMap.put(file, vf);
} else if (genRootMayContainHeaders(vf)) {
genRootsWithHeaders.incrementAndGet();
rootsMap.put(file, vf);
} else {
genRootsWithoutHeaders.incrementAndGet();
}
} else if (!isOutputArtifact(projectData.blazeInfo, path) && FileOperationProvider.getInstance().exists(file)) {
// If it's not a blaze output file, we expect it to always resolve.
logger.info(String.format("Unresolved header root %s", file.getAbsolutePath()));
}
}
return null;
}));
}
try {
Futures.allAsList(futures).get();
ImmutableMap<File, VirtualFile> result = ImmutableMap.copyOf(rootsMap);
logger.info(String.format("CollectHeaderRoots: %s roots, (%s, %s) genroots with/without headers", result.size(), genRootsWithHeaders.get(), genRootsWithoutHeaders.get()));
return result;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
context.setCancelled();
} catch (ExecutionException e) {
IssueOutput.error("Error resolving header include roots: " + e).submit(context);
logger.error("Error resolving header include roots", e);
}
return ImmutableMap.of();
}
use of com.google.idea.blaze.base.model.primitives.ExecutionRootPath in project intellij by bazelbuild.
the class ExecutionRootPathResolverTest method testNonOutputPathsRelativeToWorkspaceRoot.
@Test
public void testNonOutputPathsRelativeToWorkspaceRoot() {
ImmutableList<File> files = pathResolver.resolveToIncludeDirectories(new ExecutionRootPath("tools/fast"));
assertThat(files).containsExactly(WORKSPACE_ROOT.fileForPath(new WorkspacePath("tools/fast")));
}
use of com.google.idea.blaze.base.model.primitives.ExecutionRootPath in project intellij by bazelbuild.
the class ExecutionRootPathResolverTest method testGenfilesPathWithDifferentConfigSettingStillResolves.
@Test
public void testGenfilesPathWithDifferentConfigSettingStillResolves() {
ImmutableList<File> files = pathResolver.resolveToIncludeDirectories(new ExecutionRootPath("bazel-out/arm-linux-fastbuild/genfiles/res/normal"));
assertThat(files).containsExactly(new File(EXECUTION_ROOT, "bazel-out/arm-linux-fastbuild/genfiles/res/normal"));
}
use of com.google.idea.blaze.base.model.primitives.ExecutionRootPath in project intellij by bazelbuild.
the class BlazeCppAutoImportHelperTest method createCcTarget.
private TargetIdeInfo.Builder createCcTarget(String label, Kind kind, List<ArtifactLocation> sources, List<ArtifactLocation> headers) {
TargetIdeInfo.Builder targetInfo = TargetIdeInfo.builder().setLabel(label).setKind(kind).addDependency("//:toolchain");
sources.forEach(targetInfo::addSource);
return targetInfo.setCInfo(CIdeInfo.builder().addSources(sources).addHeaders(headers).addTransitiveIncludeDirectories(ImmutableList.of(new ExecutionRootPath("include/third_party/libxml/_/libxml"))).addTransitiveQuoteIncludeDirectories(ImmutableList.of(new ExecutionRootPath("."), new ExecutionRootPath("output/genfiles"))).addTransitiveSystemIncludeDirectories(ImmutableList.of(new ExecutionRootPath("third_party/stl"), new ExecutionRootPath("third_party/lib_that_expects_angle_include"))));
}
Aggregations