Search in sources :

Example 1 with OCCompilerSettings

use of com.jetbrains.cidr.lang.workspace.compiler.OCCompilerSettings in project intellij by bazelbuild.

the class OCResolveConfigurationAdapter method getCompilerFeatures.

@Override
public Map<Type<?>, ?> getCompilerFeatures(OCLanguageKind kind, @Nullable VirtualFile virtualFile) {
    OCCompilerSettings compilerSettings = getCompilerSettings();
    if (!(compilerSettings instanceof OCCompilerSettingsBackedByCompilerCache)) {
        return Collections.emptyMap();
    }
    OCCompilerSettingsBackedByCompilerCache backedCompilerSettings = (OCCompilerSettingsBackedByCompilerCache) compilerSettings;
    return backedCompilerSettings.getCompilerFeatures(kind, virtualFile);
}
Also used : OCCompilerSettings(com.jetbrains.cidr.lang.workspace.compiler.OCCompilerSettings) OCCompilerSettingsBackedByCompilerCache(com.jetbrains.cidr.toolchains.OCCompilerSettingsBackedByCompilerCache)

Example 2 with OCCompilerSettings

use of com.jetbrains.cidr.lang.workspace.compiler.OCCompilerSettings 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");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) OCCompilerSettings(com.jetbrains.cidr.lang.workspace.compiler.OCCompilerSettings) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath) Module(com.intellij.openapi.module.Module) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Aggregations

OCCompilerSettings (com.jetbrains.cidr.lang.workspace.compiler.OCCompilerSettings)2 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 ExecutionRootPath (com.google.idea.blaze.base.model.primitives.ExecutionRootPath)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 OCCompilerSettingsBackedByCompilerCache (com.jetbrains.cidr.toolchains.OCCompilerSettingsBackedByCompilerCache)1 Test (org.junit.Test)1