summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/clean.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /src/bootstrap/clean.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bootstrap/clean.rs')
-rw-r--r--src/bootstrap/clean.rs86
1 files changed, 64 insertions, 22 deletions
diff --git a/src/bootstrap/clean.rs b/src/bootstrap/clean.rs
index c1d867a0b..7389816b4 100644
--- a/src/bootstrap/clean.rs
+++ b/src/bootstrap/clean.rs
@@ -26,8 +26,15 @@ impl Step for CleanAll {
}
fn run(self, builder: &Builder<'_>) -> Self::Output {
- let Subcommand::Clean { all, .. } = builder.config.cmd else { unreachable!("wrong subcommand?") };
- clean_default(builder.build, all)
+ let Subcommand::Clean { all, stage } = builder.config.cmd else {
+ unreachable!("wrong subcommand?")
+ };
+
+ if all && stage.is_some() {
+ panic!("--all and --stage can't be used at the same time for `x clean`");
+ }
+
+ clean(builder.build, all, stage)
}
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -84,35 +91,70 @@ clean_crate_tree! {
Std, Mode::Std, "sysroot";
}
-fn clean_default(build: &Build, all: bool) {
+fn clean(build: &Build, all: bool, stage: Option<u32>) {
if build.config.dry_run() {
return;
}
rm_rf("tmp".as_ref());
+ // Clean the entire build directory
if all {
rm_rf(&build.out);
- } else {
- rm_rf(&build.out.join("tmp"));
- rm_rf(&build.out.join("dist"));
- rm_rf(&build.out.join("bootstrap"));
- rm_rf(&build.out.join("rustfmt.stamp"));
-
- for host in &build.hosts {
- let entries = match build.out.join(host.triple).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);
+ return;
+ }
+
+ // Clean the target stage artifacts
+ if let Some(stage) = stage {
+ clean_specific_stage(build, stage);
+ return;
+ }
+
+ // Follow the default behaviour
+ clean_default(build);
+}
+
+fn clean_specific_stage(build: &Build, stage: u32) {
+ for host in &build.hosts {
+ let entries = match build.out.join(host.triple).read_dir() {
+ Ok(iter) => iter,
+ Err(_) => continue,
+ };
+
+ for entry in entries {
+ let entry = t!(entry);
+ let stage_prefix = format!("stage{}", stage);
+
+ // if current entry is not related with the target stage, continue
+ if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) {
+ continue;
+ }
+
+ let path = t!(entry.path().canonicalize());
+ rm_rf(&path);
+ }
+ }
+}
+
+fn clean_default(build: &Build) {
+ rm_rf(&build.out.join("tmp"));
+ rm_rf(&build.out.join("dist"));
+ rm_rf(&build.out.join("bootstrap"));
+ rm_rf(&build.out.join("rustfmt.stamp"));
+
+ for host in &build.hosts {
+ let entries = match build.out.join(host.triple).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);
}
}
}