Skip to content

Commit 2fe9b8d

Browse files
get supported qemu targets from tools json (#1405)
1 parent bbf2948 commit 2fe9b8d

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/IPackage.ts

+2
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ export interface IPackage {
6464
versions: IVersion[];
6565

6666
strip_container_dirs: number;
67+
68+
supported_targets: string[];
6769
}

src/qemu/qemuManager.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { Logger } from "../logger/logger";
3333
import { statusBarItems } from "../statusBar";
3434
import { CommandKeys, createCommandDictionary } from "../cmdTreeView/cmdStore";
3535
import { appendIdfAndToolsToPath, isBinInPath } from "../utils";
36+
import { IdfToolsManager } from "../idfToolsManager";
3637

3738
export enum QemuLaunchMode {
3839
Debug,
@@ -142,20 +143,44 @@ export class QemuManager extends EventEmitter {
142143
return !!this.qemuTerminal;
143144
}
144145

146+
public async getQemuExecutable(idfPath: string) {
147+
const idfToolsManagerInstance = await IdfToolsManager.createIdfToolsManager(
148+
idfPath
149+
);
150+
const packages = await idfToolsManagerInstance.getPackageList(["qemu-xtensa", "qemu-riscv32"]);
151+
const xtensaPackage = packages.find((pkg) => {
152+
return pkg.name === "qemu-xtensa";
153+
});
154+
const risvPackage = packages.find((pkg) => {
155+
return pkg.name === "qemu-riscv32";
156+
});
157+
const qemuDictionary: { [key: string]: string } = {};
158+
for (const supportedTarget of xtensaPackage.supported_targets) {
159+
qemuDictionary[supportedTarget] = xtensaPackage.version_cmd[0];
160+
}
161+
for (const supportedTarget of risvPackage.supported_targets) {
162+
qemuDictionary[supportedTarget] = risvPackage.version_cmd[0];
163+
}
164+
// fallback for older versions
165+
if (Object.keys(qemuDictionary).length === 0) {
166+
qemuDictionary["esp32"] = "qemu-system-xtensa";
167+
qemuDictionary["esp32c3"] = "qemu-system-riscv32";
168+
}
169+
return qemuDictionary;
170+
}
171+
145172
public async start(mode: QemuLaunchMode, workspaceFolder: Uri) {
146173
if (this.isRunning()) {
147174
return;
148175
}
149176
const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder);
150-
const qemuExecutable =
151-
modifiedEnv.IDF_TARGET === "esp32"
152-
? "qemu-system-xtensa"
153-
: modifiedEnv.IDF_TARGET === "esp32c3"
154-
? "qemu-system-riscv32"
155-
: "";
177+
const qemuExecutableDict = await this.getQemuExecutable(
178+
modifiedEnv.IDF_PATH
179+
);
180+
const qemuExecutable = qemuExecutableDict[modifiedEnv.IDF_TARGET] || "";
156181
if (!qemuExecutable) {
157182
throw new Error(
158-
`${modifiedEnv.IDF_TARGET} is not supported by Espressif QEMU. Only esp32 or esp32c3 targets are supported.`
183+
`${modifiedEnv.IDF_TARGET} is not supported by Espressif QEMU. Check ESP-IDF and QEMU version installed.`
159184
);
160185
}
161186
const isQemuBinInPath = await isBinInPath(

0 commit comments

Comments
 (0)