Skip to content

Commit 7dad07a

Browse files
authored
Merge pull request rust-lang#396 from GuillaumeGomez/rustify-clean-all
Rustify `clean_all.sh`
2 parents e0c4d65 + e26e074 commit 7dad07a

File tree

11 files changed

+85
-47
lines changed

11 files changed

+85
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
./y.sh build --features master
104104
# TODO: remove --features master when it is back to the default.
105105
cargo test --features master
106-
./clean_all.sh
106+
./y.sh clean all
107107
108108
- name: Prepare dependencies
109109
run: |

.github/workflows/gcc12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
./y.sh prepare --only-libcore --libgccjit12-patches
8787
./y.sh build --no-default-features --sysroot-panic-abort
8888
cargo test --no-default-features
89-
./clean_all.sh
89+
./y.sh clean all
9090
9191
- name: Prepare dependencies
9292
run: |

.github/workflows/m68k.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
./y.sh build --target-triple m68k-unknown-linux-gnu --features master
119119
# TODO: remove --features master when it is back to the default.
120120
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test --features master
121-
./clean_all.sh
121+
./y.sh clean all
122122
123123
- name: Prepare dependencies
124124
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
EMBED_LTO_BITCODE=1 ./y.sh build --release --release-sysroot --features master
8383
# TODO: remove --features master when it is back to the default.
8484
cargo test --features master
85-
./clean_all.sh
85+
./y.sh clean all
8686
8787
- name: Prepare dependencies
8888
run: |

.github/workflows/stdarch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
- name: Clean
101101
if: ${{ !matrix.cargo_runner }}
102102
run: |
103-
./clean_all.sh
103+
./y.sh clean all
104104
105105
- name: Prepare dependencies
106106
run: |

build_sysroot/build_sysroot.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

build_system/src/clean.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use crate::utils::remove_file;
2+
3+
use std::fs::remove_dir_all;
4+
5+
#[derive(Default)]
6+
struct CleanArg {
7+
all: bool,
8+
}
9+
10+
impl CleanArg {
11+
fn new() -> Result<Option<Self>, String> {
12+
let mut args = CleanArg::default();
13+
14+
// We skip the binary and the "clean" option.
15+
for arg in std::env::args().skip(2) {
16+
match arg.as_str() {
17+
"all" => args.all = true,
18+
"--help" => {
19+
Self::usage();
20+
return Ok(None);
21+
}
22+
a => return Err(format!("Unknown argument `{}`", a)),
23+
}
24+
}
25+
Ok(Some(args))
26+
}
27+
28+
fn usage() {
29+
println!(
30+
r#"
31+
`clean` command help:
32+
33+
all : Clean all data
34+
--help : Show this help
35+
"#
36+
)
37+
}
38+
}
39+
40+
fn clean_all() -> Result<(), String> {
41+
let dirs_to_remove = [
42+
"target",
43+
"build_sysroot/sysroot",
44+
"build_sysroot/sysroot_src",
45+
"build_sysroot/target",
46+
"regex",
47+
"simple-raytracer",
48+
];
49+
for dir in dirs_to_remove {
50+
let _ = remove_dir_all(dir);
51+
}
52+
53+
let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"];
54+
55+
for file in files_to_remove {
56+
let _ = remove_file(file);
57+
}
58+
59+
println!("Successfully ran `clean all`");
60+
Ok(())
61+
}
62+
63+
pub fn run() -> Result<(), String> {
64+
let args = match CleanArg::new()? {
65+
Some(a) => a,
66+
None => return Ok(()),
67+
};
68+
69+
if args.all {
70+
clean_all()?;
71+
}
72+
Ok(())
73+
}

build_system/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::process;
33

44
mod build;
5+
mod clean;
56
mod config;
67
mod prepare;
78
mod rustc_info;
@@ -22,6 +23,7 @@ fn usage() {
2223
"\
2324
Available commands for build_system:
2425
26+
clean : Run clean command
2527
prepare : Run prepare command
2628
build : Run build command
2729
test : Run test command
@@ -30,6 +32,7 @@ Available commands for build_system:
3032
}
3133

3234
pub enum Command {
35+
Clean,
3336
Prepare,
3437
Build,
3538
Test,
@@ -41,6 +44,7 @@ fn main() {
4144
}
4245

4346
let command = match env::args().nth(1).as_deref() {
47+
Some("clean") => Command::Clean,
4448
Some("prepare") => Command::Prepare,
4549
Some("build") => Command::Build,
4650
Some("test") => Command::Test,
@@ -57,6 +61,7 @@ fn main() {
5761
};
5862

5963
if let Err(e) = match command {
64+
Command::Clean => clean::run(),
6065
Command::Prepare => prepare::run(),
6166
Command::Build => build::run(),
6267
Command::Test => test::run(),

build_system/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
346346
Ok(out)
347347
}
348348

349-
pub fn remove_file<P: AsRef<Path>>(file_path: &P) -> Result<(), String> {
349+
pub fn remove_file<P: AsRef<Path> + ?Sized>(file_path: &P) -> Result<(), String> {
350350
std::fs::remove_file(file_path).map_err(|error| {
351351
format!(
352352
"Failed to remove `{}`: {:?}",

clean_all.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

rustup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ case $1 in
1515
rustup toolchain uninstall $nightly
1616
done
1717

18-
./clean_all.sh
18+
./y.sh clean all
1919
./y.sh prepare
2020
;;
2121
"commit")

0 commit comments

Comments
 (0)