diff --git a/ostool/src/config/mod.rs b/ostool/src/config/mod.rs index c79ccd5..2e91f47 100644 --- a/ostool/src/config/mod.rs +++ b/ostool/src/config/mod.rs @@ -1,4 +1,7 @@ -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use compile::{BuildSystem, Compile, CustomBuild}; use qemu::Qemu; @@ -14,6 +17,7 @@ pub struct ProjectConfig { pub compile: Compile, pub qemu: Qemu, pub uboot: Option, + pub include: Option>, } impl ProjectConfig { @@ -29,6 +33,7 @@ impl ProjectConfig { }, qemu: Qemu::new_default(arch), uboot: None, + include: None, } } @@ -48,6 +53,7 @@ impl ProjectConfig { compile: Compile { target, build }, qemu: Qemu::new_default(arch), uboot: None, + include: None, } } diff --git a/ostool/src/main.rs b/ostool/src/main.rs index 77e1bb7..24b2fa8 100644 --- a/ostool/src/main.rs +++ b/ostool/src/main.rs @@ -27,6 +27,7 @@ struct Cli { enum SubCommands { Build, Run(RunArgs), + BoardTest, CargoTest(TestArgs), Defconfig(cmd::defconfig::Cmd), } @@ -100,6 +101,13 @@ fn main() -> Result<()> { )); } } + SubCommands::BoardTest => { + project.board_test_config().unwrap(); + steps.push(Compile::new_boxed(false)); + + let config = project.config.as_mut().unwrap(); + steps.push(Uboot::new_boxed(false)); + } SubCommands::Run(run_args) => { project.config_with_file().unwrap(); diff --git a/ostool/src/project.rs b/ostool/src/project.rs index 7b8209f..2087d1a 100644 --- a/ostool/src/project.rs +++ b/ostool/src/project.rs @@ -13,6 +13,7 @@ use colored::Colorize; use crate::{ config::{ProjectConfig, compile::BuildSystem}, shell::{Shell, check_porgram, metadata}, + step::UbootConfig, }; #[derive(Default)] @@ -68,6 +69,42 @@ impl Project { Ok(()) } + pub fn board_test_config(&mut self) -> Result<()> { + let meta = metadata(self.workdir()); + let config_path = meta.workspace_root.as_std_path().join(".project.toml"); + let board_toml_path = meta.workspace_root.as_std_path().join(".board.toml"); + + let mut config: ProjectConfig; + if !config_path.try_exists()? { + panic!(".project.toml file not found!"); + } else { + let content = fs::read_to_string(&config_path).unwrap(); + config = toml::from_str(&content).expect(".project.toml file not found!!"); + + config.include = Some(vec![board_toml_path.clone()]); + if let Some(include_files) = &config.include { + for board_toml in include_files { + if board_toml_path.exists() { + let board_content = fs::read_to_string(&board_toml_path).unwrap(); + let board_config: UbootConfig = + toml::from_str(&board_content).expect(".board.toml file not found!"); + // Merge the board-specific settings into the UbootConfig + config.uboot = Some(board_config); + } else { + println!( + "Warning: Include file does not exist: {}", + board_toml_path.display() + ); + } + } + } + } + + self.arch = Some(Arch::from_target(&config.compile.target).unwrap()); + self.config = Some(config); + Ok(()) + } + pub fn config_ref(&self) -> &ProjectConfig { self.config.as_ref().unwrap() }