chore: Isolate C++ toolchain into separate package to fix verifier error

This commit is contained in:
FalsePattern 2024-02-29 20:22:48 +01:00
parent 5758434b2c
commit a1eee6101a
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
6 changed files with 129 additions and 28 deletions

View file

@ -0,0 +1,49 @@
/*
* Copyright 2023-2024 FalsePattern
*
* 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.falsepattern.zigbrains.zig.cpp;
import com.falsepattern.zigbrains.zig.debugbridge.DebuggerDriverProvider;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.jetbrains.cidr.cpp.execution.debugger.backend.CLionGDBDriverConfiguration;
import com.jetbrains.cidr.cpp.execution.debugger.backend.CLionLLDBDriverConfiguration;
import com.jetbrains.cidr.cpp.toolchains.CPPToolchains;
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration;
import lombok.val;
import org.jetbrains.annotations.Nullable;
public class CPPDebuggerDriverProvider implements DebuggerDriverProvider {
private static final Logger LOG = Logger.getInstance(CPPDebuggerDriverProvider.class);
@Override
public @Nullable DebuggerDriverConfiguration getDebuggerConfiguration(Project project) {
val toolchains = CPPToolchains.getInstance();
var toolchain = toolchains.getToolchainByNameOrDefault("Zig");
if (toolchain == null || !toolchain.isDebuggerSupported()) {
LOG.info("Couldn't find debug-compatible C++ toolchain with name \"Zig\"");
toolchain = toolchains.getDefaultToolchain();
}
if (toolchain == null || !toolchain.isDebuggerSupported()) {
LOG.info("Couldn't find debug-compatible C++ default toolchain");
return null;
}
return switch (toolchain.getDebuggerKind()) {
case CUSTOM_GDB, BUNDLED_GDB -> new CLionGDBDriverConfiguration(project, toolchain);
case BUNDLED_LLDB -> new CLionLLDBDriverConfiguration(project, toolchain);
};
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright 2023-2024 FalsePattern
*
* 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.falsepattern.zigbrains.zig.debugbridge;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.UserDataHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.stream.Stream;
/**
* getDebuggerConfiguration should return com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration, it's UserDataHolder here to
* avoid a plugin verifier error.
*/
public interface DebuggerDriverProvider {
ExtensionPointName<DebuggerDriverProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.falsepattern.zigbrains.debuggerDriverProvider");
static @NotNull Stream<UserDataHolder> findDebuggerConfigurations(Project project) {
return EXTENSION_POINT_NAME.getExtensionList()
.stream()
.map(it -> it.getDebuggerConfiguration(project))
.filter(Objects::nonNull);
}
@Nullable UserDataHolder getDebuggerConfiguration(Project project);
}

View file

@ -16,52 +16,34 @@
package com.falsepattern.zigbrains.zig.debugger;
import com.falsepattern.zigbrains.zig.debugbridge.DebuggerDriverProvider;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.jetbrains.cidr.cpp.execution.debugger.backend.CLionGDBDriverConfiguration;
import com.jetbrains.cidr.cpp.execution.debugger.backend.CLionLLDBDriverConfiguration;
import com.jetbrains.cidr.cpp.toolchains.CPPToolchains;
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration;
import com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriverConfiguration;
import lombok.val;
import org.jetbrains.annotations.Nullable;
public class Utils {
private static final Logger LOG = Logger.getInstance(ZigDebugRunParameters.class);
public static @Nullable DebuggerDriverConfiguration getDebuggerConfiguration(Project project) {
val cppDebugger = tryGetCPPDebugger(project);
if (cppDebugger != null)
return cppDebugger;
val providedDebugger = DebuggerDriverProvider.findDebuggerConfigurations(project)
.filter(x -> x instanceof DebuggerDriverConfiguration)
.map(x -> (DebuggerDriverConfiguration)x)
.findFirst()
.orElse(null);
if (providedDebugger != null)
return providedDebugger;
if (LLDBDriverConfiguration.hasBundledLLDB()) {
Notifications.Bus.notify(new Notification("ZigBrains.Debugger.Warn",
"Couldn't find a working C++ toolchain, using bundled LLDB debugger!",
"Couldn't find a working debug toolchain, using bundled LLDB debugger!",
NotificationType.WARNING));
return new LLDBDriverConfiguration();
} else {
return null;
}
}
private static @Nullable DebuggerDriverConfiguration tryGetCPPDebugger(Project project) {
val toolchains = CPPToolchains.getInstance();
var toolchain = toolchains.getToolchainByNameOrDefault("Zig");
if (toolchain == null || !toolchain.isDebuggerSupported()) {
LOG.info("Couldn't find debug-compatible C++ toolchain with name \"Zig\"");
toolchain = toolchains.getDefaultToolchain();
}
if (toolchain == null || !toolchain.isDebuggerSupported()) {
LOG.info("Couldn't find debug-compatible C++ default toolchain");
return null;
}
return switch (toolchain.getDebuggerKind()) {
case CUSTOM_GDB, BUNDLED_GDB -> new CLionGDBDriverConfiguration(project, toolchain);
case BUNDLED_LLDB -> new CLionLLDBDriverConfiguration(project, toolchain);
};
}
}

View file

@ -0,0 +1,23 @@
<!--
~ Copyright 2023-2024 FalsePattern
~
~ 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.
-->
<idea-plugin package="com.falsepattern.zigbrains.zig.cpp">
<depends>com.intellij.modules.clion</depends>
<extensions defaultExtensionNs="com.falsepattern.zigbrains">
<debuggerDriverProvider implementation="com.falsepattern.zigbrains.zig.cpp.CPPDebuggerDriverProvider"/>
</extensions>
</idea-plugin>

View file

@ -15,7 +15,7 @@
-->
<idea-plugin package="com.falsepattern.zigbrains.zig.debugger">
<depends>com.intellij.modules.clion</depends>
<depends>com.intellij.modules.cidr.debugger</depends>
<resource-bundle>zigbrains.zig.debugger.Bundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">

View file

@ -11,6 +11,7 @@
<xi:include href="/META-INF/zigbrains-project.xml"/>
<!--suppress PluginXmlValidity -->
<depends optional="true" config-file="zigbrains-zig-debugger.xml">com.intellij.modules.cidr.debugger</depends>
<depends optional="true" config-file="zigbrains-zig-cpp.xml">com.intellij.modules.clion</depends>
<extensionPoints>
<!-- region zigbrains-project -->
@ -23,6 +24,9 @@
<extensionPoint
interface="com.falsepattern.zigbrains.zig.environment.ZLSConfigProvider" dynamic="true"
name="zlsConfigProvider"/>
<extensionPoint
interface="com.falsepattern.zigbrains.zig.debugbridge.DebuggerDriverProvider" dynamic="true"
name="debuggerDriverProvider"/>
<!-- endregion zigbrains-project -->
</extensionPoints>
</idea-plugin>