Skip to content

Commit a1c13d0

Browse files
committed
bootstrap: Add a --clean flag
Also add a `clean` target for the makefiles to blow away everything related to the build. Note that this specifically does not tamper with: * the LLVM build directory * the directory of the bootstrap system * the cached downloads of cargo/rustc
1 parent 4b2c703 commit a1c13d0

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/bootstrap/build/clean.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::fs;
12+
use std::path::Path;
13+
14+
use build::Build;
15+
16+
pub fn clean(build: &Build) {
17+
for host in build.config.host.iter() {
18+
19+
let out = build.out.join(host);
20+
21+
rm_rf(build, &out.join("compiler-rt"));
22+
23+
for stage in 0..4 {
24+
rm_rf(build, &out.join(format!("stage{}", stage)));
25+
rm_rf(build, &out.join(format!("stage{}-std", stage)));
26+
rm_rf(build, &out.join(format!("stage{}-rustc", stage)));
27+
}
28+
}
29+
}
30+
31+
fn rm_rf(build: &Build, path: &Path) {
32+
if path.exists() {
33+
build.verbose(&format!("removing `{}`", path.display()));
34+
t!(fs::remove_dir_all(path));
35+
}
36+
}

src/bootstrap/build/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Flags {
2626
pub src: Option<PathBuf>,
2727
pub jobs: Option<u32>,
2828
pub args: Vec<String>,
29+
pub clean: bool,
2930
}
3031

3132
pub struct Filter {
@@ -44,6 +45,7 @@ impl Flags {
4445
opts.optopt("", "stage", "stage to build", "N");
4546
opts.optopt("", "src", "path to repo root", "DIR");
4647
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
48+
opts.optflag("", "clean", "clean output directory");
4749
opts.optflag("h", "help", "print this help message");
4850

4951
let usage = |n| -> ! {
@@ -75,6 +77,7 @@ impl Flags {
7577

7678
Flags {
7779
verbose: m.opt_present("v"),
80+
clean: m.opt_present("clean"),
7881
stage: m.opt_str("stage").map(|j| j.parse().unwrap()),
7982
build: m.opt_str("build").unwrap(),
8083
host: Filter { values: m.opt_strs("host") },

src/bootstrap/build/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ macro_rules! t {
3030

3131
mod cc;
3232
mod channel;
33+
mod clean;
3334
mod compile;
3435
mod config;
3536
mod flags;
@@ -122,6 +123,10 @@ impl Build {
122123
#[cfg(not(windows))] fn setup_job() {}
123124
setup_job();
124125

126+
if self.flags.clean {
127+
return clean::clean(self);
128+
}
129+
125130
cc::find(self);
126131
sanity::check(self);
127132
channel::collect(self);

src/bootstrap/mk/Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ BOOTSTRAP := $(CFG_PYTHON) $(CFG_SRC_DIR)src/bootstrap/bootstrap.py $(BOOTSTRAP_
2121

2222
all:
2323
$(Q)$(BOOTSTRAP)
24+
25+
clean:
26+
$(Q)$(BOOTSTRAP) --clean

0 commit comments

Comments
 (0)