Skip to content

Commit

Permalink
Merge pull request #91 from raspberrypi/cmaketools-fixup
Browse files Browse the repository at this point in the history
Cmaketools fixup
  • Loading branch information
paulober authored Sep 23, 2024
2 parents fb3793c + d07eb73 commit dd80351
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ This extension provides the following settings:
* `raspberry-pi-pico.gitPath`: Specify a custom path for Git.
* `raspberry-pi-pico.cmakeAutoConfigure`: Provide a GitHub personal access token (classic) with the `public_repo` scope. This token is used to check for available versions of the Pico SDK and other tools. Without it, the extension uses the unauthenticated GitHub API, which has a lower rate limit and may lead to restricted functionality if the limit is exceeded. The unauthenticated rate limit is per public IP address, so a token is more necessary if your IP is shared with many users.

## CMake Tools Extension Integration

For more complex projects, such as those with multiple executables or when the project name is defined as a variable, this extension can integrate with the CMake Tools extension to enhance CMake parsing. You can enable CMake Tools integration during project generation under the **Advanced Options**. Additionally, to manually enable it, adjust the following settings in your `settings.json`:

- `raspberry-pi-pico.cmakeAutoConfigure`: Set from `true` to `false`.
- `raspberry-pi-pico.useCmakeTools`: Set from `false` to `true`.

For optimal functionality, consider enabling:

- `cmake.configureOnEdit`: true
- `cmake.automaticReconfigure`: true
- `cmake.configureOnOpen`: true

When prompted, select the `Pico` kit in CMake Tools, and set your build and launch targets accordingly. Use CMake Tools for compilation, but continue using this extension for debugging, as CMake Tools debugging is not compatible with Pico.

## VS Code Profiles

If you work with multiple microcontroller toolchains, consider installing this extension into a [VS Code Profile](https://code.visualstudio.com/docs/editor/profiles) to avoid conflicts with other toolchains. Follow these steps:
Expand Down
19 changes: 11 additions & 8 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def ParseCommandLine():
parser.add_argument("-cupy", "--customPython", action='store_true', help="Custom python path used to execute the script.")
parser.add_argument("-openOCDVersion", "--openOCDVersion", help="OpenOCD version to use - defaults to 0", default=0)
parser.add_argument("-examLibs", "--exampleLibs", action='append', help="Include an examples library in the folder")
parser.add_argument("-ucmt", "--useCmakeTools", action='store_true', help="Enable CMake Tools extension integration")

return parser.parse_args()

Expand Down Expand Up @@ -765,7 +766,7 @@ def GenerateCMake(folder, params):


# Generates the requested project files, if any
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion):
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion, useCmakeTools):

oldCWD = os.getcwd()

Expand Down Expand Up @@ -929,9 +930,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"statusBarVisibility": "hidden"
}}
}},
"cmake.configureOnEdit": false,
"cmake.automaticReconfigure": false,
"cmake.configureOnOpen": false,
"cmake.configureOnEdit": {"true" if useCmakeTools else "false"},
"cmake.automaticReconfigure": {"true" if useCmakeTools else "false"},
"cmake.configureOnOpen": {"true" if useCmakeTools else "false"},
"cmake.generator": "Ninja",
"cmake.cmakePath": "{cmakePath.replace(user_home, "${userHome}") if use_home_var else cmakePath}",
"C_Cpp.debugShortcut": false,
Expand Down Expand Up @@ -965,8 +966,8 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:\
${{env:PATH}}"
}},
"raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakeAutoConfigure": {"false" if useCmakeTools else "true"},
"raspberry-pi-pico.useCmakeTools": {"true" if useCmakeTools else "false"},
"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 Down Expand Up @@ -1236,7 +1237,8 @@ def DoEverything(parent, params):
params["ninjaPath"],
params["cmakePath"],
params["customPython"],
params["openOCDVersion"])
params["openOCDVersion"],
params['useCmakeTools'])

if params['wantBuild']:
os.system(makeCmd)
Expand Down Expand Up @@ -1360,7 +1362,8 @@ def DoEverything(parent, params):
'cmakePath' : args.cmakePath,
'customPython' : args.customPython,
'openOCDVersion': args.openOCDVersion,
'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else []
'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else [],
'useCmakeTools' : args.useCmakeTools
}

DoEverything(None, params)
Expand Down
38 changes: 28 additions & 10 deletions src/webview/newProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface ImportProjectMessageValue {

// debugger
debugger: number;
useCmakeTools: boolean;
}

