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
8 changes: 7 additions & 1 deletion ostool/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{fs, path::Path};
use std::{
fs,
path::{Path, PathBuf},
};

use compile::{BuildSystem, Compile, CustomBuild};
use qemu::Qemu;
Expand All @@ -14,6 +17,7 @@ pub struct ProjectConfig {
pub compile: Compile,
pub qemu: Qemu,
pub uboot: Option<UbootConfig>,
pub include: Option<Vec<PathBuf>>,
}

impl ProjectConfig {
Expand All @@ -29,6 +33,7 @@ impl ProjectConfig {
},
qemu: Qemu::new_default(arch),
uboot: None,
include: None,
}
}

Expand All @@ -48,6 +53,7 @@ impl ProjectConfig {
compile: Compile { target, build },
qemu: Qemu::new_default(arch),
uboot: None,
include: None,
}
}

Expand Down
8 changes: 8 additions & 0 deletions ostool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct Cli {
enum SubCommands {
Build,
Run(RunArgs),
BoardTest,
CargoTest(TestArgs),
Defconfig(cmd::defconfig::Cmd),
}
Expand Down Expand Up @@ -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();

Expand Down
37 changes: 37 additions & 0 deletions ostool/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use colored::Colorize;
use crate::{
config::{ProjectConfig, compile::BuildSystem},
shell::{Shell, check_porgram, metadata},
step::UbootConfig,
};

#[derive(Default)]
Expand Down Expand Up @@ -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()
}
Expand Down
Loading