1
Fork 0

Add --all flag to ./x.py clean

This flag removes all build artifacts, including the LLVM build
directory.
This commit is contained in:
Tommy Ip 2017-09-20 18:14:19 +01:00
parent 4cdb36262b
commit 2c78bb49fd
4 changed files with 31 additions and 20 deletions

View file

@ -306,7 +306,7 @@ impl<'a> Builder<'a> {
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]), Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]), Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]), Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
Subcommand::Clean => panic!(), Subcommand::Clean { .. } => panic!(),
}; };
let builder = Builder { let builder = Builder {

View file

@ -13,7 +13,7 @@
//! Responsible for cleaning out a build directory of all old and stale //! Responsible for cleaning out a build directory of all old and stale
//! artifacts to prepare for a fresh build. Currently doesn't remove the //! artifacts to prepare for a fresh build. Currently doesn't remove the
//! `build/cache` directory (download cache) or the `build/$target/llvm` //! `build/cache` directory (download cache) or the `build/$target/llvm`
//! directory as we want that cached between builds. //! directory unless the --all flag is present.
use std::fs; use std::fs;
use std::io::{self, ErrorKind}; use std::io::{self, ErrorKind};
@ -21,24 +21,29 @@ use std::path::Path;
use Build; use Build;
pub fn clean(build: &Build) { pub fn clean(build: &Build, all: bool) {
rm_rf("tmp".as_ref()); rm_rf("tmp".as_ref());
rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist"));
for host in &build.hosts { if all {
let entries = match build.out.join(host).read_dir() { rm_rf(&build.out);
Ok(iter) => iter, } else {
Err(_) => continue, rm_rf(&build.out.join("tmp"));
}; rm_rf(&build.out.join("dist"));
for entry in entries { for host in &build.hosts {
let entry = t!(entry); let entries = match build.out.join(host).read_dir() {
if entry.file_name().to_str() == Some("llvm") { Ok(iter) => iter,
continue Err(_) => continue,
};
for entry in entries {
let entry = t!(entry);
if entry.file_name().to_str() == Some("llvm") {
continue
}
let path = t!(entry.path().canonicalize());
rm_rf(&path);
} }
let path = t!(entry.path().canonicalize());
rm_rf(&path);
} }
} }
} }

View file

@ -60,7 +60,9 @@ pub enum Subcommand {
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
test_args: Vec<String>, test_args: Vec<String>,
}, },
Clean, Clean {
all: bool,
},
Dist { Dist {
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
}, },
@ -147,6 +149,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
opts.optmulti("", "test-args", "extra arguments", "ARGS"); opts.optmulti("", "test-args", "extra arguments", "ARGS");
}, },
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, "bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
"clean" => { opts.optflag("", "all", "clean all build artifacts"); },
_ => { }, _ => { },
}; };
@ -293,7 +296,10 @@ Arguments:
println!("\nclean takes no arguments\n"); println!("\nclean takes no arguments\n");
usage(1, &opts, &subcommand_help, &extra_help); usage(1, &opts, &subcommand_help, &extra_help);
} }
Subcommand::Clean
Subcommand::Clean {
all: matches.opt_present("all"),
}
} }
"dist" => { "dist" => {
Subcommand::Dist { Subcommand::Dist {

View file

@ -345,8 +345,8 @@ impl Build {
job::setup(self); job::setup(self);
} }
if let Subcommand::Clean = self.config.cmd { if let Subcommand::Clean { all } = self.config.cmd {
return clean::clean(self); return clean::clean(self, all);
} }
self.verbose("finding compilers"); self.verbose("finding compilers");