1use crate::Xtask;
5use crate::shell::XtaskShell;
6
7#[derive(Debug, clap::Parser)]
12#[clap(about = "Clean build system artifacts (flowey, packages, test results)")]
13pub struct Clean {
14 #[clap(long)]
16 all: bool,
17
18 #[clap(long)]
20 cargo: bool,
21
22 #[clap(long)]
24 dry_run: bool,
25}
26
27const DEFAULT_DIRS: &[&str] = &[
29 "flowey-out",
30 "flowey-persist",
31 ".packages",
32 "vmm_test_results",
33];
34
35impl Xtask for Clean {
36 fn run(self, ctx: crate::XtaskCtx) -> anyhow::Result<()> {
37 let do_cargo = self.all || self.cargo;
38
39 let mut removed_anything = false;
40
41 for dir_name in DEFAULT_DIRS {
43 let path = ctx.root.join(dir_name);
44 if path.exists() {
45 if self.dry_run {
46 println!("would remove {}", path.display());
47 } else {
48 println!("removing {}", path.display());
49 fs_err::remove_dir_all(&path)?;
50 }
51 removed_anything = true;
52 }
53 }
54
55 if do_cargo {
57 if self.dry_run {
58 println!("would run `cargo clean`");
59 } else {
60 println!("running `cargo clean`");
61 let sh = XtaskShell::new()?;
62 sh.cmd("cargo").arg("clean").run()?;
63 }
64 removed_anything = true;
65 }
66
67 if !removed_anything {
68 println!("nothing to clean");
69 }
70
71 Ok(())
72 }
73}