use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class LibraryEditor method updateProjectLibraries.
public static void updateProjectLibraries(Project project, BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Collection<BlazeLibrary> libraries) {
Set<LibraryKey> intelliJLibraryState = Sets.newHashSet();
for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
String name = library.getName();
if (name != null) {
intelliJLibraryState.add(LibraryKey.fromIntelliJLibraryName(name));
}
}
context.output(PrintOutput.log(String.format("Workspace has %d libraries", libraries.size())));
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();
try {
for (BlazeLibrary library : libraries) {
updateLibrary(project, blazeProjectData.artifactLocationDecoder, libraryTable, libraryTableModel, library);
}
// Garbage collect unused libraries
List<LibrarySource> librarySources = Lists.newArrayList();
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
LibrarySource librarySource = syncPlugin.getLibrarySource(projectViewSet, blazeProjectData);
if (librarySource != null) {
librarySources.add(librarySource);
}
}
Predicate<Library> gcRetentionFilter = librarySources.stream().map(LibrarySource::getGcRetentionFilter).filter(Objects::nonNull).reduce(Predicate::or).orElse(o -> false);
Set<LibraryKey> newLibraryKeys = libraries.stream().map((blazeLibrary) -> blazeLibrary.key).collect(Collectors.toSet());
for (LibraryKey libraryKey : intelliJLibraryState) {
String libraryIntellijName = libraryKey.getIntelliJLibraryName();
if (!newLibraryKeys.contains(libraryKey)) {
Library library = libraryTable.getLibraryByName(libraryIntellijName);
if (!gcRetentionFilter.test(library)) {
if (library != null) {
libraryTableModel.removeLibrary(library);
}
}
}
}
} finally {
libraryTableModel.commit();
}
}
use of com.google.idea.blaze.base.model.BlazeProjectData 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.BlazeProjectData in project intellij by bazelbuild.
the class BlazeAndroidProjectStructureSyncer method updateInMemoryState.
private static void updateInMemoryState(Project project, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Module workspaceModule, AndroidResourceModuleRegistry registry, LightResourceClassService.Builder rClassBuilder) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData == null) {
return;
}
AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
if (androidSdkPlatform == null) {
return;
}
updateWorkspaceModuleFacetInMemoryState(project, workspaceRoot, workspaceModule, androidSdkPlatform);
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
ModuleFinder moduleFinder = ModuleFinder.getInstance(project);
Executor resourceRepositoryExecutor = Executors.newSingleThreadExecutor();
Module libraryResourcesModule = moduleFinder.findModuleByName(LIBRARY_RESOURCES_MODULE_NAME);
if (libraryResourcesModule != null) {
updateLibraryResourcesModuleFacetInMemoryState(project, workspaceRoot, libraryResourcesModule, androidSdkPlatform, syncData.importResult.resourceLibrary == null ? ImmutableList.of() : artifactLocationDecoder.decodeAll(syncData.importResult.resourceLibrary.sources), resourceRepositoryExecutor);
} else if (useLibraryResourcesModule.getValue()) {
logger.warn("Library resources module missing.");
}
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
TargetIdeInfo target = blazeProjectData.targetMap.get(androidResourceModule.targetKey);
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for resource target: " + target.key);
continue;
}
registry.put(module, androidResourceModule);
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, artifactLocationDecoder.decodeAll(useLibraryResourcesModule.getValue() ? androidResourceModule.resources : androidResourceModule.transitiveResources), resourceRepositoryExecutor);
rClassBuilder.addRClass(androidIdeInfo.resourceJavaPackage, module);
}
Set<TargetKey> androidResourceModules = syncData.importResult.androidResourceModules.stream().map(androidResourceModule -> androidResourceModule.targetKey).collect(toSet());
List<TargetIdeInfo> runConfigurationTargets = getRunConfigurationTargets(project, projectViewSet, blazeProjectData, androidResourceModules);
for (TargetIdeInfo target : runConfigurationTargets) {
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for run configuration target: " + target.key);
continue;
}
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
}
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class CPrefetchFileSourceTest method testSourceFilesInProjectIgnored.
@Test
public void testSourceFilesInProjectIgnored() {
ProjectViewSet projectViewSet = parseProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib", "additional_languages:", " c", "android_sdk_platform: android-25");
BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("cc_library").addSource(sourceRoot("java/com/google/native.cc")).addSource(sourceRoot("java/com/google/native.h"))).build()).setWorkspaceLanguageSettings(LanguageSupport.createWorkspaceLanguageSettings(projectViewSet)).build();
Set<File> filesToPrefetch = new HashSet<>();
new CPrefetchFileSource().addFilesToPrefetch(getProject(), projectViewSet, getImportRoots(projectViewSet), projectData, filesToPrefetch);
assertThat(filesToPrefetch).isEmpty();
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class CPrefetchFileSourceTest method testCppHeaderFilesOutsideProjectIncluded.
@Test
public void testCppHeaderFilesOutsideProjectIncluded() {
ProjectViewSet projectViewSet = parseProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib", "additional_languages:", " c", "android_sdk_platform: android-25");
BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("third_party/library/BUILD")).setLabel("//third_party/library:dep").setKind("cc_library").setCInfo(CIdeInfo.builder().addSource(sourceRoot("third_party/library/main.cc")).addHeader(sourceRoot("third_party/library/dep.h")).addHeader(sourceRoot("third_party/library/other.h")).addTextualHeader(sourceRoot("third_party/library/textual.h")))).build()).setWorkspaceLanguageSettings(LanguageSupport.createWorkspaceLanguageSettings(projectViewSet)).build();
Set<File> filesToPrefetch = new HashSet<>();
new CPrefetchFileSource().addFilesToPrefetch(getProject(), projectViewSet, getImportRoots(projectViewSet), projectData, filesToPrefetch);
assertThat(filesToPrefetch).containsExactly(workspaceFile("third_party/library/dep.h"), workspaceFile("third_party/library/other.h"), workspaceFile("third_party/library/textual.h"));
}
Aggregations