1 import { CommandWithResult } from "./command.mjs";
2 import { commands, workspace } from "vscode";
6 cmakeGetSelectedToolchainAndSDKVersions,
8 } from "../utils/cmakeUtil.mjs";
9 import { join } from "path";
10 import { buildToolchainPath } from "../utils/download.mjs";
11 import Settings, { SettingsKey } from "../settings.mjs";
13 export class GetPythonPathCommand extends CommandWithResult<string> {
15 super("getPythonPath");
18 async execute(): Promise<string> {
20 workspace.workspaceFolders === undefined ||
21 workspace.workspaceFolders.length === 0
26 const pythonPath = await getPythonPath();
32 export class GetEnvPathCommand 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 extends CommandWithResult<string> {
58 workspace.workspaceFolders === undefined ||
59 workspace.workspaceFolders.length === 0
64 const workspaceFolder = workspace.workspaceFolders?.[0];
66 const selectedToolchainAndSDKVersions =
67 cmakeGetSelectedToolchainAndSDKVersions(
68 join(workspaceFolder.uri.fsPath, "CMakeLists.txt")
70 if (selectedToolchainAndSDKVersions === null) {
73 const toolchainVersion = selectedToolchainAndSDKVersions[1];
75 let triple = "arm-none-eabi";
76 if (toolchainVersion.includes("RISCV")) {
77 if (toolchainVersion.includes("COREV")) {
78 triple = "riscv32-corev-elf";
80 triple = "riscv32-unknown-elf";
82 } else if (process.platform === "linux") {
83 // Arm toolchains have incorrect libncurses versions on Linux (specifically RPiOS)
84 if (process.arch === "arm64") {
87 return "gdb-multiarch";
91 return join(buildToolchainPath(toolchainVersion), "bin", triple + "-gdb");
95 export class GetChipCommand extends CommandWithResult<string> {
100 async execute(): Promise<string> {
102 workspace.workspaceFolders === undefined ||
103 workspace.workspaceFolders.length === 0
108 const workspaceFolder = workspace.workspaceFolders?.[0];
110 const settings = Settings.getInstance();
111 let buildDir = join(workspaceFolder.uri.fsPath, "build");
113 settings !== undefined &&
114 settings.getBoolean(SettingsKey.useCmakeTools)
116 // Compiling with CMake Tools
117 const cmakeBuildDir: string = await commands.executeCommand(
118 "cmake.buildDirectory"
122 buildDir = cmakeBuildDir;
126 const platform = cmakeGetPicoVar(
127 join(buildDir, "CMakeCache.txt"),
130 if (platform === null) {
134 if (platform === "rp2350-arm-s" || platform === "rp2350-riscv") {
142 export class GetTargetCommand extends CommandWithResult<string> {
147 async execute(): Promise<string> {
149 workspace.workspaceFolders === undefined ||
150 workspace.workspaceFolders.length === 0
155 const workspaceFolder = workspace.workspaceFolders?.[0];
157 const settings = Settings.getInstance();
158 let buildDir = join(workspaceFolder.uri.fsPath, "build");
160 settings !== undefined &&
161 settings.getBoolean(SettingsKey.useCmakeTools)
163 // Compiling with CMake Tools
164 const cmakeBuildDir: string = await commands.executeCommand(
165 "cmake.buildDirectory"
169 buildDir = cmakeBuildDir;
173 const platform = cmakeGetPicoVar(
174 join(buildDir, "CMakeCache.txt"),
177 if (platform === null) {
181 if (platform === "rp2350-arm-s") {
183 } else if (platform === "rp2350-riscv") {
184 return "rp2350-riscv";