]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/build/clean.rs
Imported Upstream version 1.11.0+dfsg1
[rustc.git] / src / bootstrap / build / clean.rs
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 //! Implementation of `make clean` in rustbuild.
12 //!
13 //! Responsible for cleaning out a build directory of all old and stale
14 //! artifacts to prepare for a fresh build. Currently doesn't remove the
15 //! `build/cache` directory (download cache) or the `build/$target/llvm`
16 //! directory as we want that cached between builds.
17
18 use std::fs;
19 use std::path::Path;
20
21 use build::Build;
22
23 pub fn clean(build: &Build) {
24 rm_rf(build, "tmp".as_ref());
25 rm_rf(build, &build.out.join("tmp"));
26
27 for host in build.config.host.iter() {
28
29 let out = build.out.join(host);
30
31 rm_rf(build, &out.join("compiler-rt"));
32 rm_rf(build, &out.join("doc"));
33
34 for stage in 0..4 {
35 rm_rf(build, &out.join(format!("stage{}", stage)));
36 rm_rf(build, &out.join(format!("stage{}-std", stage)));
37 rm_rf(build, &out.join(format!("stage{}-rustc", stage)));
38 rm_rf(build, &out.join(format!("stage{}-tools", stage)));
39 rm_rf(build, &out.join(format!("stage{}-test", stage)));
40 }
41 }
42 }
43
44 fn rm_rf(build: &Build, path: &Path) {
45 if path.exists() {
46 build.verbose(&format!("removing `{}`", path.display()));
47 t!(fs::remove_dir_all(path));
48 }
49 }