Skip to content

Commit

Permalink
Fix cmake tools integration when switching boards
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Sep 24, 2024
1 parent c5164be commit ae017f6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
"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.getChip",
"title": "Get Chip",
Expand Down
5 changes: 2 additions & 3 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,9 @@ 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/{CMAKE_TOOLCHAIN_NAME}",
"environmentVariables": {{
"PATH": "${{command:raspberry-pi-pico.getEnvPath}};${{env:PATH}}"
}},
Expand Down
15 changes: 15 additions & 0 deletions src/commands/configureCmake.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import { window, workspace } from "vscode";
import { configureCmakeNinja } from "../utils/cmakeUtil.mjs";
import Settings, { SettingsKey } from "../settings.mjs";

export default class ConfigureCmakeCommand extends Command {
private _logger: Logger = new Logger("ConfigureCmakeCommand");
Expand All @@ -23,6 +24,20 @@ export default class ConfigureCmakeCommand extends Command {
return;
}

const settings = Settings.getInstance();

if (
settings !== undefined &&
settings.getBoolean(SettingsKey.useCmakeTools)
) {
void window.showErrorMessage(
"You must use the CMake Tools extension to configure your build. " +
"To use this extension instead, change the useCmakeTools setting."
);

return;
}

if (await configureCmakeNinja(workspaceFolder.uri)) {
void window.showInformationMessage("CMake has configured your build.");
} else {
Expand Down
38 changes: 38 additions & 0 deletions src/commands/getPaths.mts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,44 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
}
}

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

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

const workspaceFolder = workspace.workspaceFolders?.[0];

const selectedToolchainAndSDKVersions =
await cmakeGetSelectedToolchainAndSDKVersions(workspaceFolder.uri);
if (selectedToolchainAndSDKVersions === null) {
return "";
}
const toolchainVersion = selectedToolchainAndSDKVersions[1];

let triple = "arm-none-eabi";
if (toolchainVersion.includes("RISCV")) {
if (toolchainVersion.includes("COREV")) {
triple = "riscv32-corev-elf";
} else {
triple = "riscv32-unknown-elf";
}
}

return join(
buildToolchainPath(toolchainVersion), "bin",
triple + `-gcc${process.platform === "win32" ? ".exe" : ""}`
);
}
}

export class GetChipCommand extends CommandWithResult<string> {
constructor() {
super("getChip");
Expand Down
2 changes: 2 additions & 0 deletions src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
GetPythonPathCommand,
GetEnvPathCommand,
GetGDBPathCommand,
GetCompilerPathCommand,
GetChipCommand,
GetTargetCommand,
GetChipUppercaseCommand,
Expand Down Expand Up @@ -106,6 +107,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
new GetPythonPathCommand(),
new GetEnvPathCommand(),
new GetGDBPathCommand(),
new GetCompilerPathCommand(),
new GetChipCommand(),
new GetChipUppercaseCommand(),
new GetTargetCommand(),
Expand Down
19 changes: 10 additions & 9 deletions src/utils/cmakeUtil.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
return false;
}

if (settings.getBoolean(SettingsKey.useCmakeTools)) {
await window.showErrorMessage(
"You must use the CMake Tools extension to configure your build. " +
"To use this extension instead, change the useCmakeTools setting."
);

return false;
}

if (existsSync(join(folder.fsPath, "build", "CMakeCache.txt"))) {
// check if the build directory has been moved

Expand Down Expand Up @@ -158,6 +149,16 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
}
}

if (settings.getBoolean(SettingsKey.useCmakeTools)) {
// CMake Tools integration is enabled - skip configuration
Logger.info(
LoggerSource.cmake,
"Skipping CMake configuration, as useCmakeTools is set."
);

return false;
}

try {
// check if CMakeLists.txt exists in the root folder
await workspace.fs.stat(
Expand Down

0 comments on commit ae017f6

Please sign in to comment.