Skip to content

Commit ae0b674

Browse files
committed
Fix zephyr integration (part 3)
Signed-off-by: paulober <[email protected]>
1 parent 9effa2f commit ae0b674

File tree

7 files changed

+846
-765
lines changed

7 files changed

+846
-765
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"activationEvents": [
6767
"workspaceContains:./pico_sdk_import.cmake",
6868
"workspaceContains:./.pico-rs",
69+
"workspaceContains:./prj.conf",
6970
"onWebviewPanel:newPicoProject",
7071
"onWebviewPanel:newPicoMicroPythonProject"
7172
],

src/commands/getPaths.mts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CommandWithResult } from "./command.mjs";
22
import { commands, type Uri, window, workspace } from "vscode";
3-
import { type ExecOptions, exec, spawnSync } from "child_process";
43
import {
54
getPythonPath,
65
getPath,
@@ -29,9 +28,6 @@ import { getSupportedToolchains } from "../utils/toolchainUtil.mjs";
2928
import Logger from "../logger.mjs";
3029
import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs";
3130
import { OPENOCD_VERSION } from "../utils/sharedConstants.mjs";
32-
import findPython, { showPythonNotFoundError } from "../utils/pythonHelper.mjs";
33-
import { ensureGit } from "../utils/gitUtil.mjs";
34-
import { openOCDVersion } from "../webview/newProjectPanel.mjs";
3531
import { setupZephyr } from "../utils/setupZephyr.mjs";
3632

3733
export class GetPythonPathCommand extends CommandWithResult<string> {
@@ -572,27 +568,3 @@ export class GetZephyrWorkspacePathCommand extends CommandWithResult<
572568
return result;
573569
}
574570
}
575-
576-
export class SetupZephyrCommand extends CommandWithResult<string | undefined> {
577-
private running: boolean = false;
578-
579-
public static readonly id = "setupZephyr";
580-
581-
constructor() {
582-
super(SetupZephyrCommand.id);
583-
}
584-
585-
private readonly _logger: Logger = new Logger("SetupZephyr");
586-
587-
async execute(): Promise<string | undefined> {
588-
if (this.running) {
589-
return undefined;
590-
}
591-
592-
this.running = true;
593-
const result = setupZephyr();
594-
this.running = false;
595-
596-
return result;
597-
}
598-
}

src/extension.mts

Lines changed: 55 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import {
5050
GetPicotoolPathCommand,
5151
GetOpenOCDRootCommand,
5252
GetSVDPathCommand,
53-
SetupZephyrCommand,
5453
GetWestPathCommand,
5554
GetZephyrWorkspacePathCommand,
5655
} from "./commands/getPaths.mjs";
@@ -104,6 +103,7 @@ import { cmakeToolsForcePicoKit } from "./utils/cmakeToolsUtil.mjs";
104103
import { NewRustProjectPanel } from "./webview/newRustProjectPanel.mjs";
105104
import { OPENOCD_VERSION } from "./utils/sharedConstants.mjs";
106105
import VersionBundlesLoader from "./utils/versionBundles.mjs";
106+
import { setupZephyr } from "./utils/setupZephyr.mjs";
107107

