Skip to content

Commit

Permalink
Added getPicotool command
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <44974737+paulober@users.noreply.github.com>
  • Loading branch information
paulober committed Sep 12, 2024
1 parent cb61b8b commit bdbe0d1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspbery-pi-pico.getPicotoolPath",
"title": "Get Picotool path",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.compileProject",
"title": "Compile Pico Project",
Expand Down
50 changes: 43 additions & 7 deletions src/commands/getPaths.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import {
cmakeGetPicoVar,
} from "../utils/cmakeUtil.mjs";
import { join } from "path";
import { buildToolchainPath } from "../utils/download.mjs";
import {
buildPicotoolPath,
buildToolchainPath,
downloadAndInstallPicotool,
} from "../utils/download.mjs";
import Settings, { SettingsKey } from "../settings.mjs";
import which from "which";
import { execSync } from "child_process";
import { getPicotoolReleases } from "../utils/githubREST.mjs";

export class GetPythonPathCommand extends CommandWithResult<string> {
constructor() {
Expand Down Expand Up @@ -66,9 +71,7 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
const workspaceFolder = workspace.workspaceFolders?.[0];

const selectedToolchainAndSDKVersions =
await cmakeGetSelectedToolchainAndSDKVersions(
workspaceFolder.uri
);
await cmakeGetSelectedToolchainAndSDKVersions(workspaceFolder.uri);
if (selectedToolchainAndSDKVersions === null) {
return "";
}
Expand All @@ -87,9 +90,9 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
if (gdbPath !== null) {
// Test if system gdb supports arm_any architecture - throws an error if it's not available
try {
execSync(
`"${gdbPath}" --batch -ex "set arch arm_any"`, {stdio: 'pipe'}
);
execSync(`"${gdbPath}" --batch -ex "set arch arm_any"`, {
stdio: "pipe",
});

return "gdb";
} catch {
Expand Down Expand Up @@ -216,3 +219,36 @@ export class GetTargetCommand extends CommandWithResult<string> {
}
}
}

export class GetPicotoolPathCommand extends CommandWithResult<string> {
constructor() {
super("getPicotoolPath");
}

async execute(): Promise<string> {
// get latest release
const picotoolReleases = await getPicotoolReleases();

if (picotoolReleases === null) {
return "";
}

// it is sorted latest to oldest
const picotoolVersion = picotoolReleases[0];

// check if it is installed if not install it
const result = await downloadAndInstallPicotool(picotoolVersion);

if (result === null || !result) {
return "";
}

// TODO: maybe move "picotool" into buildPath or install it so the files
// are in root of buildPath
return join(
buildPicotoolPath(picotoolVersion),
"picotool",
process.platform === "win32" ? "picotool.exe" : "picotool"
);
}
}
2 changes: 2 additions & 0 deletions src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
GetChipCommand,
GetTargetCommand,
GetChipUppercaseCommand,
GetPicotoolPathCommand,
} from "./commands/getPaths.mjs";
import {
downloadAndInstallCmake,
Expand Down Expand Up @@ -104,6 +105,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
new GetChipCommand(),
new GetChipUppercaseCommand(),
new GetTargetCommand(),
new GetPicotoolPathCommand(),
new CompileProjectCommand(),
new RunProjectCommand(),
new FlashProjectSWDCommand(),
Expand Down

0 comments on commit bdbe0d1

Please sign in to comment.