Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions ostool/src/run/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ pub struct RunQemuArgs {
///
/// Returns an error if QEMU fails to start or exits with an error.
pub async fn run_qemu(ctx: AppContext, args: RunQemuArgs) -> anyhow::Result<()> {
// Build logic will be implemented here
let config_path = match args.qemu_config.clone() {
Some(path) => path,
None => ctx.paths.manifest.join(".qemu.toml"),
None => find_qemu_config(&ctx)?,
};

info!("Using QEMU config file: {}", config_path.display());
Expand Down Expand Up @@ -510,3 +509,44 @@ impl QemuRunner {
Ok(())
}
}

/// Find QEMU configuration file with architecture-specific priority.
///
/// Search order:
/// 1. qemu-<arch>.toml
/// 2. .qemu-<arch>.toml
/// 3. qemu.toml
/// 4. .qemu.toml
fn find_qemu_config(ctx: &AppContext) -> anyhow::Result<PathBuf> {
Comment on lines +513 to +520
let manifest_dir = &ctx.paths.manifest;

// Get architecture string if available
let arch_str = ctx.arch.map(|arch| format!("{arch:?}").to_lowercase());

// Try architecture-specific config files first
if let Some(ref arch) = arch_str {
let candidates = [
manifest_dir.join(format!("qemu-{}.toml", arch)),
manifest_dir.join(format!(".qemu-{}.toml", arch)),
Comment on lines +529 to +530

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep menuconfig aligned with the new arch-specific lookup

The new arch-priority search means run_qemu now prefers qemu-<arch>.toml or .qemu-<arch>.toml, but MenuConfigHandler::handle_qemu_config still only loads and saves .qemu.toml (ostool/src/menuconfig.rs:71-90). In any multi-arch project that adds one of these per-arch files, interactive QEMU config changes no longer affect the file that is actually used for that architecture, which is a user-visible regression introduced by this lookup order.

Useful? React with 👍 / 👎.

];
for path in &candidates {
if path.exists() {
return Ok(path.clone());
}
Comment on lines +528 to +535
}
}

// Fall back to generic config files
let fallback_candidates = [
manifest_dir.join("qemu.toml"),
manifest_dir.join(".qemu.toml"),
Comment on lines +541 to +542

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve .qemu.toml precedence over qemu.toml

This reverses the existing default config path: run_qemu used to read and auto-generate .qemu.toml, QemuArgs still documents .qemu.toml as the default (ostool/src/main.rs:55-57), and handle_qemu_config still edits that file (ostool/src/menuconfig.rs:71-90). If a project contains both files after this change, ostool run qemu will silently ignore the documented/default config and use qemu.toml instead, so menuconfig edits and previously working .qemu.toml settings stop taking effect.

Useful? React with 👍 / 👎.

];
for path in &fallback_candidates {
if path.exists() {
return Ok(path.clone());
}
}

// Return default path if none exists
Ok(manifest_dir.join(".qemu.toml"))
}
Loading