2023-12-20 13:58:43 +00:00
|
|
|
use std::fs::remove_dir_all;
|
2024-02-13 20:26:14 +00:00
|
|
|
use std::path::Path;
|
2023-12-20 13:58:43 +00:00
|
|
|
|
2024-03-20 14:15:20 +00:00
|
|
|
use crate::utils::{get_sysroot_dir, remove_file, run_command};
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-12-20 13:58:43 +00:00
|
|
|
#[derive(Default)]
|
2024-01-18 17:41:25 +00:00
|
|
|
enum CleanArg {
|
|
|
|
/// `clean all`
|
|
|
|
All,
|
|
|
|
/// `clean ui-tests`
|
|
|
|
UiTests,
|
|
|
|
/// `clean --help`
|
|
|
|
#[default]
|
|
|
|
Help,
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CleanArg {
|
2024-01-18 17:41:25 +00:00
|
|
|
fn new() -> Result<Self, String> {
|
2023-12-20 13:58:43 +00:00
|
|
|
// We skip the binary and the "clean" option.
|
|
|
|
for arg in std::env::args().skip(2) {
|
2024-01-18 17:41:25 +00:00
|
|
|
return match arg.as_str() {
|
|
|
|
"all" => Ok(Self::All),
|
|
|
|
"ui-tests" => Ok(Self::UiTests),
|
|
|
|
"--help" => Ok(Self::Help),
|
|
|
|
a => Err(format!("Unknown argument `{}`", a)),
|
|
|
|
};
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
2024-01-18 17:41:25 +00:00
|
|
|
Ok(Self::default())
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
2024-01-18 17:41:25 +00:00
|
|
|
}
|
2023-12-20 13:58:43 +00:00
|
|
|
|
2024-01-18 17:41:25 +00:00
|
|
|
fn usage() {
|
|
|
|
println!(
|
|
|
|
r#"
|
|
|
|
`clean` command help:
|
2023-12-20 13:58:43 +00:00
|
|
|
|
2024-01-18 17:41:25 +00:00
|
|
|
all : Clean all data
|
|
|
|
ui-tests : Clean ui tests
|
|
|
|
--help : Show this help
|
|
|
|
"#
|
|
|
|
)
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn clean_all() -> Result<(), String> {
|
2024-03-20 14:15:20 +00:00
|
|
|
let build_sysroot = get_sysroot_dir();
|
|
|
|
let dirs_to_remove = [
|
|
|
|
"target".into(),
|
|
|
|
build_sysroot.join("sysroot"),
|
|
|
|
build_sysroot.join("sysroot_src"),
|
|
|
|
build_sysroot.join("target"),
|
|
|
|
];
|
2023-12-20 13:58:43 +00:00
|
|
|
for dir in dirs_to_remove {
|
|
|
|
let _ = remove_dir_all(dir);
|
|
|
|
}
|
2024-02-13 20:26:14 +00:00
|
|
|
let dirs_to_remove = ["regex", "rand", "simple-raytracer"];
|
|
|
|
for dir in dirs_to_remove {
|
|
|
|
let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir));
|
|
|
|
}
|
2023-12-20 13:58:43 +00:00
|
|
|
|
2024-03-20 14:15:20 +00:00
|
|
|
let files_to_remove =
|
|
|
|
[build_sysroot.join("Cargo.lock"), "perf.data".into(), "perf.data.old".into()];
|
2023-12-20 13:58:43 +00:00
|
|
|
|
|
|
|
for file in files_to_remove {
|
2024-03-20 14:15:20 +00:00
|
|
|
let _ = remove_file(&file);
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
println!("Successfully ran `clean all`");
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-01-18 17:41:25 +00:00
|
|
|
fn clean_ui_tests() -> Result<(), String> {
|
2024-02-13 20:26:14 +00:00
|
|
|
let path = Path::new(crate::BUILD_DIR).join("rust/build/x86_64-unknown-linux-gnu/test/ui/");
|
|
|
|
run_command(&[&"find", &path, &"-name", &"stamp", &"-delete"], None)?;
|
2024-01-18 17:41:25 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-20 13:58:43 +00:00
|
|
|
|
2024-01-18 17:41:25 +00:00
|
|
|
pub fn run() -> Result<(), String> {
|
|
|
|
match CleanArg::new()? {
|
|
|
|
CleanArg::All => clean_all()?,
|
|
|
|
CleanArg::UiTests => clean_ui_tests()?,
|
|
|
|
CleanArg::Help => usage(),
|
2023-12-20 13:58:43 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|