xtask/
clean.rs

1use std::path::Path;
2
3use anyhow::Result;
4use clap::Args;
5use walkdir::WalkDir;
6
7use crate::util::{repository_root, run_cmd};
8
9/// Clean cargo target directories
10#[derive(Debug, Args)]
11pub(super) struct CleanCmd {}
12
13impl CleanCmd {
14    pub fn run(self) -> Result<()> {
15        let root_dir = repository_root()?;
16
17        run_cargo_clean(&root_dir.join("bindings"))?;
18
19        for entry in WalkDir::new(
20            root_dir
21                .join("crates")
22                .join("swc_plugin_backend_wasmer")
23                .join("tests"),
24        ) {
25            let entry = entry?;
26            if entry.file_name().to_string_lossy() == "Cargo.toml" {
27                run_cargo_clean(entry.path().parent().unwrap())?;
28            }
29        }
30
31        // This should be last due to `xtask` itself
32        run_cargo_clean(&root_dir)?;
33
34        Ok(())
35    }
36}
37
38fn run_cargo_clean(dir: &Path) -> Result<()> {
39    run_cmd(
40        std::process::Command::new("cargo")
41            .arg("clean")
42            .current_dir(dir),
43    )
44}