Skip to content

Commit

Permalink
Add commands for executable paths
Browse files Browse the repository at this point in the history
Implement commands for executable paths. Unfortunately, command substitutions do not appear to be supported by terminal.integrated.env, so does not work currently

Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed Apr 16, 2024
1 parent ccb76a5 commit 2fdd778
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 46 deletions.
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getCMakePath",
"title": "Get CMake path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getNinjaPath",
"title": "Get ninja path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getSdkPath",
"title": "Get SDK path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getToolchainPath",
"title": "Get toolchain path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getCompilerPath",
"title": "Get compiler path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getGdbPath",
"title": "Get GDB path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.compileProject",
"title": "Compile Pico Project",
Expand Down Expand Up @@ -153,6 +189,16 @@
"default": "",
"description": "Path to Ninja executable [no spaces]"
},
"raspberry-pi-pico.sdkVersion": {
"type": "string",
"default": "",
"description": "SDK Version [no spaces]"
},
"raspberry-pi-pico.toolchainVersion": {
"type": "string",
"default": "",
"description": "Toolchain Version [no spaces]"
},
"raspberry-pi-pico.gitPath": {
"type": "string",
"default": "",
Expand Down
49 changes: 24 additions & 25 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,13 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"type": "cortex-debug",
"servertype": "openocd",\
{f'{server_path}: "{openocd_path}",' if openocd_path else ""}
"gdbPath": "{gdbPath}",
"gdbPath": "${{command:raspberry-pi-pico.getGdbPath}}",
"device": "RP2040",
"configFiles": [
"{debugger}",
"target/rp2040.cfg"
],
"svdFile": "{codeSdkPath(sdkVersion)}/src/rp2040/hardware_regs/rp2040.svd",
"svdFile": "${{command:raspberry-pi-pico.getSdkPath}}/src/rp2040/hardware_regs/rp2040.svd",
"runToEntryPoint": "main",
// Give restart the same functionality as runToEntryPoint - main
"postRestartCommands": [
Expand All @@ -791,9 +791,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"type": "cortex-debug",
"servertype": "external",
"gdbTarget": "localhost:3333",
"gdbPath": "{gdbPath}",
"gdbPath": "${{command:raspberry-pi-pico.getGdbPath}}",
"device": "RP2040",
"svdFile": "{codeSdkPath(sdkVersion)}/src/rp2040/hardware_regs/rp2040.svd",
"svdFile": "${{command:raspberry-pi-pico.getSdkPath}}/src/rp2040/hardware_regs/rp2040.svd",
"runToEntryPoint": "main",
// Give restart the same functionality as runToEntryPoint - main
"postRestartCommands": [
Expand All @@ -808,7 +808,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"cwd": "${{workspaceRoot}}",
"program": "${{command:raspberry-pi-pico.launchTargetPath}}",
"MIMode": "gdb",
"miDebuggerPath": "{gdbPath}",
"miDebuggerPath": "${{command:raspberry-pi-pico.getGdbPath}}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "{openocd_path if openocd_path else "openocd"}",
"debugServerArgs": "-f {debugger} -f target/rp2040.cfg -c \\"adapter speed 5000\\"",
Expand All @@ -819,7 +819,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"limit": 4
}},
"preLaunchTask": "Flash",
"svdPath": "{codeSdkPath(sdkVersion)}/src/rp2040/hardware_regs/rp2040.svd"
"svdPath": "${{command:raspberry-pi-pico.getSdkPath}}/src/rp2040/hardware_regs/rp2040.svd"
}},
]
}}
Expand Down Expand Up @@ -856,10 +856,10 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
{{
"name": "Pico",
"compilers": {{
"C": "{cPath}",
"CXX": "{cPath}"
"C": "${{command:raspberry-pi-pico.getCompilerPath}}",
"CXX": "${{command:raspberry-pi-pico.getCompilerPath}}"
}},
"toolchainFile": "{propertiesSdkPath(sdkVersion)}/cmake/preload/toolchains/pico_arm_gcc.cmake",
"toolchainFile": "${{command:raspberry-pi-pico.getSdkPath}}/cmake/preload/toolchains/pico_arm_gcc.cmake",
"environmentVariables": {{
"PATH": "${{command:raspberry-pi-pico.getEnvPath}};${{env:PATH}}"
}},
Expand Down Expand Up @@ -887,25 +887,27 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"cmake.automaticReconfigure": false,
"cmake.configureOnOpen": false,
"cmake.generator": "Ninja",
"cmake.cmakePath": "{cmakePath.replace(user_home, "${userHome}") if use_home_var else cmakePath}",
"cmake.cmakePath": "${{command:raspberry-pi-pico.getCMakePath}}",
"C_Cpp.debugShortcut": false,
"terminal.integrated.env.windows": {{
"PICO_SDK_PATH": "{propertiesSdkPath(sdkVersion, force_windows=True)}",
"PICO_TOOLCHAIN_PATH": "{propertiesToolchainPath(sdkVersion, force_windows=True)}",
"Path": "{propertiesToolchainPath(toolchainVersion, force_windows=True)}/bin;{os.path.dirname(cmakePath.replace(user_home, "${env:USERPROFILE}") if use_home_var else cmakePath)};{os.path.dirname(ninjaPath.replace(user_home, "${env:USERPROFILE}") if use_home_var else ninjaPath)};${{env:PATH}}"
"PICO_SDK_PATH": "${{command:raspberry-pi-pico.getSdkPath}}",
"PICO_TOOLCHAIN_PATH": "${{command:raspberry-pi-pico.getToolchainPath}}",
"Path": "${{command:raspberry-pi-pico.getEnvPath}};${{env:Path}}"
}},
"terminal.integrated.env.osx": {{
"PICO_SDK_PATH": "{propertiesSdkPath(sdkVersion, force_non_windows=True)}",
"PICO_TOOLCHAIN_PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}",
"PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}/bin:{os.path.dirname(cmakePath.replace(user_home, "${env:HOME}") if use_home_var else cmakePath)}:{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:${{env:PATH}}"
"PICO_SDK_PATH": "${{command:raspberry-pi-pico.getSdkPath}}",
"PICO_TOOLCHAIN_PATH": "${{command:raspberry-pi-pico.getToolchainPath}}",
"PATH": "${{command:raspberry-pi-pico.getEnvPath}}:${{env:PATH}}"
}},
"terminal.integrated.env.linux": {{
"PICO_SDK_PATH": "{propertiesSdkPath(sdkVersion, force_non_windows=True)}",
"PICO_TOOLCHAIN_PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}",
"PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}/bin:{os.path.dirname(cmakePath.replace(user_home, "${env:HOME}") if use_home_var else cmakePath)}:{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:${{env:PATH}}"
"PICO_SDK_PATH": "${{command:raspberry-pi-pico.getSdkPath}}",
"PICO_TOOLCHAIN_PATH": "${{command:raspberry-pi-pico.getToolchainPath}}",
"PATH": "${{command:raspberry-pi-pico.getEnvPath}}:${{env:PATH}}"
}},
"raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.sdkVersion": "{sdkVersion}",
"raspberry-pi-pico.toolchainVersion": "{toolchainVersion}",
"raspberry-pi-pico.cmakePath": "{cmakePath.replace(user_home, "${HOME}") if use_home_var else cmakePath}",
"raspberry-pi-pico.ninjaPath": "{ninjaPath.replace(user_home, "${HOME}") if use_home_var else ninjaPath}"'''

Expand All @@ -931,19 +933,16 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"tasks": [
{{
"label": "Compile Project",
"type": "process",
"type": "shell",
"isBuildCommand": true,
"command": "{ninjaPath.replace(user_home, "${userHome}") if use_home_var else ninjaPath}",
"command": "${{command:raspberry-pi-pico.getNinjaPath}}",
"args": ["-C", "${{workspaceFolder}}/build"],
"group": "build",
"presentation": {{
"reveal": "always",
"panel": "dedicated"
}},
"problemMatcher": "$gcc",
"windows": {{
"command": "{ninjaPath.replace(user_home, "${env:USERPROFILE}") if use_home_var else ninjaPath}.exe"
}}
"problemMatcher": "$gcc"
}},
{{
"label": "Flash",
Expand Down
178 changes: 176 additions & 2 deletions src/commands/getPaths.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { CommandWithResult } from "./command.mjs";
import { workspace } from "vscode";
import { getPythonPath, getPath } from "../utils/cmakeUtil.mjs";
import {
getPythonPath, getPath, getCMakePath, getNinjaPath
} from "../utils/cmakeUtil.mjs";
import Settings, { SettingsKey } from "../settings.mjs";
import { homedir } from "os";

export class GetPythonPathCommand
extends CommandWithResult<string> {
Expand All @@ -16,7 +20,8 @@ export class GetPythonPathCommand
return "";
}

const pythonPath = await getPythonPath();
const isWindows = process.platform === "win32";
const pythonPath = await getPythonPath(isWindows);

return pythonPath;
}
Expand All @@ -41,3 +46,172 @@ export class GetEnvPathCommand
return path;
}
}

export class GetCMakePathCommand
extends CommandWithResult<string> {
constructor() {
super("getCMakePath");
}

async execute(): Promise<string> {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const isWindows = process.platform === "win32";

Check warning on line 64 in src/commands/getPaths.mts

View workflow job for this annotation

GitHub Actions / build

'isWindows' is assigned a value but never used
const path = await getCMakePath();


return path;
}
}

export class GetNinjaPathCommand
extends CommandWithResult<string> {
constructor() {
super("getNinjaPath");
}

async execute(): Promise<string> {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const isWindows = process.platform === "win32";

Check warning on line 86 in src/commands/getPaths.mts

View workflow job for this annotation

GitHub Actions / build

'isWindows' is assigned a value but never used
const path = await getNinjaPath();


return path;
}
}

export class GetSdkPathCommand
extends CommandWithResult<string> {
constructor() {
super("getSdkPath");
}

execute(): string {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const settings = Settings.getInstance();
if (settings === undefined) {
return "";
}

const path = `${
homedir().replaceAll("\\", "/")
}/.pico-sdk/sdk/${
settings.getString(SettingsKey.sdkVersion)
}`;

return path;
}
}

export class GetToolchainPathCommand
extends CommandWithResult<string> {
constructor() {
super("getToolchainPath");
}

execute(): string {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const settings = Settings.getInstance();
if (settings === undefined) {
return "";
}

const path = `${
homedir().replaceAll("\\", "/")
}/.pico-sdk/toolchain/${
settings.getString(SettingsKey.toolchainVersion)
}`;

return path;
}
}

export class GetCompilerPathCommand
extends CommandWithResult<string> {
constructor() {
super("getCompilerPath");
}

execute(): string {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const settings = Settings.getInstance();
if (settings === undefined) {
return "";
}

const isWindows = process.platform === "win32";

const path = `${
homedir().replaceAll("\\", "/")
}/.pico-sdk/toolchain/${
settings.getString(SettingsKey.toolchainVersion)
}/bin/arm-none-eabi-gcc${isWindows ? ".exe" : ""}`;

return path;
}
}

export class GetGdbPathCommand
extends CommandWithResult<string> {
constructor() {
super("getGdbPath");
}

execute(): string {
if (
workspace.workspaceFolders === undefined ||
workspace.workspaceFolders.length === 0
) {
return "";
}

const settings = Settings.getInstance();
if (settings === undefined) {
return "";
}

const isWindows = process.platform === "win32";
const isMac = process.platform === "darwin";

if (!isMac && !isWindows) {
return "gdb";
}

const path = `${
homedir().replaceAll("\\", "/")
}/.pico-sdk/toolchain/${
settings.getString(SettingsKey.toolchainVersion)
}/bin/arm-none-eabi-gdb${isWindows ? ".exe" : ""}`;

return path;
}
}
Loading

0 comments on commit 2fdd778

Please sign in to comment.