diff --git a/aswb/BUILD b/aswb/BUILD
index acd02563032..d0cf72f9057 100644
--- a/aswb/BUILD
+++ b/aswb/BUILD
@@ -166,6 +166,7 @@ java_library(
deps = [
"//base",
"//common/experiments",
+ "//cpp",
"//intellij_platform_sdk:jsr305", # unuseddeps: keep
"//intellij_platform_sdk:kotlin",
"//intellij_platform_sdk:plugin_api",
diff --git a/aswb/src/META-INF/aswb.xml b/aswb/src/META-INF/aswb.xml
index 1b102d5493a..4d1c88a8f3b 100644
--- a/aswb/src/META-INF/aswb.xml
+++ b/aswb/src/META-INF/aswb.xml
@@ -98,6 +98,10 @@
+
+
+
+
diff --git a/aswb/src/com/google/idea/blaze/android/cppimpl/NdkCppSupportChecker.java b/aswb/src/com/google/idea/blaze/android/cppimpl/NdkCppSupportChecker.java
new file mode 100644
index 00000000000..85fe77739ad
--- /dev/null
+++ b/aswb/src/com/google/idea/blaze/android/cppimpl/NdkCppSupportChecker.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2024 The Bazel Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.idea.blaze.android.cppimpl;
+
+import com.android.tools.ndk.AndroidSysroot;
+import com.android.tools.ndk.configuration.NdkConfigurationValidatorKt;
+import com.google.common.collect.ImmutableList;
+import com.google.idea.blaze.cpp.CppSupportChecker;
+import java.nio.file.Path;
+
+/**
+ * Uses the Android Studio API to check if a CPP configuration is supported, i.e. is for NDK
+ * development rather than non-Android CPP.
+ */
+public class NdkCppSupportChecker implements CppSupportChecker {
+
+ @Override
+ public boolean supportsCppConfiguration(
+ ImmutableList compilerSwitches, Path workspaceRoot) {
+ return NdkConfigurationValidatorKt.isValidNdkConfiguration(
+ compilerSwitches,
+ workspaceRoot,
+ AndroidSysroot::isValidAndroidSysroot,
+ AndroidSysroot::isValidAndroidSysrootUsrInclude,
+ AndroidSysroot::isPotentialNonAndroidSysrootUsrInclude);
+ }
+}
diff --git a/clwb/src/META-INF/clwb.xml b/clwb/src/META-INF/clwb.xml
index b12be15c1b7..8d05b1ed8a1 100644
--- a/clwb/src/META-INF/clwb.xml
+++ b/clwb/src/META-INF/clwb.xml
@@ -43,6 +43,10 @@
+
+
+
+
com.google.idea.blaze.plugin.ClwbProjectSpecificInitializer
diff --git a/clwb/src/com/google/idea/blaze/clwb/ClwbSupportsCpp.java b/clwb/src/com/google/idea/blaze/clwb/ClwbSupportsCpp.java
new file mode 100644
index 00000000000..4c42001f1c7
--- /dev/null
+++ b/clwb/src/com/google/idea/blaze/clwb/ClwbSupportsCpp.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2024 The Bazel Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.idea.blaze.clwb;
+
+import com.google.common.collect.ImmutableList;
+import com.google.idea.blaze.cpp.CppSupportChecker;
+import java.nio.file.Path;
+
+/** CLwB supports all CPP development. */
+public class ClwbSupportsCpp implements CppSupportChecker {
+
+ @Override
+ public boolean supportsCppConfiguration(
+ ImmutableList compilerSwitches, Path workspaceRoot) {
+ return true;
+ }
+}
diff --git a/cpp/sdkcompat/v223/com/google/idea/blaze/cpp/BlazeCWorkspace.java b/cpp/sdkcompat/v223/com/google/idea/blaze/cpp/BlazeCWorkspace.java
index 6f0b9a435d9..5e06d6378b2 100644
--- a/cpp/sdkcompat/v223/com/google/idea/blaze/cpp/BlazeCWorkspace.java
+++ b/cpp/sdkcompat/v223/com/google/idea/blaze/cpp/BlazeCWorkspace.java
@@ -52,6 +52,7 @@
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.OCLanguageKind;
import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches;
+import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches.Format;
import com.jetbrains.cidr.lang.toolchains.CidrSwitchBuilder;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
@@ -311,18 +312,24 @@ private static void addConfiguration(
id, displayName, null, OCResolveConfiguration.DEFAULT_FILE_SEPARATORS);
for (Map.Entry languageEntry :
configLanguages.entrySet()) {
- OCCompilerSettings.ModifiableModel langSettings =
- config.getLanguageCompilerSettings(languageEntry.getKey());
PerLanguageCompilerOpts configForLanguage = languageEntry.getValue();
- langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
- langSettings.setCompilerSwitches(configForLanguage.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ configForLanguage.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel langSettings =
+ config.getLanguageCompilerSettings(languageEntry.getKey());
+ langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
+ langSettings.setCompilerSwitches(configForLanguage.switches);
+ }
}
for (Map.Entry fileEntry : configSourceFiles.entrySet()) {
PerFileCompilerOpts compilerOpts = fileEntry.getValue();
- OCCompilerSettings.ModifiableModel fileCompilerSettings =
- config.addSource(fileEntry.getKey(), compilerOpts.kind);
- fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ compilerOpts.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel fileCompilerSettings =
+ config.addSource(fileEntry.getKey(), compilerOpts.kind);
+ fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ }
}
}
diff --git a/cpp/sdkcompat/v231/com/google/idea/blaze/cpp/BlazeCWorkspace.java b/cpp/sdkcompat/v231/com/google/idea/blaze/cpp/BlazeCWorkspace.java
index 6f0b9a435d9..5e06d6378b2 100644
--- a/cpp/sdkcompat/v231/com/google/idea/blaze/cpp/BlazeCWorkspace.java
+++ b/cpp/sdkcompat/v231/com/google/idea/blaze/cpp/BlazeCWorkspace.java
@@ -52,6 +52,7 @@
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.OCLanguageKind;
import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches;
+import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches.Format;
import com.jetbrains.cidr.lang.toolchains.CidrSwitchBuilder;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
@@ -311,18 +312,24 @@ private static void addConfiguration(
id, displayName, null, OCResolveConfiguration.DEFAULT_FILE_SEPARATORS);
for (Map.Entry languageEntry :
configLanguages.entrySet()) {
- OCCompilerSettings.ModifiableModel langSettings =
- config.getLanguageCompilerSettings(languageEntry.getKey());
PerLanguageCompilerOpts configForLanguage = languageEntry.getValue();
- langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
- langSettings.setCompilerSwitches(configForLanguage.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ configForLanguage.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel langSettings =
+ config.getLanguageCompilerSettings(languageEntry.getKey());
+ langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
+ langSettings.setCompilerSwitches(configForLanguage.switches);
+ }
}
for (Map.Entry fileEntry : configSourceFiles.entrySet()) {
PerFileCompilerOpts compilerOpts = fileEntry.getValue();
- OCCompilerSettings.ModifiableModel fileCompilerSettings =
- config.addSource(fileEntry.getKey(), compilerOpts.kind);
- fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ compilerOpts.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel fileCompilerSettings =
+ config.addSource(fileEntry.getKey(), compilerOpts.kind);
+ fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ }
}
}
diff --git a/cpp/sdkcompat/v232/com/google/idea/blaze/cpp/BlazeCWorkspace.java b/cpp/sdkcompat/v232/com/google/idea/blaze/cpp/BlazeCWorkspace.java
index 6f0b9a435d9..5e06d6378b2 100644
--- a/cpp/sdkcompat/v232/com/google/idea/blaze/cpp/BlazeCWorkspace.java
+++ b/cpp/sdkcompat/v232/com/google/idea/blaze/cpp/BlazeCWorkspace.java
@@ -52,6 +52,7 @@
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.OCLanguageKind;
import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches;
+import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches.Format;
import com.jetbrains.cidr.lang.toolchains.CidrSwitchBuilder;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
@@ -311,18 +312,24 @@ private static void addConfiguration(
id, displayName, null, OCResolveConfiguration.DEFAULT_FILE_SEPARATORS);
for (Map.Entry languageEntry :
configLanguages.entrySet()) {
- OCCompilerSettings.ModifiableModel langSettings =
- config.getLanguageCompilerSettings(languageEntry.getKey());
PerLanguageCompilerOpts configForLanguage = languageEntry.getValue();
- langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
- langSettings.setCompilerSwitches(configForLanguage.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ configForLanguage.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel langSettings =
+ config.getLanguageCompilerSettings(languageEntry.getKey());
+ langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
+ langSettings.setCompilerSwitches(configForLanguage.switches);
+ }
}
for (Map.Entry fileEntry : configSourceFiles.entrySet()) {
PerFileCompilerOpts compilerOpts = fileEntry.getValue();
- OCCompilerSettings.ModifiableModel fileCompilerSettings =
- config.addSource(fileEntry.getKey(), compilerOpts.kind);
- fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ compilerOpts.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel fileCompilerSettings =
+ config.addSource(fileEntry.getKey(), compilerOpts.kind);
+ fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ }
}
}
diff --git a/cpp/sdkcompat/v233/com/google/idea/blaze/cpp/BlazeCWorkspace.java b/cpp/sdkcompat/v233/com/google/idea/blaze/cpp/BlazeCWorkspace.java
index f6f682ff7da..bd8ca9dc197 100644
--- a/cpp/sdkcompat/v233/com/google/idea/blaze/cpp/BlazeCWorkspace.java
+++ b/cpp/sdkcompat/v233/com/google/idea/blaze/cpp/BlazeCWorkspace.java
@@ -52,6 +52,7 @@
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.OCLanguageKind;
import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches;
+import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches.Format;
import com.jetbrains.cidr.lang.toolchains.CidrSwitchBuilder;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
@@ -312,18 +313,24 @@ private static void addConfiguration(
id, displayName, null, OCResolveConfiguration.DEFAULT_FILE_SEPARATORS);
for (Map.Entry languageEntry :
configLanguages.entrySet()) {
- OCCompilerSettings.ModifiableModel langSettings =
- config.getLanguageCompilerSettings(languageEntry.getKey());
PerLanguageCompilerOpts configForLanguage = languageEntry.getValue();
- langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
- langSettings.setCompilerSwitches(configForLanguage.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ configForLanguage.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel langSettings =
+ config.getLanguageCompilerSettings(languageEntry.getKey());
+ langSettings.setCompiler(configForLanguage.kind, configForLanguage.compiler, directory);
+ langSettings.setCompilerSwitches(configForLanguage.switches);
+ }
}
for (Map.Entry fileEntry : configSourceFiles.entrySet()) {
PerFileCompilerOpts compilerOpts = fileEntry.getValue();
- OCCompilerSettings.ModifiableModel fileCompilerSettings =
- config.addSource(fileEntry.getKey(), compilerOpts.kind);
- fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ if (CppSupportChecker.isSupportedCppConfiguration(
+ compilerOpts.switches.getList(Format.RAW), directory.toPath())) {
+ OCCompilerSettings.ModifiableModel fileCompilerSettings =
+ config.addSource(fileEntry.getKey(), compilerOpts.kind);
+ fileCompilerSettings.setCompilerSwitches(compilerOpts.switches);
+ }
}
}
diff --git a/cpp/src/META-INF/blaze-cpp.xml b/cpp/src/META-INF/blaze-cpp.xml
index 0a4c934ed04..651a4efa3e8 100644
--- a/cpp/src/META-INF/blaze-cpp.xml
+++ b/cpp/src/META-INF/blaze-cpp.xml
@@ -26,6 +26,8 @@
+
diff --git a/cpp/src/com/google/idea/blaze/cpp/CppSupportChecker.java b/cpp/src/com/google/idea/blaze/cpp/CppSupportChecker.java
new file mode 100644
index 00000000000..15e9b0879ba
--- /dev/null
+++ b/cpp/src/com/google/idea/blaze/cpp/CppSupportChecker.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2024 The Bazel Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.idea.blaze.cpp;
+
+import com.google.common.collect.ImmutableList;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import java.nio.file.Path;
+import java.util.List;
+
+/** Checks whether or not the IDE supports a given CPP configuration. */
+public interface CppSupportChecker {
+
+ ExtensionPointName EP_NAME =
+ new ExtensionPointName<>("com.google.idea.blaze.cpp.CppSupportChecker");
+
+ Logger logger = Logger.getInstance(CppSupportChecker.class);
+
+ static boolean isSupportedCppConfiguration(List compilerSwitches, Path workspaceRoot) {
+ for (CppSupportChecker checker : EP_NAME.getExtensionList()) {
+ if (checker.supportsCppConfiguration(ImmutableList.copyOf(compilerSwitches), workspaceRoot)) {
+ logger.info("CPP support allowed by " + checker.getClass().getName());
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boolean supportsCppConfiguration(ImmutableList compilerSwitches, Path workspaceRoot);
+}
diff --git a/cpp/src/com/google/idea/blaze/cpp/qsync/CcProjectModelUpdateOperation.java b/cpp/src/com/google/idea/blaze/cpp/qsync/CcProjectModelUpdateOperation.java
index 22d8618a097..77c390cd16e 100644
--- a/cpp/src/com/google/idea/blaze/cpp/qsync/CcProjectModelUpdateOperation.java
+++ b/cpp/src/com/google/idea/blaze/cpp/qsync/CcProjectModelUpdateOperation.java
@@ -24,6 +24,7 @@
import com.google.idea.blaze.base.util.UrlUtil;
import com.google.idea.blaze.common.Context;
import com.google.idea.blaze.common.PrintOutput;
+import com.google.idea.blaze.cpp.CppSupportChecker;
import com.google.idea.blaze.qsync.cc.FlagResolver;
import com.google.idea.blaze.qsync.project.ProjectPath;
import com.google.idea.blaze.qsync.project.ProjectPath.Root;
@@ -41,6 +42,7 @@
import com.intellij.util.containers.MultiMap;
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches;
+import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches.Format;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
import com.jetbrains.cidr.lang.workspace.OCResolveConfiguration;
@@ -110,6 +112,12 @@ private void visitCompilationContext(CcCompilationContext ccCc) {
private void visitLanguageCompilerSettingsMap(
Map map, OCResolveConfiguration.ModifiableModel config) {
for (Map.Entry e : map.entrySet()) {
+ CidrCompilerSwitches switches =
+ checkNotNull(compilerSwitches.get(e.getValue().getFlagSetId()));
+ if (!CppSupportChecker.isSupportedCppConfiguration(
+ switches.getList(Format.RAW), compilerWorkingDir.toPath())) {
+ return;
+ }
CLanguageKind lang =
getLanguageKind(
ProjectProto.CcLanguage.valueOf(
@@ -119,12 +127,18 @@ private void visitLanguageCompilerSettingsMap(
config.getLanguageCompilerSettings(lang);
compilerSettings.setCompiler(
ClangCompilerKind.INSTANCE, getCompilerExecutable(e.getValue()), compilerWorkingDir);
- compilerSettings.setCompilerSwitches(
- checkNotNull(compilerSwitches.get(e.getValue().getFlagSetId())));
+ compilerSettings.setCompilerSwitches(switches);
}
}
private void visitSourceFile(CcSourceFile source, OCResolveConfiguration.ModifiableModel config) {
+ CidrCompilerSwitches switches =
+ checkNotNull(compilerSwitches.get(source.getCompilerSettings().getFlagSetId()));
+ if (!CppSupportChecker.isSupportedCppConfiguration(
+ switches.getList(Format.RAW), pathResolver.resolve(ProjectPath.WORKSPACE_ROOT))) {
+ // Ignore the file if it's not supported by the current IDE.
+ return;
+ }
Path srcPath = Path.of(source.getWorkspacePath());
CLanguageKind language =
getLanguageKind(source.getLanguage(), "Source file " + source.getWorkspacePath());
@@ -134,8 +148,7 @@ private void visitSourceFile(CcSourceFile source, OCResolveConfiguration.Modifia
}
OCCompilerSettings.ModifiableModel perSourceCompilerSettings =
config.addSource(UrlUtil.pathToIdeaDirectoryUrl(srcPath), language);
- perSourceCompilerSettings.setCompilerSwitches(
- checkNotNull(compilerSwitches.get(source.getCompilerSettings().getFlagSetId())));
+ perSourceCompilerSettings.setCompilerSwitches(switches);
perSourceCompilerSettings.setCompiler(
ClangCompilerKind.INSTANCE,
getCompilerExecutable(source.getCompilerSettings()),