Skip to content

Commit 99c1b11

Browse files
committed
Experimental build selector fixes
1 parent 3ca14b2 commit 99c1b11

File tree

6 files changed

+113
-26
lines changed

6 files changed

+113
-26
lines changed

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ export async function activate(context: vscode.ExtensionContext) {
586586
vscode.commands.registerCommand("zephyr-ide.add-build", async () => {
587587
if (wsConfig.activeSetupState && wsConfig.activeSetupState.westUpdated) {
588588
let result = await project.addBuild(wsConfig, context);
589+
console.log("Updating web view");
590+
console.log(result);
589591
vscode.commands.executeCommand("zephyr-ide.update-web-view");
592+
console.log("returning from adding build");
590593
return result;
591594
} else {
592595
vscode.window.showErrorMessage("Run `Zephyr IDE: West Update` first.");

src/project_utilities/build_selector.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,45 @@ async function getBoardlistWest(setupState: SetupState, folder: vscode.Uri | und
7575
}
7676

7777
let prevError: any;
78-
if (setupState.zephyrVersion === undefined) { return; }
78+
console.log("zephyrVersion");
79+
console.log(setupState.zephyrVersion);
80+
81+
if (setupState.zephyrVersion === undefined) {
82+
console.log("Returning because zephyrVersion is not set");
83+
return;
84+
}
7985
let res;
8086
let has_qualifiers = false;
8187
let has_revisions = false;
88+
console.log("Getting board list");
89+
8290
if (isVersionNumberGreater(setupState.zephyrVersion, 4, 1, 0)) {
91+
92+
console.log("Getting board list1");
8393
res = await executeShellCommandInPythonEnv("west boards -f '{name};{dir};{qualifiers};{revisions};{revision_default}'" + boardRootString, setupState.setupPath, setupState, false);
8494
has_qualifiers = true;
8595
has_revisions = true;
8696
} else if (isVersionNumberGreaterEqual(setupState.zephyrVersion, 3, 7, 0)) {
97+
console.log("Getting board list2");
8798
res = await executeShellCommandInPythonEnv("west boards -f '{name};{dir};{qualifiers}'" + boardRootString, setupState.setupPath, setupState, false);
8899
has_qualifiers = true;
89100
} else {
101+
102+
console.log("Getting board list3");
90103
res = await executeShellCommandInPythonEnv("west boards -f '{name};{dir}'" + boardRootString, setupState.setupPath, setupState, false);
91104
}
105+
console.log("Got board list");
106+
107+
console.log(res);
108+
console.log(res.stdout);
109+
console.log(res.stderr);
110+
console.log(JSON.stringify(res));
92111

93-
if (!res.stdout) {
94-
output.append(prevError);
95-
output.append(res.stderr);
112+
if (!res.stdout || res.stdout === "") {
113+
console.log("error");
114+
115+
console.log(prevError);
116+
console.log(res.stderr);
96117
vscode.window.showErrorMessage("Failed to run west boards command. See Zephyr IDE Output for error message");
97118
return;
98119
}
@@ -154,8 +175,8 @@ export async function pickBoard(setupState: SetupState, rootPath: string) {
154175
boardDirectories.push("Select Other Folder");
155176
const boardDirectoriesQpItems: QuickPickItem[] = boardDirectories.map(label => ({ label }));
156177

157-
const title = "Board Picker";
158-
178+
const title = "Board Dir Picker";
179+
console.log("picking directories");
159180
let pickPromise = showQuickPick({
160181
title,
161182
step: 1,
@@ -176,6 +197,7 @@ export async function pickBoard(setupState: SetupState, rootPath: string) {
176197

177198
let relBoardDir: string | undefined = path.relative(rootPath, (pick.label));
178199
if (pick.label === "Select Other Folder") {
200+
console.log("selecting other folder");
179201
const boarddir = await vscode.window.showOpenDialog({
180202
canSelectFiles: false,
181203
canSelectFolders: true,
@@ -192,13 +214,19 @@ export async function pickBoard(setupState: SetupState, rootPath: string) {
192214
}
193215

194216
let boardList;
217+
console.log("getting board list");
218+
console.log(relBoardDir);
219+
195220
if (relBoardDir) {
196221
boardList = await getBoardlistWest(setupState, vscode.Uri.file(path.join(rootPath, relBoardDir)));
197222
} else {
198223
boardList = await getBoardlistWest(setupState, undefined);
199224
}
225+
console.log("finished getting boar lsit");
200226

201227
if (!boardList) {
228+
console.log("empty board list");
229+
202230
return;
203231
}
204232

@@ -213,12 +241,17 @@ export async function pickBoard(setupState: SetupState, rootPath: string) {
213241
activeItem: undefined
214242
}).catch((error) => {
215243
console.error(error);
244+
245+
console.log("Pick Board error");
216246
return undefined;
217247
});
218248
pick = (await pickPromise as QuickPickItem);
219249
if (!pick) {
250+
console.log("Pick error");
251+
220252
return;
221253
};
254+
console.log(pick);
222255

223256
let pick_data = (pick as BoardItem);
224257

@@ -256,17 +289,20 @@ export async function pickBoard(setupState: SetupState, rootPath: string) {
256289
activeItem: revisionQPItems[revisionIndex]
257290
}).catch((error) => {
258291
console.error(error);
292+
293+
console.log("pick rev error");
259294
return undefined;
260295
});
261296
let pick = (await pickPromise as QuickPickItem);
262297
if (!pick) {
298+
299+
console.log("pick error");
263300
return;
264301
};
265302
revision = pick.label;
266303
}
267304

268-
269-
305+
console.log("returning board config");
270306
let boardConfig = {
271307
board: board,
272308
relBoardDir: relBoardDir,
@@ -280,6 +316,7 @@ export async function buildSelector(context: ExtensionContext, setupState: Setup
280316
const title = 'Add Build Configuration';
281317

282318
async function pickBoardStep(input: MultiStepInput, state: Partial<BuildConfig>) {
319+
console.log("picking board");
283320
let boardData = await pickBoard(setupState, rootPath);
284321
if (boardData) {
285322
state.relBoardDir = boardData.relBoardDir;

src/project_utilities/project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,13 @@ export async function addProject(wsConfig: WorkspaceConfig, context: vscode.Exte
505505

506506
export async function addBuildToProject(wsConfig: WorkspaceConfig, context: vscode.ExtensionContext, projectName: string) {
507507

508+
console.log(`Startign build1`);
508509
if (wsConfig.activeSetupState) {
509510

511+
console.log(`Startign build2`);
510512
let result = await buildSelector(context, wsConfig.activeSetupState, wsConfig.rootPath);
513+
514+
console.log(`build selector returned`);
511515
if (result && result.name !== undefined) {
512516
result.runnerConfigs = {};
513517
if (wsConfig.projects[projectName].buildConfigs[result.name]) {
@@ -517,7 +521,7 @@ export async function addBuildToProject(wsConfig: WorkspaceConfig, context: vsco
517521
return;
518522
}
519523
}
520-
524+
console.log(`Creating Build Configuration: ${result.name}`);
521525
vscode.window.showInformationMessage(`Creating Build Configuration: ${result.name}`);
522526
wsConfig.projects[projectName].buildConfigs[result.name] = result;
523527
wsConfig.projectStates[projectName].buildStates[result.name] = { runnerStates: {}, viewOpen: true };

src/setup_utilities/west-operations.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,18 @@ export async function setupWestEnvironment(context: vscode.ExtensionContext, wsC
246246
}
247247

248248
// Install `west`
249+
let res1 = await executeShellCommandInPythonEnv(`west --version`, wsConfig.activeSetupState.setupPath, wsConfig.activeSetupState, true);
250+
console.log(JSON.stringify(res1));
251+
252+
249253
let res = await executeShellCommandInPythonEnv(`python -m pip install west`, wsConfig.activeSetupState.setupPath, wsConfig.activeSetupState, true);
254+
console.log("Installing west");
255+
console.log(JSON.stringify(res));
256+
257+
console.log("new check")
258+
let res2 = await executeShellCommandInPythonEnv(`west --version`, wsConfig.activeSetupState.setupPath, wsConfig.activeSetupState, true);
259+
console.log(JSON.stringify(res2));
260+
250261
if (res.stdout) {
251262
output.append(res.stdout);
252263
output.appendLine("[SETUP] west installed");
@@ -256,6 +267,7 @@ export async function setupWestEnvironment(context: vscode.ExtensionContext, wsC
256267
return;
257268
}
258269

270+
259271
output.appendLine("[SETUP] West Python Environment Setup complete!");
260272

261273
// Setup flag complete

src/test/workflow-integration.test.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ suite("Workflow Integration Test Suite", () => {
166166
);
167167
} else if (currentStep === "build-config") {
168168
const firstItemLabel = (items[0]?.label || "").toLowerCase();
169-
if (firstItemLabel.includes("zephyr directory")) {
169+
if (firstItemLabel.includes("zephyr directory") || items.some((item: any) => item.label?.toLowerCase().includes("zephyr directory"))) {
170+
console.log(' → Build Config: Selecting Zephyr Directory Only option');
170171
return (
171172
items.find((item: any) =>
172173
item.label?.toLowerCase().includes("zephyr directory")
@@ -222,19 +223,26 @@ suite("Workflow Integration Test Suite", () => {
222223
hide: () => { },
223224
dispose: () => { },
224225
show: () => {
225-
setTimeout(() => {
226-
const selectedItem = getSelection(mockQuickPick.items);
227-
if (selectedItem) {
228-
mockQuickPick.selectedItems = [selectedItem];
229-
mockQuickPick.activeItems = [selectedItem];
230-
if (mockQuickPick._onDidChangeSelectionCallback) {
231-
mockQuickPick._onDidChangeSelectionCallback([selectedItem]);
226+
const checkAndSelect = () => {
227+
if (mockQuickPick.items && mockQuickPick.items.length > 0) {
228+
const selectedItem = getSelection(mockQuickPick.items);
229+
if (selectedItem) {
230+
console.log(` → QuickPick: Selected "${selectedItem.label || selectedItem}" from ${mockQuickPick.items.length} items`);
231+
mockQuickPick.selectedItems = [selectedItem];
232+
mockQuickPick.activeItems = [selectedItem];
233+
if (mockQuickPick._onDidChangeSelectionCallback) {
234+
mockQuickPick._onDidChangeSelectionCallback([selectedItem]);
235+
}
232236
}
237+
if (mockQuickPick._onDidAcceptCallback) {
238+
mockQuickPick._onDidAcceptCallback();
239+
}
240+
} else {
241+
// Retry if items not populated yet
242+
setTimeout(checkAndSelect, 5000);
233243
}
234-
if (mockQuickPick._onDidAcceptCallback) {
235-
mockQuickPick._onDidAcceptCallback();
236-
}
237-
}, 8000);
244+
};
245+
setTimeout(checkAndSelect, 2000);
238246
},
239247
onDidTriggerButton: () => ({ dispose: () => { } }),
240248
onDidChangeSelection: (callback: any) => {
@@ -292,7 +300,7 @@ suite("Workflow Integration Test Suite", () => {
292300
if (mockInputBox._onDidAcceptCallback) {
293301
mockInputBox._onDidAcceptCallback();
294302
}
295-
}, 8000);
303+
}, 30000);
296304
},
297305
onDidAccept: (callback: any) => {
298306
mockInputBox._onDidAcceptCallback = callback;
@@ -445,6 +453,15 @@ suite("Workflow Integration Test Suite", () => {
445453
globalQuickPickCallCount = 0;
446454
globalInputBoxCallCount = 0;
447455
currentStep = "build-config";
456+
457+
// Check if west is available before attempting build config
458+
const ext = vscode.extensions.getExtension("mylonics.zephyr-ide");
459+
const wsConfig = ext?.exports?.getWorkspaceConfig();
460+
if (!wsConfig?.initialSetupComplete) {
461+
console.log("⚠️ Setup not complete, retrying in 10 seconds...");
462+
await new Promise((resolve) => setTimeout(resolve, 10000));
463+
}
464+
448465
result = await vscode.commands.executeCommand("zephyr-ide.add-build");
449466
assert.ok(result, "Build configuration should succeed");
450467

src/utilities/utils.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export function isMacOS() {
5959
}
6060

6161
export function getPythonVenvBinaryFolder(setupState: SetupState) {
62+
console.log(JSON.stringify(setupState.env));
63+
console.log(JSON.stringify(platform));
6264
if (setupState.env["VIRTUAL_ENV"]) {
6365
switch (platform) {
6466
case "win32":
@@ -169,9 +171,9 @@ async function executeTask(task: vscode.Task) {
169171
export async function executeTaskHelperInPythonEnv(setupState: SetupState | undefined, taskName: string, cmd: string, cwd: string | undefined) {
170172
if (setupState && isMacOS()) {
171173
let newCmd = path.join(getPythonVenvBinaryFolder(setupState), cmd);
172-
return executeTaskHelper(taskName, newCmd, cwd);
174+
return await executeTaskHelper(taskName, newCmd, cwd);
173175
} else {
174-
return executeTaskHelper(taskName, cmd, cwd);
176+
return await executeTaskHelper(taskName, cmd, cwd);
175177
}
176178
}
177179

@@ -197,21 +199,33 @@ export async function executeTaskHelper(taskName: string, cmd: string, cwd: stri
197199
}
198200

199201
export async function executeShellCommandInPythonEnv(cmd: string, cwd: string, setupState: SetupState, display_error = true) {
202+
203+
console.log("Executing shell command in python env");
204+
console.log(JSON.stringify(setupState));
205+
console.log(JSON.stringify(cmd));
200206
let newCmd = path.join(getPythonVenvBinaryFolder(setupState), cmd);
201-
return executeShellCommand(newCmd, cwd, display_error);
207+
208+
let newCmd2 = "ls " + getPythonVenvBinaryFolder(setupState);
209+
console.log(JSON.stringify(newCmd));
210+
executeShellCommand(newCmd2, cwd, display_error);
211+
return await executeShellCommand(newCmd, cwd, display_error);
202212
};
203213

204214
export async function executeShellCommand(cmd: string, cwd: string, display_error = true) {
215+
console.log(cmd);
216+
console.log(cwd);
205217
let exec = util.promisify(cp.exec);
206218
let res = await exec(cmd, { cwd: cwd }).then(
207-
208219
value => {
220+
221+
console.log(JSON.stringify(value));
209222
return { stdout: value.stdout, stderr: value.stderr };
210223
},
211224
reason => {
212225
if (display_error) {
213226
output.append(reason);
214227
}
228+
console.log(JSON.stringify(reason));
215229
return { stdout: undefined, stderr: reason.stderr };
216230
}
217231
);

0 commit comments

Comments
 (0)