interface SubmitExampleMessageValue extends ImportProjectMessageValue {
Expand Down Expand Up @@ -268,6 +269,7 @@ interface ImportProjectOptions {
ninjaExecutable: string;
cmakeExecutable: string;
debugger: Debugger;
useCmakeTools: boolean;
}

interface NewExampleBasedProjectOptions extends ImportProjectOptions {
Expand Down Expand Up @@ -1131,6 +1133,7 @@ export class NewProjectPanel {
},
ninjaExecutable,
cmakeExecutable,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand All @@ -1155,6 +1158,7 @@ export class NewProjectPanel {
},
ninjaExecutable,
cmakeExecutable,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand All @@ -1176,6 +1180,7 @@ export class NewProjectPanel {
ninjaExecutable,
cmakeExecutable,
debugger: data.debugger === 1 ? Debugger.swd : Debugger.debugProbe,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand Down Expand Up @@ -2004,18 +2009,30 @@ export class NewProjectPanel {
</div>`
: ""
}
<div id="section-debugger" class="snap-start mt-10">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<input checked id="debugger-radio-debug-probe" type="radio" value="0" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
<label for="debugger-radio-debug-probe" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">DebugProbe (CMSIS-DAP) [Default]</label>
</div>
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<input id="debugger-radio-swd" type="radio" value="1" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
<label for="debugger-radio-swd" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">SWD (Pi host, on Pi 5 it requires Linux Kernel >= 6.6.47)</label>
<div class="grid gap-6 grid-cols-3 mt-10">
<div id="section-debugger" class="snap-start col-span-2">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<input checked id="debugger-radio-debug-probe" type="radio" value="0" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
<label for="debugger-radio-debug-probe" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">DebugProbe (CMSIS-DAP) [Default]</label>
</div>
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<input id="debugger-radio-swd" type="radio" value="1" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
<label for="debugger-radio-swd" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">SWD (Pi host, on Pi 5 it requires Linux Kernel >= 6.6.47)</label>
</div>
</div>
</div>
<div id="section-extension-integration" class="snap-end advanced-option" hidden>
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">CMake Tools</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<input id="use-cmake-tools-cb" type="checkbox" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
<label for="use-cmake-tools-cb" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">Enable CMake-Tools extension integration</label>
</div>
</div>
</div>
</div>
<div class="bottom-3 mt-8 mb-12 w-full flex justify-end">
<button id="btn-advanced-options" class="focus:outline-none bg-transparent ring-2 focus:ring-4 ring-yellow-400 dark:ring-yellow-700 font-medium rounded-lg text-lg px-4 py-2 mr-4 hover:bg-yellow-500 dark:hover:bg-yellow-700 focus:ring-yellow-600 dark:focus:ring-yellow-800">Show Advanced Options</button>
Expand Down Expand Up @@ -2209,6 +2226,7 @@ export class NewProjectPanel {
`"${options.ninjaExecutable}"`,
"--cmakePath",
`"${options.cmakeExecutable}"`,
options.useCmakeTools ? "-ucmt" : "",

// set custom python executable path used flag if python executable is not in PATH
pythonExe.includes("/") ? "-cupy" : "",
Expand Down
10 changes: 7 additions & 3 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ var exampleSupportedBoards = [];
submitted = false;
return;
}
const useCmakeTools = document.getElementById('use-cmake-tools-cb').checked;

if (doProjectImport) {
vscode.postMessage({
Expand All @@ -293,7 +294,8 @@ var exampleSupportedBoards = [];
pythonPath: pythonPath,

// debugger selection
debugger: 0
debugger: 0,
useCmakeTools
}
});
return;
Expand All @@ -319,7 +321,8 @@ var exampleSupportedBoards = [];
pythonPath: pythonPath,

// debugger selection
debugger: debuggerSelection
debugger: debuggerSelection,
useCmakeTools
}
});
return;
Expand Down Expand Up @@ -410,7 +413,8 @@ var exampleSupportedBoards = [];
cppExceptions: cppExceptionsCodeGen,

// debugger selection
debugger: debuggerSelection
debugger: debuggerSelection,
useCmakeTools
}
});
}
Expand Down
10 changes: 9 additions & 1 deletion web/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class State {
cppExceptionsCodeGen;
selRiscv;
debuggerSelection;
useCMakeTools;

// special ui only state
uiShowAdvancedOptions;
Expand Down Expand Up @@ -157,12 +158,16 @@ function restoreState(state) {
document.getElementById('pico-wireless-radio-background').checked = state.picoWirelessSelection == 3;
}
// instead of setting debug-probe if selection is undefined or 0,
// first check so the default can be controlled in the html
// first check so the default can be controlled in the html
if (state.debuggerSelection !== undefined) {
document.getElementById('debugger-radio-debug-probe').checked = state.debuggerSelection == 0;
document.getElementById('debugger-radio-swd').checked = state.debuggerSelection == 1;
}

if (state.useCMakeTools !== undefined) {
document.getElementById('use-cmake-tools-cb').checked = state.useCMakeTools;
}

// instead of setting ninja-radio-default-version if selection is undefined or 0,
// first check so the default can be controlled in the html
if (state.ninjaMode !== undefined) {
Expand Down Expand Up @@ -444,6 +449,9 @@ function setupStateSystem(vscode) {
case "sel-riscv":
state.selRiscv = checkbox.checked;
break;
case "use-cmake-tools-cb":
state.useCMakeTools = checkbox.checked;
break;
}

vscode.setState(state);
Expand Down

0 comments on commit dd80351

Please sign in to comment.