Skip to content

Commit 2c78bb4

Browse files
committedSep 20, 2017
Add --all flag to ./x.py clean
This flag removes all build artifacts, including the LLVM build directory.
1 parent 4cdb362 commit 2c78bb4

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
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

+8-2
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

@@ -293,7 +296,10 @@ Arguments:
293296
println!("\nclean takes no arguments\n");
294297
usage(1, &opts, &subcommand_help, &extra_help);
295298
}
296-
Subcommand::Clean
299+
300+
Subcommand::Clean {
301+
all: matches.opt_present("all"),
302+
}
297303
}
298304
"dist" => {
299305
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)
Please sign in to comment.