Skip to content

Commit 6bc8ca0

Browse files
Rollup merge of rust-lang#44694 - tommyip:make_clean, r=Mark-Simulacrum
Add --all flag to ./x.py clean This make `clean` removes the LLVM and download cache directory as well. Fixes rust-lang#44214. r? @Mark-Simulacrum
2 parents 20f892f + 09d90e5 commit 6bc8ca0

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a> Builder<'a> {
306306
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
307307
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
308308
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
309-
Subcommand::Clean => panic!(),
309+
Subcommand::Clean { .. } => panic!(),
310310
};
311311

312312
let builder = Builder {

src/bootstrap/clean.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,37 @@
1313
//! Responsible for cleaning out a build directory of all old and stale
1414
//! artifacts to prepare for a fresh build. Currently doesn't remove the
1515
//! `build/cache` directory (download cache) or the `build/$target/llvm`
16-
//! directory as we want that cached between builds.
16+
//! directory unless the --all flag is present.
1717
1818
use std::fs;
1919
use std::io::{self, ErrorKind};
2020
use std::path::Path;
2121

2222
use Build;
2323

24-
pub fn clean(build: &Build) {
24+
pub fn clean(build: &Build, all: bool) {
2525
rm_rf("tmp".as_ref());
26-
rm_rf(&build.out.join("tmp"));
27-
rm_rf(&build.out.join("dist"));
2826

29-
for host in &build.hosts {
30-
let entries = match build.out.join(host).read_dir() {
31-
Ok(iter) => iter,
32-
Err(_) => continue,
33-
};
27+
if all {
28+
rm_rf(&build.out);
29+
} else {
30+
rm_rf(&build.out.join("tmp"));
31+
rm_rf(&build.out.join("dist"));
3432

35-
for entry in entries {
36-
let entry = t!(entry);
37-
if entry.file_name().to_str() == Some("llvm") {
38-
continue
33+
for host in &build.hosts {
34+
let entries = match build.out.join(host).read_dir() {
35+
Ok(iter) => iter,
36+
Err(_) => continue,
37+
};
38+
39+
for entry in entries {
40+
let entry = t!(entry);
41+
if entry.file_name().to_str() == Some("llvm") {
42+
continue
43+
}
44+
let path = t!(entry.path().canonicalize());
45+
rm_rf(&path);
3946
}
40-
let path = t!(entry.path().canonicalize());
41-
rm_rf(&path);
4247
}
4348
}
4449
}

src/bootstrap/flags.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ pub enum Subcommand {
6060
paths: Vec<PathBuf>,
6161
test_args: Vec<String>,
6262
},
63-
Clean,
63+
Clean {
64+
all: bool,
65+
},
6466
Dist {
6567
paths: Vec<PathBuf>,
6668
},
@@ -147,6 +149,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
147149
opts.optmulti("", "test-args", "extra arguments", "ARGS");
148150
},
149151
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
152+
"clean" => { opts.optflag("", "all", "clean all build artifacts"); },
150153
_ => { },
151154
};
152155

@@ -250,17 +253,18 @@ Arguments:
250253
}
251254
});
252255

253-
// All subcommands can have an optional "Available paths" section
256+
// All subcommands except `clean` can have an optional "Available paths" section
254257
if matches.opt_present("verbose") {
255258
let config = Config::parse(&["build".to_string()]);
256259
let mut build = Build::new(config);
257260
metadata::build(&mut build);
258261

259262
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
260263
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());
261-
} else {
262-
extra_help.push_str(format!("Run `./x.py {} -h -v` to see a list of available paths.",
263-
subcommand).as_str());
264+
} else if subcommand.as_str() != "clean" {
265+
extra_help.push_str(format!(
266+
"Run `./x.py {} -h -v` to see a list of available paths.",
267+
subcommand).as_str());
264268
}
265269

266270
// User passed in -h/--help?
@@ -290,10 +294,13 @@ Arguments:
290294
}
291295
"clean" => {
292296
if paths.len() > 0 {
293-
println!("\nclean takes no arguments\n");
297+
println!("\nclean does not take a path argument\n");
294298
usage(1, &opts, &subcommand_help, &extra_help);
295299
}
296-
Subcommand::Clean
300+
301+
Subcommand::Clean {
302+
all: matches.opt_present("all"),
303+
}
297304
}
298305
"dist" => {
299306
Subcommand::Dist {

src/bootstrap/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ impl Build {
345345
job::setup(self);
346346
}
347347

348-
if let Subcommand::Clean = self.config.cmd {
349-
return clean::clean(self);
348+
if let Subcommand::Clean { all } = self.config.cmd {
349+
return clean::clean(self, all);
350350
}
351351

352352
self.verbose("finding compilers");

0 commit comments

Comments
 (0)