Skip to content

Commit 660da33

Browse files
authored
Fixed issue where workspace would not set up if zephyr folder was used directly (#167)
* Fixed issue where workspace would not set up if zephyr folder was used directly * Using zephyrDir for python requirements install
1 parent bbeb5a8 commit 660da33

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/setup_utilities/west-operations.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ export async function westUpdate(context: vscode.ExtensionContext, wsConfig: Wor
132132
if (zephyrModuleInfo) {
133133
wsConfig.activeSetupState.zephyrDir = zephyrModuleInfo.path;
134134
wsConfig.activeSetupState.zephyrVersion = await getModuleVersion(zephyrModuleInfo.path);
135+
} else {
136+
// Fallback: check for zephyr/VERSION file in setupPath
137+
const zephyrVersionFile = path.join(wsConfig.activeSetupState.setupPath, "zephyr", "VERSION");
138+
if (fs.existsSync(zephyrVersionFile)) {
139+
try {
140+
const versionContent = fs.readFileSync(zephyrVersionFile, "utf8");
141+
// Parse version info
142+
const majorMatch = versionContent.match(/VERSION_MAJOR\s*=\s*(\d+)/);
143+
const minorMatch = versionContent.match(/VERSION_MINOR\s*=\s*(\d+)/);
144+
const patchMatch = versionContent.match(/PATCHLEVEL\s*=\s*(\d+)/);
145+
const tweakMatch = versionContent.match(/VERSION_TWEAK\s*=\s*(\d+)/);
146+
const extraMatch = versionContent.match(/EXTRAVERSION\s*=\s*(.*)/);
147+
let version = "";
148+
if (majorMatch && minorMatch && patchMatch) {
149+
version = `${majorMatch[1]}.${minorMatch[1]}.${patchMatch[1]}`;
150+
if (tweakMatch && tweakMatch[1] !== "0") {
151+
version += `.${tweakMatch[1]}`;
152+
}
153+
if (extraMatch && extraMatch[1].trim()) {
154+
version += `-${extraMatch[1].trim()}`;
155+
}
156+
wsConfig.activeSetupState.zephyrDir = path.join(wsConfig.activeSetupState.setupPath, "zephyr");
157+
// Parse version string into ZephyrVersionNumber type
158+
wsConfig.activeSetupState.zephyrVersion = {
159+
major: majorMatch ? parseInt(majorMatch[1]) : 0,
160+
minor: minorMatch ? parseInt(minorMatch[1]) : 0,
161+
patch: patchMatch ? parseInt(patchMatch[1]) : 0,
162+
tweak: tweakMatch ? parseInt(tweakMatch[1]) : 0,
163+
extra: extraMatch && extraMatch[1].trim() !== "" ? parseInt(extraMatch[1].trim()) : 0
164+
};
165+
output.appendLine(`[SETUP] Zephyr version detected from VERSION file: ${version}`);
166+
} else {
167+
vscode.window.showErrorMessage("West Update succeeded, but Zephyr VERSION file could not be parsed.");
168+
}
169+
} catch (err) {
170+
vscode.window.showErrorMessage("West Update succeeded, but error reading Zephyr VERSION file.");
171+
}
172+
} else {
173+
vscode.window.showErrorMessage("West Update succeeded, but Zephyr module information could not be found.");
174+
}
135175
}
136176

137177
reloadEnvironmentVariables(context, wsConfig.activeSetupState);
@@ -160,16 +200,11 @@ export async function installPythonRequirements(context: vscode.ExtensionContext
160200
return false;
161201
}
162202

163-
let zephyrPath = await getModulePathAndVersion(wsConfig.activeSetupState, "zephyr");
164-
if (!zephyrPath || !zephyrPath.path) {
165-
vscode.window.showErrorMessage('Zephyr IDE: Zephyr folder not found. Please call West Update First');
166-
return false;
167-
}
168203

169204
wsConfig.activeSetupState.packagesInstalled = false;
170205
saveSetupState(context, wsConfig, globalConfig);
171206

172-
let cmd = `pip install -r ${path.join(zephyrPath.path, "scripts", "requirements.txt")} -U dtsh patool semvar tqdm`;
207+
let cmd = `pip install -r ${path.join(wsConfig.activeSetupState.zephyrDir, "scripts", "requirements.txt")} -U dtsh patool semvar tqdm`;
173208
let reqRes = await executeTaskHelperInPythonEnv(wsConfig.activeSetupState, "Zephyr IDE: Install Python Requirements", cmd, wsConfig.activeSetupState.setupPath);
174209

175210
if (!reqRes) {

0 commit comments

Comments
 (0)