Skip to content

Commit 71fc6bb

Browse files
committed
feat(ostool): expose variable and OVMF cache APIs
1 parent abeee21 commit 71fc6bb

7 files changed

Lines changed: 55 additions & 6 deletions

File tree

ostool/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
//! - [`build`] - Build system configuration and Cargo integration
2020
//! - [`invocation`] - Invocation inputs and resolved project layout
2121
//! - [`menuconfig`] - TUI-based menu configuration
22+
//! - [`ovmf`] - Verified prebuilt OVMF firmware cache
2223
//! - [`run`] - QEMU, TFTP, and U-Boot runners
2324
//! - [`sterm`] - Serial terminal implementation
2425
//! - [`utils`] - Common utilities and helper functions
26+
//! - [`variables`] - Workspace, package, temporary, and environment variable expansion
2527
//!
2628
//! ## Example
2729
//!
@@ -62,6 +64,9 @@ pub mod logger;
6264
/// build options through an interactive terminal interface.
6365
pub mod menuconfig;
6466

67+
/// Verified prebuilt OVMF firmware cache.
68+
pub mod ovmf;
69+
6570
mod project;
6671

6772
mod process;
@@ -81,6 +86,9 @@ pub mod sterm;
8186
/// Common utilities and helper functions.
8287
pub mod utils;
8388

89+
/// Workspace, package, temporary, and environment variable expansion.
90+
pub mod variables;
91+
8492
#[macro_use]
8593
extern crate log;
8694
#[macro_use]

ostool/src/ovmf.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Verified prebuilt OVMF firmware cache.
2+
3+
use std::path::PathBuf;
4+
5+
pub use crate::run::ovmf_prebuilt::{Arch, Error, FileType, Prebuilt, Source};
6+
7+
/// Returns the shared OVMF cache directory.
8+
///
9+
/// All ostool consumers use `$TMPDIR/ostool/ovmf`, where `$TMPDIR` is the
10+
/// platform temporary directory selected by [`std::env::temp_dir`].
11+
pub fn default_cache_dir() -> PathBuf {
12+
std::env::temp_dir().join("ostool").join("ovmf")
13+
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use super::*;
18+
19+
#[test]
20+
fn shared_cache_is_owned_by_ostool() {
21+
assert_eq!(
22+
default_cache_dir(),
23+
std::env::temp_dir().join("ostool").join("ovmf")
24+
);
25+
}
26+
}

ostool/src/project/variables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl VariableScope {
2828
}
2929

3030
/// Builds a variable scope for a specific Cargo package directory.
31-
pub fn for_package(layout: &ProjectLayout, package_dir: PathBuf) -> Self {
31+
pub(crate) fn for_package(layout: &ProjectLayout, package_dir: PathBuf) -> Self {
3232
Self::new(
3333
layout.workspace_dir().to_path_buf(),
3434
package_dir,

ostool/src/run/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mod output_matcher;
3434

3535
pub use output_matcher::{ByteStreamMatcher, StreamMatch, StreamMatchKind};
3636

37-
/// OVMF prebuilt firmware downloader (internal).
38-
mod ovmf_prebuilt;
37+
/// OVMF prebuilt firmware downloader backing the public cache API.
38+
pub(crate) mod ovmf_prebuilt;
3939

4040
/// Shared shell auto-init matcher and delayed command sender.
4141
pub(crate) mod shell_init;

ostool/src/run/qemu.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ use crate::{
5050
boot::artifacts::{default_qemu_dtb_dump_path, prepare_qemu_dtb_dump},
5151
build::config::Cargo,
5252
invocation::Invocation,
53+
ovmf::{Arch, FileType, Prebuilt, Source, default_cache_dir},
5354
process::ProcessContext,
5455
project::variables::{self, VariableScope},
5556
project::{ProjectLayout, metadata},
5657
run::{
5758
execution::{RunnerExecutionSummary, RunnerExitStatus, timeout_duration},
5859
output_matcher::{ByteStreamMatcher, compile_regexes, print_match_event},
59-
ovmf_prebuilt::{Arch, FileType, Prebuilt, Source},
6060
qemu_plan::{QemuBootSource, QemuCommandPlanInput, build_qemu_command_plan},
6161
shell_init::{
6262
SHELL_INIT_CHUNK_DELAY, SHELL_INIT_CHUNK_SIZE, SHELL_INIT_DELAY, ShellAutoInitMatcher,
@@ -611,8 +611,7 @@ impl QemuRunner {
611611
.input
612612
.arch
613613
.ok_or_else(|| anyhow::anyhow!("Cannot determine architecture for OVMF preparation"))?;
614-
let tmp = std::env::temp_dir();
615-
let bios_dir = tmp.join("ostool").join("ovmf");
614+
let bios_dir = default_cache_dir();
616615
fs::create_dir_all(&bios_dir)
617616
.await
618617
.with_path("failed to create directory", &bios_dir)?;

ostool/src/variables.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Workspace, package, temporary, and environment variable expansion.
2+
3+
pub use crate::project::variables::{VariableScope, expand_path_variables, expand_variables};

ostool/tests/ui/pass_module_level_apis.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,26 @@ use ostool::{
88
config::{BuildConfig, BuildSystem, Cargo, Custom},
99
},
1010
invocation::{Invocation, InvocationOptions},
11+
ovmf::{Arch, FileType, Prebuilt, Source, default_cache_dir},
1112
run::{
1213
qemu::{self, QemuConfig, RunQemuOptions},
1314
uboot::{self, UbootConfig},
1415
},
16+
variables::{VariableScope, expand_path_variables, expand_variables},
1517
};
1618

19+
fn assert_prebuilt_api(prebuilt: &Prebuilt) {
20+
let _ = prebuilt.get_file(Arch::X64, FileType::Code);
21+
}
22+
1723
fn main() {
24+
let scope = VariableScope::new("workspace".into(), "package".into(), "tmp".into());
25+
let _ = expand_variables("${workspace}", &scope).unwrap();
26+
let _ = expand_path_variables(Path::new("${tmpDir}/asset"), &scope).unwrap();
27+
let _ = default_cache_dir();
28+
let _ = Source::LATEST;
29+
let _ = assert_prebuilt_api;
30+
1831
let mut invocation = Invocation::new(InvocationOptions::default()).unwrap();
1932
let cargo = Cargo {
2033
package: "kernel".into(),

0 commit comments

Comments
 (0)