Rollup merge of #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 #44214.

r? @Mark-Simulacrum
This commit is contained in:
Mark Simulacrum 2017-09-29 17:58:54 -06:00 committed by GitHub
commit 6bc8ca06c1
4 changed files with 37 additions and 25 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,8 +21,12 @@ 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());
if all {
rm_rf(&build.out);
} else {
rm_rf(&build.out.join("tmp")); rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist")); rm_rf(&build.out.join("dist"));
@ -42,6 +46,7 @@ pub fn clean(build: &Build) {
} }
} }
} }
}
fn rm_rf(path: &Path) { fn rm_rf(path: &Path) {
match path.symlink_metadata() { match path.symlink_metadata() {

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"); },
_ => { }, _ => { },
}; };
@ -250,7 +253,7 @@ Arguments:
} }
}); });
// All subcommands can have an optional "Available paths" section // All subcommands except `clean` can have an optional "Available paths" section
if matches.opt_present("verbose") { if matches.opt_present("verbose") {
let config = Config::parse(&["build".to_string()]); let config = Config::parse(&["build".to_string()]);
let mut build = Build::new(config); let mut build = Build::new(config);
@ -258,8 +261,9 @@ Arguments:
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str()); let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());
} else { } else if subcommand.as_str() != "clean" {
extra_help.push_str(format!("Run `./x.py {} -h -v` to see a list of available paths.", extra_help.push_str(format!(
"Run `./x.py {} -h -v` to see a list of available paths.",
subcommand).as_str()); subcommand).as_str());
} }
@ -290,10 +294,13 @@ Arguments:
} }
"clean" => { "clean" => {
if paths.len() > 0 { if paths.len() > 0 {
println!("\nclean takes no arguments\n"); println!("\nclean does not take a path argument\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");