1 import { CommandWithResult } from "./command.mjs";
2 import { commands, workspace } from "vscode";
4 getPythonPath, getPath,
5 cmakeGetSelectedToolchainAndSDKVersions, cmakeGetPicoVar
6 } from "../utils/cmakeUtil.mjs";
7 import { join } from "path";
8 import { buildToolchainPath } from "../utils/download.mjs";
9 import Settings, { SettingsKey } from "../settings.mjs";
11 export class GetPythonPathCommand
12 extends CommandWithResult<string> {
14 super("getPythonPath");
17 async execute(): Promise<string> {
19 workspace.workspaceFolders === undefined ||
20 workspace.workspaceFolders.length === 0
25 const pythonPath = await getPythonPath();
31 export class GetEnvPathCommand
32 extends CommandWithResult<string> {
37 async execute(): Promise<string> {
39 workspace.workspaceFolders === undefined ||
40 workspace.workspaceFolders.length === 0
45 const path = await getPath();
51 export class GetGDBPathCommand
52 extends CommandWithResult<string> {
59 workspace.workspaceFolders === undefined ||
60 workspace.workspaceFolders.length === 0
65 const workspaceFolder = workspace.workspaceFolders?.[0];
67 const selectedToolchainAndSDKVersions =
68 cmakeGetSelectedToolchainAndSDKVersions(
69 join(workspaceFolder.uri.fsPath, "CMakeLists.txt")
71 if (selectedToolchainAndSDKVersions === null) {
74 const toolchainVersion = selectedToolchainAndSDKVersions[1];
76 let triple = "arm-none-eabi";
77 if (toolchainVersion.includes("RISCV")) {
78 if (toolchainVersion.includes("COREV")) {
79 triple = "riscv32-corev-elf";
81 triple = "riscv32-unknown-elf";
83 } else if (process.platform === "linux") {
84 // Arm toolchains have incorrect libncurses versions on Linux (specifically RPiOS)
85 if (process.arch === "arm64") {
88 return "gdb-multiarch";
92 return join(buildToolchainPath(toolchainVersion), "bin", triple + "-gdb");
96 export class GetChipCommand
97 extends CommandWithResult<string> {
102 async execute(): Promise<string> {
104 workspace.workspaceFolders === undefined ||
105 workspace.workspaceFolders.length === 0
110 const workspaceFolder = workspace.workspaceFolders?.[0];
112 const settings = Settings.getInstance();
113 let buildDir = join(workspaceFolder.uri.fsPath, "build");
115 settings !== undefined && settings.getBoolean(SettingsKey.useCmakeTools)
117 // Compiling with CMake Tools
118 const cmakeBuildDir: string = await commands.executeCommand(
119 "cmake.buildDirectory"
123 buildDir = cmakeBuildDir;
129 join(buildDir, "CMakeCache.txt"),
132 if (platform === null) {
136 if (platform === "rp2350-arm-s" || platform === "rp2350-riscv") {
144 export class GetTargetCommand
145 extends CommandWithResult<string> {
150 async execute(): Promise<string> {
152 workspace.workspaceFolders === undefined ||
153 workspace.workspaceFolders.length === 0
158 const workspaceFolder = workspace.workspaceFolders?.[0];
160 const settings = Settings.getInstance();
161 let buildDir = join(workspaceFolder.uri.fsPath, "build");
163 settings !== undefined && settings.getBoolean(SettingsKey.useCmakeTools)
165 // Compiling with CMake Tools
166 const cmakeBuildDir: string = await commands.executeCommand(
167 "cmake.buildDirectory"
171 buildDir = cmakeBuildDir;
177 join(buildDir, "CMakeCache.txt"),
180 if (platform === null) {
184 if (platform === "rp2350-arm-s") {
186 } else if (platform === "rp2350-riscv") {
187 return "rp2350-riscv";