Skip to content

Commit 57a4c54

Browse files
committed
Add command board-test, .board.toml is contained in .project.toml
1 parent e1a5b0e commit 57a4c54

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

ostool/src/config/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{fs, path::Path};
1+
use std::{
2+
fs,
3+
path::{Path, PathBuf},
4+
};
25

36
use compile::{BuildSystem, Compile, CustomBuild};
47
use qemu::Qemu;
@@ -14,6 +17,7 @@ pub struct ProjectConfig {
1417
pub compile: Compile,
1518
pub qemu: Qemu,
1619
pub uboot: Option<UbootConfig>,
20+
pub include: Option<Vec<PathBuf>>,
1721
}
1822

1923
impl ProjectConfig {
@@ -29,6 +33,7 @@ impl ProjectConfig {
2933
},
3034
qemu: Qemu::new_default(arch),
3135
uboot: None,
36+
include: None,
3237
}
3338
}
3439

@@ -48,6 +53,7 @@ impl ProjectConfig {
4853
compile: Compile { target, build },
4954
qemu: Qemu::new_default(arch),
5055
uboot: None,
56+
include: None,
5157
}
5258
}
5359

ostool/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct Cli {
2727
enum SubCommands {
2828
Build,
2929
Run(RunArgs),
30+
BoardTest,
3031
CargoTest(TestArgs),
3132
Defconfig(cmd::defconfig::Cmd),
3233
}
@@ -100,6 +101,13 @@ fn main() -> Result<()> {
100101
));
101102
}
102103
}
104+
SubCommands::BoardTest => {
105+
project.board_test_config().unwrap();
106+
steps.push(Compile::new_boxed(false));
107+
108+
let config = project.config.as_mut().unwrap();
109+
steps.push(Uboot::new_boxed(false));
110+
}
103111
SubCommands::Run(run_args) => {
104112
project.config_with_file().unwrap();
105113

ostool/src/project.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use colored::Colorize;
1313
use crate::{
1414
config::{ProjectConfig, compile::BuildSystem},
1515
shell::{Shell, check_porgram, metadata},
16+
step::UbootConfig,
1617
};
1718

1819
#[derive(Default)]
@@ -68,6 +69,42 @@ impl Project {
6869
Ok(())
6970
}
7071

72+
pub fn board_test_config(&mut self) -> Result<()> {
73+
let meta = metadata(self.workdir());
74+
let config_path = meta.workspace_root.as_std_path().join(".project.toml");
75+
let board_toml_path = meta.workspace_root.as_std_path().join(".board.toml");
76+
77+
let mut config: ProjectConfig;
78+
if !config_path.try_exists()? {
79+
panic!(".project.toml file not found!");
80+
} else {
81+
let content = fs::read_to_string(&config_path).unwrap();
82+
config = toml::from_str(&content).expect(".project.toml file not found!!");
83+
84+
config.include = Some(vec![board_toml_path.clone()]);
85+
if let Some(include_files) = &config.include {
86+
for board_toml in include_files {
87+
if board_toml_path.exists() {
88+
let board_content = fs::read_to_string(&board_toml_path).unwrap();
89+
let board_config: UbootConfig =
90+
toml::from_str(&board_content).expect(".board.toml file not found!");
91+
// Merge the board-specific settings into the UbootConfig
92+
config.uboot = Some(board_config);
93+
} else {
94+
println!(
95+
"Warning: Include file does not exist: {}",
96+
board_toml_path.display()
97+
);
98+
}
99+
}
100+
}
101+
}
102+
103+
self.arch = Some(Arch::from_target(&config.compile.target).unwrap());
104+
self.config = Some(config);
105+
Ok(())
106+
}
107+
71108
pub fn config_ref(&self) -> &ProjectConfig {
72109
self.config.as_ref().unwrap()
73110
}

0 commit comments

Comments
 (0)