From 5bdf59cd4a76cdad2368fdb559f3535991d9387b Mon Sep 17 00:00:00 2001 From: Shalx Date: Sun, 10 Nov 2024 14:36:26 -0600 Subject: [PATCH] Add support for looking into PICO_BOARD_HEADER_DIRS custom board header files Add Use CMAKE_PROJECT_NAME from CMakeCache.txt when getting the project name --- src/commands/launchTargetPath.mts | 15 ++++++++-- src/commands/switchBoard.mts | 50 ++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/commands/launchTargetPath.mts b/src/commands/launchTargetPath.mts index 69951ba..7a4419c 100644 --- a/src/commands/launchTargetPath.mts +++ b/src/commands/launchTargetPath.mts @@ -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 { constructor() { @@ -27,8 +28,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult { // 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"]; @@ -45,6 +46,16 @@ export default class LaunchTargetPathCommand extends CommandWithResult { 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; diff --git a/src/commands/switchBoard.mts b/src/commands/switchBoard.mts index 717805d..a0a9a2b 100644 --- a/src/commands/switchBoard.mts +++ b/src/commands/switchBoard.mts @@ -11,6 +11,7 @@ import { cmakeGetSelectedToolchainAndSDKVersions, cmakeUpdateBoard, cmakeUpdateSDK, + cmakeGetPicoVar, } from "../utils/cmakeUtil.mjs"; import { join } from "path"; import { compareLtMajor } from "../utils/semverUtil.mjs"; @@ -32,16 +33,51 @@ 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 (!compareLtMajor(sdkVersion, "2.0.0")) { quickPickItems.push("pico2"); } - const sdkPath = buildSDKPath(sdkVersion); + const boardHeaderDirList = []; + + if(workspaceFolder !== undefined) { + const ws = workspaceFolder.uri.fsPath; + const cMakeCachePath = join(ws, "build","CMakeCache.txt"); - readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach( - file => { - quickPickItems.push(file.split(".")[0]); + const picoBoardHeaderDirs = cmakeGetPicoVar( + cMakeCachePath, + "PICO_BOARD_HEADER_DIRS"); + + if(picoBoardHeaderDirs){ + boardHeaderDirList.push(picoBoardHeaderDirs); + } + } + + 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); + } + } + ) } ); @@ -54,11 +90,9 @@ export default class SwitchBoardCommand extends Command { return board; } - + // 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")) {