Skip to content

Commit 4d10bf7

Browse files
committed
Fix integration of zephyr (part 1)
Signed-off-by: paulober <[email protected]>
1 parent 3978c84 commit 4d10bf7

File tree

3 files changed

+189
-163
lines changed

3 files changed

+189
-163
lines changed

src/commands/switchBoardZephyr.mts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, PathOrFileDescriptor, readFileSync } from "fs";
1+
import { existsSync, type PathOrFileDescriptor, readFileSync } from "fs";
22
import { join } from "path";
33
import { join as joinPosix } from "path/posix";
44
import { window, workspace, Uri } from "vscode";
@@ -14,12 +14,19 @@ enum BoardNames {
1414
pico2W = "Pico 2W",
1515
}
1616

17+
interface TasksJson {
18+
tasks: Array<{
19+
label: string;
20+
args: string[];
21+
}>;
22+
}
23+
1724
export function findZephyrBoardInTasksJson(
1825
tasksJsonFilePath: PathOrFileDescriptor
1926
): string | undefined {
20-
const tasksJson: any = JSON.parse(
27+
const tasksJson = JSON.parse(
2128
readFileSync(tasksJsonFilePath).toString("utf-8")
22-
);
29+
) as TasksJson;
2330

2431
// Check it has a tasks object with
2532
if (tasksJson.tasks === undefined || !Array.isArray(tasksJson.tasks)) {
@@ -168,7 +175,7 @@ export default class SwitchZephyrBoardCommand extends Command {
168175
const jsonString = (
169176
await workspace.fs.readFile(Uri.file(taskJsonFile))
170177
).toString();
171-
const tasksJson: any = JSON.parse(jsonString);
178+
const tasksJson = JSON.parse(jsonString) as TasksJson;
172179

173180
// Check it has a tasks object with
174181
if (tasksJson.tasks === undefined || !Array.isArray(tasksJson.tasks)) {
@@ -195,7 +202,7 @@ export default class SwitchZephyrBoardCommand extends Command {
195202
return;
196203
}
197204

198-
let args: string[] = tasksJson.tasks[compileIndex].args;
205+
const args: string[] = tasksJson.tasks[compileIndex].args;
199206

200207
if (args === undefined || !Array.isArray(args)) {
201208
window.showErrorMessage(

src/utils/setupZephyr.mts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export async function setupZephyr(
9191
return;
9292
}
9393

94-
let output: ZephyrSetupOutputs = { cmakeExecutable: "" };
94+
const output: ZephyrSetupOutputs = { cmakeExecutable: "" };
9595

96-
let python3Path = "";
96+
let python3Path: string | undefined = "";
9797
let isWindows = false;
9898
await window.withProgress(
9999
{
@@ -524,7 +524,7 @@ export async function setupZephyr(
524524
}
525525
);
526526

527-
const pythonExe = python3Path.replace(
527+
const pythonExe = python3Path?.replace(
528528
HOME_VAR,
529529
homedir().replaceAll("\\", "/")
530530
);
@@ -827,46 +827,49 @@ export async function setupZephyr(
827827
title: "Installing Zephyr SDK",
828828
cancellable: false,
829829
},
830-
async progress2 => {
831-
const westInstallSDKCommand: string = [
832-
westExe,
833-
"sdk install -t arm-zephyr-eabi",
834-
`-b ${zephyrWorkspaceDirectory}`,
835-
].join(" ");
830+
async progress2 =>
831+
new Promise<void>(resolve => {
832+
const westInstallSDKCommand: string = [
833+
westExe,
834+
"sdk install -t arm-zephyr-eabi",
835+
`-b ${zephyrWorkspaceDirectory}`,
836+
].join(" ");
837+
838+
// This has to be a spawn due to the way the underlying SDK command calls
839+
// subprocess and needs to inherit the Path variables set in customEnv
840+
_logger.info("Installing Zephyr SDK");
841+
const child = spawnSync(westInstallSDKCommand, {
842+
shell: true,
843+
cwd: zephyrWorkspaceDirectory,
844+
windowsHide: true,
845+
env: customEnv,
846+
});
847+
_logger.info("stdout: ", child.stdout.toString());
848+
_logger.info("stderr: ", child.stderr.toString());
849+
if (child.status) {
850+
_logger.info("exit code: ", child.status);
851+
if (child.status !== 0) {
852+
window.showErrorMessage(
853+
"Error installing Zephyr SDK." + "Exiting Zephyr Setup."
854+
);
855+
}
836856

837-
// This has to be a spawn due to the way the underlying SDK command calls
838-
// subprocess and needs to inherit the Path variables set in customEnv
839-
_logger.info("Installing Zephyr SDK");
840-
const child = spawnSync(westInstallSDKCommand, {
841-
shell: true,
842-
cwd: zephyrWorkspaceDirectory,
843-
windowsHide: true,
844-
env: customEnv,
845-
});
846-
_logger.info("stdout: ", child.stdout.toString());
847-
_logger.info("stderr: ", child.stderr.toString());
848-
if (child.status) {
849-
_logger.info("exit code: ", child.status);
850-
if (child.status !== 0) {
851-
window.showErrorMessage(
852-
"Error installing Zephyr SDK." + "Exiting Zephyr Setup."
853-
);
857+
installedSuccessfully = false;
858+
progress2.report({
859+
message: "Failed",
860+
increment: 100,
861+
});
862+
resolve();
863+
864+
return;
854865
}
855866

856-
installedSuccessfully = false;
857867
progress2.report({
858-
message: "Failed",
868+
message: "Successfully installed Zephyr SDK.",
859869
increment: 100,
860870
});
861-
862-
return;
863-
}
864-
865-
progress2.report({
866-
message: "Successfully installed Zephyr SDK.",
867-
increment: 100,
868-
});
869-
}
871+
resolve();
872+
})
870873
);
871874

872875
if (installedSuccessfully) {

0 commit comments

Comments
 (0)