Skip to content

Commit

Permalink
Rollup merge of rust-lang#44694 - tommyip:make_clean, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Add --all flag to ./x.py clean

This make `clean` removes the LLVM and download cache directory as well.

Fixes rust-lang#44214.

r? @Mark-Simulacrum
  • Loading branch information
Mark-Simulacrum authored Sep 29, 2017
2 parents 20f892f + 09d90e5 commit 6bc8ca0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'a> Builder<'a> {
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
Subcommand::Clean => panic!(),
Subcommand::Clean { .. } => panic!(),
};

let builder = Builder {
Expand Down
35 changes: 20 additions & 15 deletions src/bootstrap/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,37 @@
//! Responsible for cleaning out a build directory of all old and stale
//! artifacts to prepare for a fresh build. Currently doesn't remove the
//! `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::io::{self, ErrorKind};
use std::path::Path;

use Build;

pub fn clean(build: &Build) {
pub fn clean(build: &Build, all: bool) {
rm_rf("tmp".as_ref());
rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist"));

for host in &build.hosts {
let entries = match build.out.join(host).read_dir() {
Ok(iter) => iter,
Err(_) => continue,
};
if all {
rm_rf(&build.out);
} else {
rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist"));

for entry in entries {
let entry = t!(entry);
if entry.file_name().to_str() == Some("llvm") {
continue
for host in &build.hosts {
let entries = match build.out.join(host).read_dir() {
Ok(iter) => iter,
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);
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub enum Subcommand {
paths: Vec<PathBuf>,
test_args: Vec<String>,
},
Clean,
Clean {
all: bool,
},
Dist {
paths: Vec<PathBuf>,
},
Expand Down Expand Up @@ -147,6 +149,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
opts.optmulti("", "test-args", "extra arguments", "ARGS");
},
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
"clean" => { opts.optflag("", "all", "clean all build artifacts"); },
_ => { },
};

Expand Down Expand Up @@ -250,17 +253,18 @@ 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") {
let config = Config::parse(&["build".to_string()]);
let mut build = Build::new(config);
metadata::build(&mut build);

let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());
} else {
extra_help.push_str(format!("Run `./x.py {} -h -v` to see a list of available paths.",
subcommand).as_str());
} else if subcommand.as_str() != "clean" {
extra_help.push_str(format!(
"Run `./x.py {} -h -v` to see a list of available paths.",
subcommand).as_str());
}

// User passed in -h/--help?
Expand Down Expand Up @@ -290,10 +294,13 @@ Arguments:
}
"clean" => {
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);
}
Subcommand::Clean

Subcommand::Clean {
all: matches.opt_present("all"),
}
}
"dist" => {
Subcommand::Dist {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ impl Build {
job::setup(self);
}

if let Subcommand::Clean = self.config.cmd {
return clean::clean(self);
if let Subcommand::Clean { all } = self.config.cmd {
return clean::clean(self, all);
}

self.verbose("finding compilers");
Expand Down

0 comments on commit 6bc8ca0

Please sign in to comment.