Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for looking into PICO_BOARD_HEADER_DIRS custom board header #123

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/commands/launchTargetPath.mts
shalxmva marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CommandWithResult } from "./command.mjs";
import { commands, window, workspace } from "vscode";
import { join } from "path";
import Settings, { SettingsKey } from "../settings.mjs";
import { cmakeGetPicoVar } from "../utils/cmakeUtil.mjs";

export default class LaunchTargetPathCommand extends CommandWithResult<string> {
constructor() {
Expand All @@ -27,8 +28,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {

// Extract the project name from the matched result
if (match && match[1]) {
const projectName = match[1].trim();

let projectName = match[1].trim();
if (matchBg && matchPoll) {
// For examples with both background and poll, let user pick which to run
const quickPickItems = ["Threadsafe Background", "Poll"];
Expand All @@ -45,6 +46,16 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
case quickPickItems[1]:
return projectName + "_poll";
}
}else{
if(workspace.workspaceFolders !== undefined) {
let cmakeCacheFile = workspace.workspaceFolders[0].uri.fsPath;
cmakeCacheFile = join(cmakeCacheFile,"build","CMakeCache.txt");

const value = cmakeGetPicoVar(cmakeCacheFile,"CMAKE_PROJECT_NAME");
if(value !== null){
projectName = value;
}
}
}

return projectName;
Expand Down
52 changes: 43 additions & 9 deletions src/commands/switchBoard.mts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this change - just a couple of whitespace issues which I'll fixup

Copy link
Author

@shalxmva shalxmva Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added support to that variable as a path list,
If you add spaces at the end of the value, single quote characters are added at start and at the end.
This change will make this feature more robust.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
cmakeGetSelectedToolchainAndSDKVersions,
cmakeUpdateBoard,
cmakeUpdateSDK,
cmakeGetPicoVar,
} from "../utils/cmakeUtil.mjs";
import { join } from "path";
import { compareLt } from "../utils/semverUtil.mjs";
Expand All @@ -32,20 +33,55 @@ export default class SwitchBoardCommand extends Command {
public static async askBoard(sdkVersion: string):
Promise<[string, boolean] | undefined> {
const quickPickItems: string[] = ["pico", "pico_w"];
const workspaceFolder = workspace.workspaceFolders?.[0];

if (!compareLt(sdkVersion, "2.0.0")) {
quickPickItems.push("pico2");
}

will-v-pi marked this conversation as resolved.
Show resolved Hide resolved
if (!compareLt(sdkVersion, "2.1.0")) {
quickPickItems.push("pico2_w");
}

const sdkPath = buildSDKPath(sdkVersion);
const boardHeaderDirList = [];

if(workspaceFolder !== undefined) {
const ws = workspaceFolder.uri.fsPath;
const cMakeCachePath = join(ws, "build","CMakeCache.txt");

const picoBoardHeaderDirs = cmakeGetPicoVar(
cMakeCachePath,
"PICO_BOARD_HEADER_DIRS");

if(picoBoardHeaderDirs){
boardHeaderDirList.push(picoBoardHeaderDirs);
}
}

readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach(
file => {
quickPickItems.push(file.split(".")[0]);
const sdkPath = buildSDKPath(sdkVersion);
const systemBoardHeaderDir =
join(sdkPath,"src", "boards", "include","boards");

boardHeaderDirList.push(systemBoardHeaderDir);

interface IBoardFile{
[key: string]: string;
};

const boardFiles:IBoardFile = {};

boardHeaderDirList.forEach(
path =>{
readdirSync(path).forEach(
file => {
const fullFilename = join(path, file);
if(fullFilename.endsWith(".h")) {
const boardName = file.split(".")[0];
boardFiles[boardName] = fullFilename;
quickPickItems.push(boardName);
}
}
)
}
);

Expand All @@ -58,11 +94,9 @@ export default class SwitchBoardCommand extends Command {

return board;
}

will-v-pi marked this conversation as resolved.
Show resolved Hide resolved
// Check that board doesn't have an RP2040 on it
const data = readFileSync(
join(sdkPath, "src", "boards", "include", "boards", `${board}.h`)
)
const data = readFileSync(boardFiles[board])

if (data.includes("rp2040")) {

Expand Down