Skip to content

feat: 添加超时配置支持到 QEMU 和 U-Boot 运行器,改进串口终端的超时处理#55

Merged
ZR233 merged 9 commits intomainfrom
dev-api
Mar 25, 2026
Merged

feat: 添加超时配置支持到 QEMU 和 U-Boot 运行器,改进串口终端的超时处理#55
ZR233 merged 9 commits intomainfrom
dev-api

Conversation

@ZR233
Copy link
Member

@ZR233 ZR233 commented Mar 25, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 08:59
@ZR233 ZR233 changed the title Dev api feat: 添加超时配置支持到 QEMU 和 U-Boot 运行器,改进串口终端的超时处理 Mar 25, 2026
@ZR233 ZR233 merged commit d49b788 into main Mar 25, 2026
4 checks passed
@ZR233 ZR233 deleted the dev-api branch March 25, 2026 09:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new Tool orchestration API and refactors the CLI + runners (QEMU/U-Boot/TFTP) to use it, adding file-based logging and new automation features (shell auto-init + timeouts).

Changes:

  • Add Tool/ToolConfig + manifest/workspace resolution and migrate build/run flows away from the old AppContext path/config responsibilities.
  • Add a file logger ({workspace}/target/ostool.ans) and update CLIs to report errors and log locations consistently.
  • Enhance QEMU/U-Boot runners with shared regex compilation/printing helpers, shell auto-init support, Linux system TFTP staging, and timeout handling.

Reviewed changes

Copilot reviewed 16 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ostool/src/tool.rs New Tool API (manifest/workspace resolution, artifact handling, build config UI hooks).
ostool/src/ctx.rs Slim down AppContext to runtime state + artifacts only.
ostool/src/run/qemu.rs Refactor to Tool, add shell auto-init + timeout + stdin passthrough/raw-mode guard, adjust config resolution behavior.
ostool/src/run/uboot.rs Refactor to Tool, add shell auto-init + timeout, improve TFTP handling and regex utilities usage.
ostool/src/run/tftp.rs Add Linux tftpd-hpa detection/installation/config staging; keep built-in server for other platforms.
ostool/src/run/shell_init.rs New shared shell auto-init matcher + delayed command sender.
ostool/src/run/output_matcher.rs Factor out regex compilation + match printing + match-to-result conversion.
ostool/src/run/mod.rs Register new shell_init module.
ostool/src/sterm/mod.rs Add optional session timeout + terminal restore helper and propagate timeout errors.
ostool/src/logger.rs New file logger implementation + initializer.
ostool/src/main.rs Switch CLI to Tool, add logger init + improved error reporting.
ostool/src/bin/cargo-osrun.rs Switch runner binary to Tool, add logger init + improved error reporting.
ostool/src/menuconfig.rs Switch menuconfig handler to Tool and updated config path resolution.
ostool/src/build/mod.rs Migrate build/run entrypoints to Tool; enhance QEMU runner kind defaults and config path selection.
ostool/src/build/cargo_builder.rs Migrate to Tool; resolve cargo executable via JSON messages and propagate artifact dirs.
ostool/src/lib.rs Export Tool API and add logger module.
ostool/Cargo.toml Add chrono dependency for timestamped file logs.
Cargo.lock Lockfile updates (chrono bump and windows-sys bumps via dependency resolution).
.gitignore Ignore .sisyphus.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +222 to +224
let timeout = self.timeout.unwrap();
let label = self.timeout_label.as_deref().unwrap_or("serial terminal");
return Err(anyhow!("{label} timed out after {}s", timeout.as_secs()));
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

timed_out can be set whenever stop_deadline expires (e.g., when callers use TermHandle::stop_after(MATCH_DRAIN_DURATION) to drain output), but run_terminal treats any timed_out() as a session timeout and then unconditionally does self.timeout.unwrap(). If no timeout was configured, this will panic; even if a timeout was configured, it can misreport a drain/stop as a timeout. Consider separating “session timeout” from other stop_after uses (e.g., distinct deadlines or a stop reason enum), and only return a timeout error when the configured session timeout expires.

Suggested change
let timeout = self.timeout.unwrap();
let label = self.timeout_label.as_deref().unwrap_or("serial terminal");
return Err(anyhow!("{label} timed out after {}s", timeout.as_secs()));
if let Some(timeout) = self.timeout {
let label = self.timeout_label.as_deref().unwrap_or("serial terminal");
return Err(anyhow!("{label} timed out after {}s", timeout.as_secs()));
} else {
// Timed-out flag was set, but no session timeout was configured.
// Treat this as a non-session deadline/drain completion rather than an error.
info!("Serial terminal stopped after deadline without configured session timeout");
return Ok(());
}

Copilot uses AI. Check for mistakes.

pub fn restore_terminal_mode() {
let _ = disable_raw_mode();
let _ = Command::new("stty").arg("echo").arg("icanon").status();
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

restore_terminal_mode() unconditionally runs stty echo icanon. This is Unix-specific and will fail/no-op on Windows (and can also fail on minimal Linux containers without stty). Consider guarding the stty invocation with #[cfg(unix)] (or a runtime OS check) and relying on crossterm raw mode restoration on non-Unix platforms.

Suggested change
let _ = Command::new("stty").arg("echo").arg("icanon").status();
#[cfg(unix)]
{
let _ = Command::new("stty").arg("echo").arg("icanon").status();
}

Copilot uses AI. Check for mistakes.
Comment on lines +415 to +434
fn ui_hock_pacage_select(&self) -> ElemHock {
let path = "system.package";
let cargo_toml = self.workspace_dir.join("Cargo.toml");

ElemHock {
path: path.to_string(),
callback: Arc::new(move |siv: &mut Cursive, path: &str| {
let mut items = Vec::new();
if let Ok(metadata) = cargo_metadata::MetadataCommand::new()
.manifest_path(&cargo_toml)
.no_deps()
.exec()
{
for pkg in &metadata.packages {
items.push(pkg.name.to_string());
}
}

show_list_select(siv, "Pacage", &items, path, on_package_selected);
}),
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Spelling: ui_hock_pacage_select / dialog title "Pacage" look like typos for "package". Renaming the function and fixing the UI label will improve clarity and avoid propagating the misspelling into public-ish identifiers.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot mentioned this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants