Skip to content
Merged
Show file tree
Hide file tree
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
238 changes: 147 additions & 91 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ mmio-api = { version = "0.2.2", path = "memory/mmio-api" }
lock_api = { version = "0.4", default-features = false }
log = "0.4"
spin = "0.12"
ostool = { version = "0.21" }
ostool = { version = "0.22.1" }
riscv = { version = "0.16.1", default-features = false }
sbi-rt = { version = "0.0.4", default-features = false }
uefi = "0.37.0"
Expand Down
2 changes: 0 additions & 2 deletions scripts/axbuild/src/arceos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impl ArceOS {
let mut qemu = match request.qemu_config.as_deref() {
Some(path) => self
.app
.tool_mut()
.read_qemu_config_from_path_for_cargo(cargo, path)
.await
.map(Some)?,
Expand All @@ -259,7 +258,6 @@ impl ArceOS {
match request.uboot_config.as_deref() {
Some(path) => self
.app
.tool_mut()
.read_uboot_config_from_path_for_cargo(cargo, path)
.await
.map(Some),
Expand Down
3 changes: 0 additions & 3 deletions scripts/axbuild/src/axvisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ impl Axvisor {
match request.uboot_config.as_deref() {
Some(path) => self
.app
.tool_mut()
.read_uboot_config_from_path_for_cargo(cargo, path)
.await
.map(Some),
Expand All @@ -390,14 +389,12 @@ impl Axvisor {
match board_config_path {
Some(path) => {
self.app
.tool_mut()
.read_board_run_config_from_path_for_cargo(cargo, path)
.await
}
None => {
let workspace_root = self.app.workspace_root().to_path_buf();
self.app
.tool_mut()
.ensure_board_run_config_in_dir_for_cargo(cargo, &workspace_root)
.await
}
Expand Down
1 change: 0 additions & 1 deletion scripts/axbuild/src/axvisor/rootfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub(super) async fn load_patched_qemu_config(
});
let mut qemu = axvisor
.app
.tool_mut()
.read_qemu_config_from_path_for_cargo(cargo, &config_path)
.await?;
patch_qemu_rootfs(
Expand Down
8 changes: 1 addition & 7 deletions scripts/axbuild/src/axvisor/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,7 @@ impl Axvisor {
let cargo = build::load_cargo_config(&request)?;
let base_uboot = match request.uboot_config.as_deref() {
Some(_) => self.load_uboot_config(&request, &cargo).await?,
None => Some(
self.app
.tool_mut()
.ensure_uboot_config_for_cargo(&cargo)
.await?,
),
None => Some(self.app.ensure_uboot_config_for_cargo(&cargo).await?),
};
let board_config = self
.load_board_config(&cargo, Some(board_test_config.as_path()))
Expand Down Expand Up @@ -604,7 +599,6 @@ impl Axvisor {
)?;
let qemu = self
.app
.tool_mut()
.read_qemu_config_from_path_for_cargo(&cargo, &case.case.qemu_config_path)
.await
.with_context(|| {
Expand Down
183 changes: 119 additions & 64 deletions scripts/axbuild/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ use std::{
use anyhow::Context;
use log::info;
use ostool::{
Tool, ToolConfig,
board::{RunBoardOptions, config::BoardRunConfig},
build::{CargoQemuRunnerArgs, CargoRunnerKind, CargoUbootRunnerArgs, config::Cargo},
board::{self as ostool_board, RunBoardOptions, config::BoardRunConfig},
build::{
self as ostool_build, CargoQemuRunnerArgs, CargoRunnerKind, CargoUbootRunnerArgs,
config::{BuildConfig, BuildSystem, Cargo},
},
invocation::{Invocation, InvocationOptions},
run::{
qemu::{QemuConfig, RunQemuOptions},
uboot::UbootConfig,
qemu::{self as ostool_qemu, QemuConfig, RunQemuOptions},
uboot::{self as ostool_uboot, UbootConfig},
},
};

Expand Down Expand Up @@ -69,7 +72,7 @@ fn snapshot_store_disabled() -> bool {
}

pub struct AppContext {
tool: Tool,
invocation: Invocation,
build_config_path: Option<PathBuf>,
root: PathBuf,
member_dirs: HashMap<String, PathBuf>,
Expand All @@ -84,9 +87,10 @@ impl AppContext {

info!("Workspace root: {}", workspace_root.display());

let tool = Tool::new(ToolConfig::default()).context("failed to initialize ostool")?;
let invocation = Self::new_invocation(&workspace_root, false)
.context("failed to initialize ostool invocation")?;
Ok(Self {
tool,
invocation,
build_config_path: None,
root: workspace_root,
member_dirs: HashMap::new(),
Expand All @@ -99,10 +103,6 @@ impl AppContext {
&self.root
}

pub(crate) fn tool_mut(&mut self) -> &mut Tool {
&mut self.tool
}

pub(crate) fn workspace_member_dir(&mut self, package: &str) -> anyhow::Result<&Path> {
if !self.member_dirs.contains_key(package) {
let member_dir = resolve_workspace_member_dir(package)?;
Expand All @@ -126,15 +126,16 @@ impl AppContext {
) -> anyhow::Result<()> {
self.set_build_config_path(build_config_path);
let _env_guard = EnvRestoreGuard::set(&cargo.env);
self.tool.cargo_build(&cargo).await
let build_config_path = self.build_config_path.clone();
ostool_build::cargo_build(&mut self.invocation, &cargo, build_config_path.as_deref()).await
}

pub(crate) async fn prepare_elf_artifact(
&mut self,
elf_path: PathBuf,
to_bin: bool,
) -> anyhow::Result<()> {
self.tool.prepare_elf_artifact(elf_path, to_bin).await
self.invocation.prepare_elf_artifact(elf_path, to_bin).await
}

pub(crate) async fn qemu(
Expand All @@ -146,17 +147,18 @@ impl AppContext {
let _env_guard = EnvRestoreGuard::set(&cargo.env);
let _path_guard = self.scoped_qemu_path(&cargo)?;
self.set_build_config_path(build_config_path);
self.tool
.cargo_run(
&cargo,
&CargoRunnerKind::Qemu(Box::new(CargoQemuRunnerArgs {
qemu,
debug: self.debug,
dtb_dump: false,
show_output: true,
})),
)
.await
let build_config_path = self.build_config_path.clone();
ostool_build::cargo_run(
&mut self.invocation,
&cargo,
build_config_path.as_deref(),
&CargoRunnerKind::Qemu(Box::new(CargoQemuRunnerArgs {
qemu,
debug: self.debug,
dtb_dump: false,
})),
)
.await
}

pub(crate) async fn run_qemu(
Expand All @@ -171,15 +173,13 @@ impl AppContext {
.map(crate::support::backtrace_output_capture::BacktraceOutputCaptureGuard::install)
.transpose()
.context("failed to install backtrace block output capture")?;
self.tool
.run_qemu(
&qemu,
RunQemuOptions {
dtb_dump: false,
show_output: true,
},
)
.await
self.activate_cargo_build_context(cargo)?;
ostool_qemu::run_qemu(
&mut self.invocation,
&qemu,
RunQemuOptions { dtb_dump: false },
)
.await
}

pub(crate) async fn run_prepared_qemu(
Expand All @@ -192,15 +192,12 @@ impl AppContext {
.map(crate::support::backtrace_output_capture::BacktraceOutputCaptureGuard::install)
.transpose()
.context("failed to install backtrace block output capture")?;
self.tool
.run_qemu(
&qemu,
RunQemuOptions {
dtb_dump: false,
show_output: true,
},
)
.await
ostool_qemu::run_qemu(
&mut self.invocation,
&qemu,
RunQemuOptions { dtb_dump: false },
)
.await
}

pub(crate) async fn uboot(
Expand All @@ -211,15 +208,14 @@ impl AppContext {
) -> anyhow::Result<()> {
let _env_guard = EnvRestoreGuard::set(&cargo.env);
self.set_build_config_path(build_config_path);
self.tool
.cargo_run(
&cargo,
&CargoRunnerKind::Uboot(Box::new(CargoUbootRunnerArgs {
uboot,
show_output: true,
})),
)
.await
let build_config_path = self.build_config_path.clone();
ostool_build::cargo_run(
&mut self.invocation,
&cargo,
build_config_path.as_deref(),
&CargoRunnerKind::Uboot(Box::new(CargoUbootRunnerArgs { uboot })),
)
.await
}

pub(crate) async fn board(
Expand All @@ -231,31 +227,90 @@ impl AppContext {
) -> anyhow::Result<()> {
let _env_guard = EnvRestoreGuard::set(&cargo.env);
self.set_build_config_path(build_config_path);
self.tool
.cargo_run_board(&cargo, &board_config, options)
.await
let build_config_path = self.build_config_path.clone();
ostool_board::cargo_run_board(
&mut self.invocation,
&cargo,
build_config_path.as_deref(),
&board_config,
options,
)
.await
}

pub(crate) fn set_debug_mode(&mut self, debug: bool) -> anyhow::Result<()> {
if self.debug == debug {
return Ok(());
}

self.tool = Tool::new(ToolConfig {
debug,
..ToolConfig::default()
})?;
self.invocation = Self::new_invocation(&self.root, debug)
.context("failed to reinitialize ostool invocation")?;
self.debug = debug;

self.tool
.set_build_config_path(self.build_config_path.clone());

Ok(())
}

pub(crate) async fn read_qemu_config_from_path_for_cargo(
&self,
cargo: &Cargo,
path: &Path,
) -> anyhow::Result<QemuConfig> {
ostool_qemu::read_config_from_path_for_cargo(&self.invocation, cargo, path).await
}

pub(crate) async fn read_uboot_config_from_path_for_cargo(
&self,
cargo: &Cargo,
path: &Path,
) -> anyhow::Result<UbootConfig> {
ostool_uboot::read_config_from_path_for_cargo(&self.invocation, cargo, path).await
}

pub(crate) async fn ensure_uboot_config_for_cargo(
&self,
cargo: &Cargo,
) -> anyhow::Result<UbootConfig> {
ostool_uboot::ensure_config_for_cargo(&self.invocation, cargo).await
}

pub(crate) async fn read_board_run_config_from_path_for_cargo(
&self,
cargo: &Cargo,
path: &Path,
) -> anyhow::Result<BoardRunConfig> {
ostool_board::read_run_config_from_path_for_cargo(&self.invocation, cargo, path).await
}

pub(crate) async fn ensure_board_run_config_in_dir_for_cargo(
&self,
cargo: &Cargo,
dir: &Path,
) -> anyhow::Result<BoardRunConfig> {
ostool_board::ensure_run_config_in_dir_for_cargo(&self.invocation, cargo, dir).await
}

fn set_build_config_path(&mut self, path: PathBuf) {
self.build_config_path = Some(path.clone());
self.tool.set_build_config_path(Some(path));
self.build_config_path = Some(path);
}

fn activate_cargo_build_context(&mut self, cargo: &Cargo) -> anyhow::Result<()> {
let build_config_path = self.build_config_path.clone();
ostool_build::activate_build_config(
&mut self.invocation,
&BuildConfig {
system: BuildSystem::Cargo(cargo.clone()),
},
build_config_path.as_deref(),
)
}

fn new_invocation(workspace_root: &Path, debug: bool) -> anyhow::Result<Invocation> {
Invocation::new(InvocationOptions::new(
Some(workspace_root.join("Cargo.toml")),
None,
None,
debug,
))
}

fn scoped_qemu_path(&self, cargo: &Cargo) -> anyhow::Result<PathRestoreGuard> {
Expand Down
Loading