108108
export async function activate(context: ExtensionContext): Promise<void> {
109109
Logger.info(LoggerSource.extension, "Extension activation triggered");
@@ -145,7 +145,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
145145
new GetSVDPathCommand(context.extensionUri),
146146
new GetWestPathCommand(),
147147
new GetZephyrWorkspacePathCommand(),
148-
new SetupZephyrCommand(),
149148
new NewZephyrProjectCommand(),
150149
new CompileProjectCommand(),
151150
new RunProjectCommand(),
@@ -262,63 +261,68 @@ export async function activate(context: ExtensionContext): Promise<void> {
262261
return;
263262
}
264263

265-
// Set Pico Zephyr Project false by default
266-
await commands.executeCommand(
267-
"setContext",
268-
ContextKeys.isPicoZephyrProject,
269-
false
270-
);
271-
272-
// Check for pico_zephyr in CMakeLists.txt
273-
if (
274-
readFileSync(cmakeListsFilePath).toString("utf-8").includes("pico_zephyr")
275-
) {
276-
Logger.info(LoggerSource.extension, "Pico Zephyr Project");
264+
// Set Pico Zephyr Project false by default
277265
await commands.executeCommand(
278266
"setContext",
279267
ContextKeys.isPicoZephyrProject,
280-
true
268+
false
281269
);
282270

283-
// Update the board info if it can be found in tasks.json
284-
const tasksJsonFilePath = join(
285-
workspaceFolder.uri.fsPath,
286-
".vscode",
287-
"tasks.json"
288-
);
271+
// Check for pico_zephyr in CMakeLists.txt
272+
if (
273+
readFileSync(cmakeListsFilePath).toString("utf-8").includes("pico_zephyr")
274+
) {
275+
Logger.info(LoggerSource.extension, "Project is of type: Zephyr");
276+
await commands.executeCommand(
277+
"setContext",
278+
ContextKeys.isPicoZephyrProject,
279+
true
280+
);
289281

290-
// Update UI with board description
291-
const board = findZephyrBoardInTasksJson(tasksJsonFilePath);
292-
293-
if (board !== undefined) {
294-
if (board === "rpi_pico2/rp2350a/m33/w") {
295-
ui.updateBoard("Pico 2W");
296-
} else if (board === "rpi_pico2/rp2350a/m33") {
297-
ui.updateBoard("Pico 2");
298-
} else if (board === "rpi_pico/rp2040/w") {
299-
ui.updateBoard("Pico W");
300-
} else if (board.includes("rpi_pico")) {
301-
ui.updateBoard("Pico");
302-
} else {
303-
ui.updateBoard("Other");
282+
// TODO: !!!!!!!!! IMPORTANT !!!!!!!!!
283+
// TODO: make sure zephy dependencies are installed
284+
285+
ui.showStatusBarItems(false, true);
286+
287+
// Update the board info if it can be found in tasks.json
288+
const tasksJsonFilePath = join(
289+
workspaceFolder.uri.fsPath,
290+
".vscode",
291+
"tasks.json"
292+
);
293+
294+
// Update UI with board description
295+
const board = findZephyrBoardInTasksJson(tasksJsonFilePath);
296+
297+
if (board !== undefined) {
298+
if (board === "rpi_pico2/rp2350a/m33/w") {
299+
ui.updateBoard("Pico 2W");
300+
} else if (board === "rpi_pico2/rp2350a/m33") {
301+
ui.updateBoard("Pico 2");
302+
} else if (board === "rpi_pico/rp2040/w") {
303+
ui.updateBoard("Pico W");
304+
} else if (board.includes("rpi_pico")) {
305+
ui.updateBoard("Pico");
306+
} else {
307+
ui.updateBoard("Other");
308+
}
304309
}
305310
}
306-
}
307-
// check for pico_sdk_init() in CMakeLists.txt
308-
else if (
309-
!readFileSync(cmakeListsFilePath)
310-
.toString("utf-8")
311-
.includes("pico_sdk_init()")
312-
) {
313-
Logger.warn(
314-
LoggerSource.extension,
315-
"No pico_sdk_init() in CMakeLists.txt found."
316-
);
317-
await commands.executeCommand(
318-
"setContext",
319-
ContextKeys.isPicoProject,
320-
false
321-
);
311+
// check for pico_sdk_init() in CMakeLists.txt
312+
else if (
313+
!readFileSync(cmakeListsFilePath)
314+
.toString("utf-8")
315+
.includes("pico_sdk_init()")
316+
) {
317+
Logger.warn(
318+
LoggerSource.extension,
319+
"No pico_sdk_init() in CMakeLists.txt found."
320+
);
321+
await commands.executeCommand(
322+
"setContext",
323+
ContextKeys.isPicoProject,
324+
false
325+
);
322326

323327
return;
324328
}
@@ -870,108 +874,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
870874
return;
871875
}
872876

873-
/*
874-
const pythonPath = settings.getString(SettingsKey.python3Path);
875-
if (pythonPath && pythonPath.includes("/.pico-sdk/python")) {
876-
// check if python path exists
877-
if (!existsSync(pythonPath.replace(HOME_VAR, homedir()))) {
878-
Logger.warn(
879-
LoggerSource.extension,
880-
"Python path in settings does not exist.",
881-
"Installing Python3 to default path."
882-
);
883-
const pythonVersion = /\/\.pico-sdk\/python\/([.0-9]+)\//.exec(
884-
pythonPath
885-
)?.[1];
886-
if (pythonVersion === undefined) {
887-
Logger.error(
888-
LoggerSource.extension,
889-
"Failed to get Python version from path."
890-
);
891-
await commands.executeCommand(
892-
"setContext",
893-
ContextKeys.isPicoProject,
894-
false
895-
);
896-
897-
return;
898-
}
899-
900-
let result: string | undefined;
901-
await window.withProgress(
902-
{
903-
location: ProgressLocation.Notification,
904-
title:
905-
"Downloading and installing Python. This may take a long while...",
906-
cancellable: false,
907-
},
908-
async progress => {
909-
if (process.platform === "win32") {
910-
const versionBundle = await new VersionBundlesLoader(
911-
context.extensionUri
912-
).getPythonWindowsAmd64Url(pythonVersion);
913-
914-
if (versionBundle === undefined) {
915-
Logger.error(
916-
LoggerSource.extension,
917-
"Failed to get Python download url from version bundle."
918-
);
919-
await commands.executeCommand(
920-
"setContext",
921-
ContextKeys.isPicoProject,
922-
false
923-
);
924-
925-
return;
926-
}
927-
928-
// ! because data.pythonMode === 0 => versionBundle !== undefined
929-
result = await downloadEmbedPython(versionBundle);
930-
} else if (process.platform === "darwin") {
931-
const result1 = await setupPyenv();
932-
if (!result1) {
933-
progress.report({
934-
increment: 100,
935-
});
936-
937-
return;
938-
}
939-
const result2 = await pyenvInstallPython(pythonVersion);
940-
941-
if (result2 !== null) {
942-
result = result2;
943-
}
944-
} else {
945-
Logger.info(
946-
LoggerSource.extension,
947-
"Automatic Python installation is only",
948-
"supported on Windows and macOS."
949-
);
950-
951-
await window.showErrorMessage(
952-
"Automatic Python installation is only " +
953-
"supported on Windows and macOS."
954-
);
955-
}
956-
progress.report({
957-
increment: 100,
958-
});
959-
}
960-
);
961-
962-
if (result === undefined) {
963-
Logger.error(LoggerSource.extension, "Failed to install Python3.");
964-
await commands.executeCommand(
965-
"setContext",
966-
ContextKeys.isPicoProject,
967-
false
968-
);
969-
970-
return;
971-
}
972-
}
973-
}*/
974-
975877
ui.showStatusBarItems();
976878
ui.updateSDKVersion(selectedToolchainAndSDKVersions[0]);
977879

src/logger.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export enum LoggerSource {
4444
vscodeConfigUtil = "vscodeConfigUtil",
4545
rustUtil = "rustUtil",
4646
projectRust = "projectRust",
47+
zephyrSetup = "setupZephyr",
4748
}
4849

4950
/**

src/ui.mts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const STATUS_BAR_ITEMS: {
1717
command: string;
1818
tooltip: string;
1919
rustSupport: boolean;
20+
zephyrSupport: boolean;
2021
};
2122
} = {
2223
[StatusBarItemKey.compile]: {
@@ -25,26 +26,30 @@ const STATUS_BAR_ITEMS: {
2526
command: "raspberry-pi-pico.compileProject",
2627
tooltip: "Compile Project",
2728
rustSupport: true,
29+
zephyrSupport: true,
2830
},
2931
[StatusBarItemKey.run]: {
3032
// alt. "$(gear) Compile"
3133
text: "$(run) Run",
3234
command: "raspberry-pi-pico.runProject",
3335
tooltip: "Run Project",
3436
rustSupport: true,
37+
zephyrSupport: true,
3538
},
3639
[StatusBarItemKey.picoSDKQuickPick]: {
3740
text: "Pico SDK: <version>",
3841
command: "raspberry-pi-pico.switchSDK",
3942
tooltip: "Select Pico SDK",
4043
rustSupport: false,
44+
zephyrSupport: false,
4145
},
4246
[StatusBarItemKey.picoBoardQuickPick]: {
4347
text: "Board: <board>",
4448
rustText: "Chip: <chip>",
4549
command: "raspberry-pi-pico.switchBoard",
4650
tooltip: "Select Chip",
4751
rustSupport: true,
52+
zephyrSupport: true,
4853
},
4954
};
5055

@@ -69,9 +74,15 @@ export default class UI {
6974
});
7075
}
7176

72-
public showStatusBarItems(isRustProject = false): void {
77+
public showStatusBarItems(
78+
isRustProject = false,
79+
isZephyrProject = false
80+
): void {
7381
Object.values(this._items)
7482
.filter(item => !isRustProject || STATUS_BAR_ITEMS[item.id].rustSupport)
83+
.filter(
84+
item => !isZephyrProject || STATUS_BAR_ITEMS[item.id].zephyrSupport
85+
)
7586
.forEach(item => item.show());
7687
}
7788

0 commit comments

Comments
 (0)