From fcd336b3de942192d9723a3e523c4b0cbe616d3d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 24 Oct 2023 17:15:18 +0200 Subject: [PATCH] Add basics for `test` command in build system --- build_system/src/main.rs | 5 +++++ build_system/src/test.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 build_system/src/test.rs diff --git a/build_system/src/main.rs b/build_system/src/main.rs index 332a14ff0a2..bff82b6e3e5 100644 --- a/build_system/src/main.rs +++ b/build_system/src/main.rs @@ -5,6 +5,7 @@ mod build; mod config; mod prepare; mod rustc_info; +mod test; mod utils; macro_rules! arg_error { @@ -23,6 +24,7 @@ Available commands for build_system: prepare : Run prepare command build : Run build command + test : Run test command --help : Show this message" ); } @@ -30,6 +32,7 @@ Available commands for build_system: pub enum Command { Prepare, Build, + Test, } fn main() { @@ -40,6 +43,7 @@ fn main() { let command = match env::args().nth(1).as_deref() { Some("prepare") => Command::Prepare, Some("build") => Command::Build, + Some("test") => Command::Test, Some("--help") => { usage(); process::exit(0); @@ -55,6 +59,7 @@ fn main() { if let Err(e) = match command { Command::Prepare => prepare::run(), Command::Build => build::run(), + Command::Test => test::run(), } { eprintln!("Command failed to run: {e:?}"); process::exit(1); diff --git a/build_system/src/test.rs b/build_system/src/test.rs new file mode 100644 index 00000000000..4c8c63e59ab --- /dev/null +++ b/build_system/src/test.rs @@ -0,0 +1,15 @@ +use crate::utils::run_command_with_output; + +fn get_args<'a>(args: &mut Vec<&'a dyn AsRef>, extra_args: &'a Vec) { + for extra_arg in extra_args { + args.push(extra_arg); + } +} + +pub fn run() -> Result<(), String> { + let mut args: Vec<&dyn AsRef> = vec![&"bash", &"test.sh"]; + let extra_args = std::env::args().skip(2).collect::>(); + get_args(&mut args, &extra_args); + let current_dir = std::env::current_dir().map_err(|error| format!("`current_dir` failed: {:?}", error))?; + run_command_with_output(args.as_slice(), Some(¤t_dir)) +}