Skip to content

Commit 9effa2f

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

File tree

6 files changed

+78
-75
lines changed

6 files changed

+78
-75
lines changed

src/commands/newProject.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { window, type Uri } from "vscode";
44
import { NewProjectPanel } from "../webview/newProjectPanel.mjs";
55
// eslint-disable-next-line max-len
66
import { NewMicroPythonProjectPanel } from "../webview/newMicroPythonProjectPanel.mjs";
7+
import { NewRustProjectPanel } from "../webview/newRustProjectPanel.mjs";
78
import { NewZephyrProjectPanel } from "../webview/newZephyrProjectPanel.mjs";
89

910
/**

src/utils/download.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { cloneRepository, initSubmodules, ensureGit } from "./gitUtil.mjs";
2323
import { HOME_VAR, SettingsKey } from "../settings.mjs";
2424
import Settings from "../settings.mjs";
2525
import which from "which";
26-
import { ProgressLocation, type Uri, window, workspace } from "vscode";
26+
import { ProgressLocation, Uri, window, workspace } from "vscode";
2727
import { fileURLToPath } from "url";
2828
import {
2929
type GithubReleaseAssetData,

src/utils/setupZephyr.mts

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import {
1818
downloadFileGot,
1919
} from "../utils/download.mjs";
2020
import Settings, { HOME_VAR } from "../settings.mjs";
21-
import { openOCDVersion } from "../webview/newProjectPanel.mjs";
2221
import findPython, { showPythonNotFoundError } from "../utils/pythonHelper.mjs";
2322
import { ensureGit } from "../utils/gitUtil.mjs";
24-
import { type VersionBundle } from "../utils/versionBundles.mjs";
23+
import VersionBundlesLoader from "./versionBundles.mjs";
24+
import { OPENOCD_VERSION } from "./sharedConstants.mjs";
2525

2626
const _logger = new Logger("zephyrSetup");
2727

@@ -48,10 +48,10 @@ manifest:
4848
`;
4949

5050
interface ZephyrSetupValue {
51-
versionBundle: VersionBundle | undefined;
5251
cmakeMode: number;
5352
cmakePath: string;
5453
cmakeVersion: string;
54+
extUri: Uri;
5555
}
5656

5757
interface ZephyrSetupOutputs {
@@ -90,7 +90,17 @@ export async function setupZephyr(
9090

9191
return;
9292
}
93+
_logger.info("Setting up Zephyr...");
9394

95+
const latestVb = await new VersionBundlesLoader(data.extUri).getLatest();
96+
if (latestVb === undefined) {
97+
_logger.error("Failed to get latest version bundles.");
98+
void window.showErrorMessage(
99+
"Failed to get latest version bundles. Cannot continue Zephyr setup."
100+
);
101+
102+
return;
103+
}
94104
const output: ZephyrSetupOutputs = { cmakeExecutable: "" };
95105

96106
let python3Path: string | undefined = "";
@@ -131,11 +141,7 @@ export async function setupZephyr(
131141

132142
// Handle CMake install
133143
switch (data.cmakeMode) {
134-
case 0:
135-
if (data.versionBundle !== undefined) {
136-
data.cmakeVersion = data.versionBundle.cmake;
137-
}
138-
// eslint-disable-next-line no-fallthrough
144+
case 4:
139145
case 2:
140146
installedSuccessfully = false;
141147
prog2LastState = 0;
@@ -215,7 +221,7 @@ export async function setupZephyr(
215221
message: "Failed",
216222
increment: 100,
217223
});
218-
void window.showErrorMessage("Unknown cmake selection.");
224+
void window.showErrorMessage("Unknown CMake version selected.");
219225

220226
return;
221227
}
@@ -227,13 +233,16 @@ export async function setupZephyr(
227233
},
228234
async progress2 => {
229235
if (
230-
await downloadAndInstallNinja("v1.12.1", (prog: GotProgress) => {
231-
const per = prog.percent * 100;
232-
progress2.report({
233-
increment: per - prog2LastState,
234-
});
235-
prog2LastState = per;
236-
})
236+
await downloadAndInstallNinja(
237+
latestVb[1].ninja,
238+
(prog: GotProgress) => {
239+
const per = prog.percent * 100;
240+
progress2.report({
241+
increment: per - prog2LastState,
242+
});
243+
prog2LastState = per;
244+
}
245+
)
237246
) {
238247
progress2.report({
239248
message: "Successfully downloaded and installed Ninja.",
@@ -259,13 +268,16 @@ export async function setupZephyr(
259268
},
260269
async progress2 => {
261270
if (
262-
await downloadAndInstallPicotool("2.1.1", (prog: GotProgress) => {
263-
const per = prog.percent * 100;
264-
progress2.report({
265-
increment: per - prog2LastState,
266-
});
267-
prog2LastState = per;
268-
})
271+
await downloadAndInstallPicotool(
272+
latestVb[1].picotool,
273+
(prog: GotProgress) => {
274+
const per = prog.percent * 100;
275+
progress2.report({
276+
increment: per - prog2LastState,
277+
});
278+
prog2LastState = per;
279+
}
280+
)
269281
) {
270282
progress2.report({
271283
message: "Successfully downloaded and installed Picotool.",
@@ -322,6 +334,7 @@ export async function setupZephyr(
322334
},
323335
async progress2 => {
324336
if (
337+
// TODO: integrate into extension system for github api caching
325338
await downloadAndInstallArchive(
326339
"https://github.com/oss-winget/oss-winget-storage/raw/" +
327340
"96ea1b934342f45628a488d3b50d0c37cf06012c/packages/dtc/" +
@@ -355,6 +368,7 @@ export async function setupZephyr(
355368
},
356369
async progress2 => {
357370
if (
371+
// TODO: integrate into extension system for github api caching
358372
await downloadAndInstallArchive(
359373
"https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/" +
360374
"gperf-3.0.1-bin.zip/download",
@@ -391,6 +405,7 @@ export async function setupZephyr(
391405
},
392406
async progress2 => {
393407
if (
408+
// TODO: integrate into extension system for github api caching
394409
await downloadAndInstallArchive(
395410
"https:///eternallybored.org/misc/wget/releases/" +
396411
"wget-1.21.4-win64.zip",
@@ -498,7 +513,7 @@ export async function setupZephyr(
498513
async progress2 => {
499514
if (
500515
await downloadAndInstallOpenOCD(
501-
openOCDVersion,
516+
OPENOCD_VERSION,
502517
(prog: GotProgress) => {
503518
const per = prog.percent * 100;
504519
progress2.report({
@@ -844,12 +859,13 @@ export async function setupZephyr(
844859
windowsHide: true,
845860
env: customEnv,
846861
});
847-
_logger.info("stdout: ", child.stdout.toString());
848-
_logger.info("stderr: ", child.stderr.toString());
862+
_logger.debug("stdout: ", child.stdout.toString());
863+
_logger.debug("stderr: ", child.stderr.toString());
864+
849865
if (child.status) {
850-
_logger.info("exit code: ", child.status);
866+
_logger.debug("exit code: ", child.status);
851867
if (child.status !== 0) {
852-
window.showErrorMessage(
868+
void window.showErrorMessage(
853869
"Error installing Zephyr SDK." + "Exiting Zephyr Setup."
854870
);
855871
}
@@ -873,7 +889,8 @@ export async function setupZephyr(
873889
);
874890

875891
if (installedSuccessfully) {
876-
window.showInformationMessage("Zephyr setup complete");
892+
// TODO: duplicate signaling
893+
void window.showInformationMessage("Zephyr setup complete");
877894
progress.report({
878895
message: "Zephyr setup complete.",
879896
increment: 100,

src/utils/versionBundles.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface VersionBundle {
1616
picotool: string;
1717
toolchain: string;
1818
riscvToolchain: string;
19-
modifiers: { [triple: string] : {[tool: string]: string}};
19+
modifiers: { [triple: string]: { [tool: string]: string } };
2020
}
2121

2222
export interface VersionBundles {
@@ -108,20 +108,20 @@ export default class VersionBundlesLoader {
108108
const platformDouble = `${process.platform}_${process.arch}`;
109109
if (modifiers[platformDouble] !== undefined) {
110110
chosenBundle.cmake =
111-
modifiers[platformDouble]["cmake"] ?? chosenBundle.cmake
111+
modifiers[platformDouble]["cmake"] ?? chosenBundle.cmake;
112112

113113
chosenBundle.ninja =
114-
modifiers[platformDouble]["ninja"] ?? chosenBundle.ninja
114+
modifiers[platformDouble]["ninja"] ?? chosenBundle.ninja;
115115

116116
chosenBundle.picotool =
117-
modifiers[platformDouble]["picotool"] ?? chosenBundle.picotool
117+
modifiers[platformDouble]["picotool"] ?? chosenBundle.picotool;
118118

119119
chosenBundle.toolchain =
120-
modifiers[platformDouble]["toolchain"] ?? chosenBundle.toolchain
120+
modifiers[platformDouble]["toolchain"] ?? chosenBundle.toolchain;
121121

122122
chosenBundle.riscvToolchain =
123123
modifiers[platformDouble]["riscvToolchain"] ??
124-
chosenBundle.riscvToolchain
124+
chosenBundle.riscvToolchain;
125125
}
126126
}
127127
}

src/webview/newZephyrProjectPanel.mts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import { PythonExtension } from "@vscode/python-extension";
2727
import { unknownErrorToString } from "../utils/errorHelper.mjs";
2828
import { buildZephyrWorkspacePath } from "../utils/download.mjs";
2929
import { setupZephyr } from "../utils/setupZephyr.mjs";
30-
import type { VersionBundle } from "../utils/versionBundles.mjs";
31-
import type VersionBundlesLoader from "../utils/versionBundles.mjs";
3230
import { getCmakeReleases } from "../utils/githubREST.mjs";
3331
import { getSystemCmakeVersion } from "../utils/cmakeUtil.mjs";
3432

@@ -142,8 +140,6 @@ export class NewZephyrProjectPanel {
142140

143141
private _projectRoot?: Uri;
144142
private _pythonExtensionApi?: PythonExtension;
145-
private _versionBundlesLoader?: VersionBundlesLoader;
146-
private _versionBundle: VersionBundle | undefined;
147143
private _systemCmakeVersion: string | undefined;
148144

149145
// Create settings.json file with correct subsitution for tools such as
@@ -254,7 +250,7 @@ export class NewZephyrProjectPanel {
254250
)
255251
.then(selected => {
256252
if (selected === "Reload Window") {
257-
commands.executeCommand("workbench.action.reloadWindow");
253+
void commands.executeCommand("workbench.action.reloadWindow");
258254
}
259255
});
260256

@@ -280,7 +276,6 @@ export class NewZephyrProjectPanel {
280276
return;
281277
}
282278

283-
// TODO: reload if it was import panel maybe in state
284279
NewZephyrProjectPanel.currentPanel = new NewZephyrProjectPanel(
285280
panel,
286281
settings,
@@ -345,23 +340,6 @@ export class NewZephyrProjectPanel {
345340
}
346341
}
347342
break;
348-
case "versionBundleAvailableTest":
349-
{
350-
// test if versionBundle for sdk version is available
351-
const versionBundle =
352-
await this._versionBundlesLoader?.getModuleVersion(
353-
message.value as string
354-
);
355-
// return result in message of command versionBundleAvailableTest
356-
await this._panel.webview.postMessage({
357-
command: "versionBundleAvailableTest",
358-
value: {
359-
result: versionBundle !== undefined,
360-
picotoolVersion: versionBundle?.picotool,
361-
},
362-
});
363-
}
364-
break;
365343
case "cancel":
366344
this.dispose();
367345
break;
@@ -445,6 +423,13 @@ export class NewZephyrProjectPanel {
445423
}
446424
}
447425

426+
/**
427+
* Convert the enum to the Zephyr board name
428+
*
429+
* @param e BoardType enum
430+
* @returns string Zephyr board name
431+
* @throws Error if unknown board type
432+
*/
448433
private enumToBoard(e: BoardType): string {
449434
switch (e) {
450435
case BoardType.pico:
@@ -456,7 +441,6 @@ export class NewZephyrProjectPanel {
456441
case BoardType.pico2W:
457442
return "rpi_pico2/rp2350a/m33/w";
458443
default:
459-
// TODO: maybe just return an empty string
460444
throw new Error(`Unknown Board Type: ${e as string}`);
461445
}
462446
}
@@ -501,7 +485,7 @@ export class NewZephyrProjectPanel {
501485
return;
502486
}
503487

504-
if (this._versionBundle === undefined && data.cmakeMode === 0) {
488+
if (data.cmakeMode === 0) {
505489
progress.report({
506490
message: "Failed",
507491
increment: 100,
@@ -513,10 +497,10 @@ export class NewZephyrProjectPanel {
513497

514498
// Setup Zephyr before doing anything else
515499
const zephyrSetupOutputs = await setupZephyr({
516-
versionBundle: this._versionBundle,
517500
cmakeMode: data.cmakeMode,
518501
cmakePath: data.cmakePath,
519502
cmakeVersion: data.cmakeVersion,
503+
extUri: this._extensionUri,
520504
});
521505

522506
if (zephyrSetupOutputs === null) {
@@ -992,11 +976,6 @@ export class NewZephyrProjectPanel {
992976
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg
993977
focus:ring-blue-500 focus:border-blue-500 p-2.5
994978
dark:bg-gray-700 dark:border-gray-600 dark:text-white">
995-
${
996-
this._versionBundle !== undefined
997-
? `<option value="default">Default bundle</option>`
998-
: ""
999-
}
1000979
${
1001980
this._systemCmakeVersion !== undefined
1002981
? `<option value="system">Use system version</option>`

web/zephyr/main.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var submitted = false;
128128
window.submitBtnClick = () => {
129129
// get all values of inputs
130130
const projectNameElement = document.getElementById("inp-project-name");
131-
// if is project import then the project name element will not be rendered and does not exist in the DOM
131+
132132
const projectName = projectNameElement.value;
133133
if (
134134
projectName !== undefined &&
@@ -235,17 +235,18 @@ var submitted = false;
235235
let cmakeVersion = null; // string | null
236236

237237
const cmakeModeSel = document.getElementById('cmake-mode');
238-
const selCmake = document.getElementById('sel-cmake'); // shown in "select" mode
239-
const cmakeFileInp = document.getElementById('cmake-path-executable'); // shown in "custom" mode
238+
const selCmake = document.getElementById('sel-cmake'); // shown in "select" mode
239+
const cmakeFileInp = document.getElementById('cmake-path-executable'); // shown in "custom" mode
240+
const latestCmakeVersion = document.getElementById('cmake-latest-label'); // get latest version
240241

241242
// Fallback to "latest" if the select isn't there for some reason
242243
const cmakeModeStr = (cmakeModeSel?.value || 'latest');
243244

244245
// Map string modes -> numeric API
245246
// 0 = default bundle, 1 = system, 2 = select version, 3 = custom path, 4 = latest
246247
switch (cmakeModeStr) {
247-
// should never happen, but just in case let the backend handle it
248-
case 'default': cmakeMode = 0; break;
248+
// default to latest
249+
case 'default': cmakeMode = 4; break;
249250
case 'system': cmakeMode = 1; break;
250251
case 'select': cmakeMode = 2; break;
251252
case 'custom': cmakeMode = 3; break;
@@ -261,7 +262,12 @@ var submitted = false;
261262
}
262263

263264
// Validate + collect per-mode extras
264-
if (cmakeMode === 2) {
265+
if (cmakeMode === 4) {
266+
if (!latestCmakeVersion) {
267+
268+
}
269+
cmakeVersion = latestCmakeVersion.textContent.trim();
270+
} else if (cmakeMode === 2) {
265271
// specific version chosen from dropdown
266272
if (!selCmake || !selCmake.value) {
267273
vscode.postMessage({
@@ -288,8 +294,8 @@ var submitted = false;
288294
cmakePath = files[0].name;
289295
}
290296

291-
// Final sanity check: numeric range 0..4
292-
if (cmakeMode === null || isNaN(cmakeMode) || cmakeMode < 0 || cmakeMode > 4) {
297+
// Final sanity check: numeric range 1..4
298+
if (cmakeMode === null || isNaN(cmakeMode) || cmakeMode < 1 || cmakeMode > 4) {
293299
console.debug('Invalid cmake version value: ' + cmakeMode);
294300
vscode.postMessage({
295301
command: CMD_ERROR,

0 commit comments

Comments
 (0)