From da606facb0a06224b109d8cbc03cefb095194a10 Mon Sep 17 00:00:00 2001 From: Christian Westrom Date: Sat, 1 Jun 2024 00:31:04 +0900 Subject: [PATCH 1/2] un-hard-code the tests --- repbuild/src/main.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 191d544..f85bfe5 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -139,10 +139,6 @@ fn get_fs() -> Result, io::Error> { let fs = FileSystem::new(img, FsOptions::new())?; - // TODO: Do not hard code these here - let p = Package::load_from_file("sysdata/programs/tests/meta.toml".to_owned()); - p.build(); - // Read the contents of the file using a `match` block // to return the `data: Ok(c)` as a `String` // or handle any `errors: Err(_)`. @@ -244,7 +240,26 @@ TERM_BACKDROP={} let modules = value.get_mut("modules").unwrap().as_table_mut().unwrap(); // let mut real_modules = modules.clone(); - for (key, value) in modules.into_iter() { + modules.into_iter().for_each(|(key, value)| { + if value.is_table() && key == "tests" { + let path = value + .get("path") + .expect("You must have `path` as a value") + .as_str() + .unwrap() + .split("boot:///") + .last() + .unwrap() + .split(".") + .next() + .unwrap(); + let p = Package::load_from_file( + format!("sysdata/programs/{}/meta.toml", path).to_owned(), + ); + p.build(); + } + }); + modules.into_iter().for_each(|(_key, value)| { if value.is_table() { let path = value.get("path").expect("You must have `path` as a value"); let default_value = Value::String("".into()); @@ -258,10 +273,10 @@ TERM_BACKDROP={} ); limine_str.push_str(&a); } - } + }); // Copy modules into the test_programs directory - modules.into_iter().for_each(|(key, value)| { + modules.into_iter().for_each(|(_key, value)| { if value.is_table() { let path = value .get("path") From b0358efab855c4a9574a6a4b7f39a9c8d4b6b338 Mon Sep 17 00:00:00 2001 From: Christian Westrom Date: Sat, 1 Jun 2024 00:43:40 +0900 Subject: [PATCH 2/2] factor out separating path names from the boot prefix --- repbuild/src/main.rs | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index f85bfe5..0418a1e 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -12,6 +12,7 @@ use { path::Path, process::{exit, Command}, }, + toml::Value, }; fn main() -> Result<(), Error> { @@ -124,6 +125,10 @@ fn assemble() -> Result<(), Error> { Ok(()) } +fn get_path_without_boot_prefix(val: &Value) -> Option<&str> { + val.as_str()?.split("boot:///").last() +} + fn get_fs() -> Result, io::Error> { let filename = "sysdata/system_config.toml"; @@ -192,12 +197,7 @@ TERM_BACKDROP={} ); // Copy the term_wallpaper to the image - let term_wallpaper_path = term_wallpaper - .as_str() - .unwrap() - .split("boot:///") - .last() - .unwrap(); + let term_wallpaper_path = get_path_without_boot_prefix(term_wallpaper).unwrap(); copy_file_to_img(&format!("sysdata/{}", term_wallpaper_path), &fs); limine_str.push_str(&base); @@ -242,17 +242,13 @@ TERM_BACKDROP={} modules.into_iter().for_each(|(key, value)| { if value.is_table() && key == "tests" { - let path = value - .get("path") - .expect("You must have `path` as a value") - .as_str() - .unwrap() - .split("boot:///") - .last() - .unwrap() - .split(".") - .next() - .unwrap(); + let path = get_path_without_boot_prefix( + value.get("path").expect("You must have `path` as a value"), + ) + .unwrap() + .split(".") + .next() + .unwrap(); let p = Package::load_from_file( format!("sysdata/programs/{}/meta.toml", path).to_owned(), ); @@ -278,14 +274,12 @@ TERM_BACKDROP={} // Copy modules into the test_programs directory modules.into_iter().for_each(|(_key, value)| { if value.is_table() { - let path = value - .get("path") - .expect("You must have a `path` as a value") - .as_str() - .unwrap() - .split("boot:///") - .last() - .unwrap(); + let path = get_path_without_boot_prefix( + value + .get("path") + .expect("You must have a `path` as a value"), + ) + .unwrap(); let fpath = format!("target/test-programs/{}", path); copy_file_to_img(&fpath, &fs); }