diff --git a/build_system/src/clean.rs b/build_system/src/clean.rs index 56cc19d255f..929a878113d 100644 --- a/build_system/src/clean.rs +++ b/build_system/src/clean.rs @@ -1,40 +1,43 @@ -use crate::utils::remove_file; +use crate::utils::{remove_file, run_command}; use std::fs::remove_dir_all; #[derive(Default)] -struct CleanArg { - all: bool, +enum CleanArg { + /// `clean all` + All, + /// `clean ui-tests` + UiTests, + /// `clean --help` + #[default] + Help, } impl CleanArg { - fn new() -> Result, String> { - let mut args = CleanArg::default(); - + fn new() -> Result { // We skip the binary and the "clean" option. for arg in std::env::args().skip(2) { - match arg.as_str() { - "all" => args.all = true, - "--help" => { - Self::usage(); - return Ok(None); - } - a => return Err(format!("Unknown argument `{}`", a)), - } + return match arg.as_str() { + "all" => Ok(Self::All), + "ui-tests" => Ok(Self::UiTests), + "--help" => Ok(Self::Help), + a => Err(format!("Unknown argument `{}`", a)), + }; } - Ok(Some(args)) + Ok(Self::default()) } +} - fn usage() { - println!( - r#" - `clean` command help: +fn usage() { + println!( + r#" +`clean` command help: - all : Clean all data - --help : Show this help - "# - ) - } + all : Clean all data + ui-tests : Clean ui tests + --help : Show this help +"# + ) } fn clean_all() -> Result<(), String> { @@ -60,14 +63,25 @@ fn clean_all() -> Result<(), String> { Ok(()) } -pub fn run() -> Result<(), String> { - let args = match CleanArg::new()? { - Some(a) => a, - None => return Ok(()), - }; +fn clean_ui_tests() -> Result<(), String> { + run_command( + &[ + &"find", + &"rust/build/x86_64-unknown-linux-gnu/test/ui/", + &"-name", + &"stamp", + &"-delete", + ], + None, + )?; + Ok(()) +} - if args.all { - clean_all()?; +pub fn run() -> Result<(), String> { + match CleanArg::new()? { + CleanArg::All => clean_all()?, + CleanArg::UiTests => clean_ui_tests()?, + CleanArg::Help => usage(), } Ok(()) } diff --git a/build_system/src/test.rs b/build_system/src/test.rs index 1577cbf2b53..f3d0d38499c 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -32,7 +32,6 @@ fn get_runners() -> Runners { ("Run failing rustc tests", test_failing_rustc), ); runners.insert("--test-libcore", ("Run libcore tests", test_libcore)); - runners.insert("--clean-ui-tests", ("Clean ui tests", clean_ui_tests)); runners.insert("--clean", ("Empty cargo target directory", clean)); runners.insert("--build-sysroot", ("Build sysroot", build_sysroot)); runners.insert("--std-tests", ("Run std tests", std_tests)); @@ -1086,20 +1085,6 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> { }) } -fn clean_ui_tests(_env: &Env, _args: &TestArg) -> Result<(), String> { - run_command( - &[ - &"find", - &"rust/build/x86_64-unknown-linux-gnu/test/ui/", - &"-name", - &"stamp", - &"-delete", - ], - None, - )?; - Ok(()) -} - fn run_all(env: &Env, args: &TestArg) -> Result<(), String> { clean(env, args)?; mini_tests(env, args)?;