use of com.google.idea.blaze.base.ideinfo.TargetMap 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.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeRenderErrorContributorTest method createTargetMapWithNonStandardAndroidManifestNameInDependency.
private void createTargetMapWithNonStandardAndroidManifestNameInDependency() {
Label mainResourceTarget = Label.create("//com/google/example:main");
Label dependencyResourceTarget = Label.create("//com/google/example:dependency");
ArtifactLocation mainManifest = artifact("com/google/example/main/AndroidManifest.xml", true);
ArtifactLocation mainResource = artifact("com/google/example/main/res", true);
ArtifactLocation mainBuildFile = artifact("com/google/example/main/BUILD", true);
ArtifactLocation dependencyManifest = artifact("com/google/example/dependency/MyManifest.xml", true);
ArtifactLocation dependencyResource = artifact("com/google/example/dependency/res", true);
ArtifactLocation dependencyBuildFile = artifact("com/google/example/dependency/BUILD", true);
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(mainResourceTarget)).addResource(mainResource).addTransitiveResourceDependency(dependencyResourceTarget).addTransitiveResource(dependencyResource).build());
registry.put(mock(Module.class), AndroidResourceModule.builder(TargetKey.forPlainTarget(dependencyResourceTarget)).addResource(dependencyResource).build());
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(mainResourceTarget).setBuildFile(mainBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(mainManifest).addResource(mainResource))).addTarget(TargetIdeInfo.builder().setLabel(dependencyResourceTarget).setBuildFile(dependencyBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(dependencyManifest).addResource(dependencyResource))).build();
projectDataManager.setTargetMap(targetMap);
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method importJavaWorkspace.
private BlazeJavaImportResult importJavaWorkspace(WorkspaceRoot workspaceRoot, TargetMapBuilder targetMapBuilder, ProjectView projectView) {
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
TargetMap targetMap = targetMapBuilder.build();
JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
BlazeJavaWorkspaceImporter blazeWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, workingSet, FAKE_ARTIFACT_DECODER);
return blazeWorkspaceImporter.importWorkspace(context);
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.
@Test
public void testIdlClassJarIsAddedAsLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
TargetMap targetMap = targetMapBuilder.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method importWorkspace.
public BlazeAndroidImportResult importWorkspace() {
List<TargetIdeInfo> sourceTargets = targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.ANDROID).filter(target -> target.androidIdeInfo != null).filter(importFilter::isSourceTarget).filter(target -> !importFilter.excludeTarget(target)).collect(Collectors.toList());
TransitiveResourceMap transitiveResourceMap = new TransitiveResourceMap(targetMap);
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceTargets) {
addSourceTarget(workspaceBuilder, transitiveResourceMap, target);
}
GeneratedResourceWarnings.submit(project, context, projectViewSet, artifactLocationDecoder, workspaceBuilder.generatedResourceLocations, whitelistedGenResourcePaths);
ImmutableList<AndroidResourceModule> androidResourceModules = buildAndroidResourceModules(workspaceBuilder);
BlazeResourceLibrary resourceLibrary = createResourceLibrary(androidResourceModules);
ImmutableList<AarLibrary> aarLibraries = createAarLibraries(sourceFilter.getLibraryTargets());
return new BlazeAndroidImportResult(androidResourceModules, resourceLibrary, aarLibraries, getJavacJar(targetMap.targets()));
}
Aggregations