Skip to content

Commit cbede85

Browse files
committed
Support x clean --stage 1 rustc_query_impl
Previously, clean only supported `--stage 0` for specific crates. The new `crate_description` function generates a string that looks like ``` : {rustc_query_impl} ```
1 parent e37ff7e commit cbede85

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

src/bootstrap/builder.rs

+19
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ impl RunConfig<'_> {
109109
}
110110
}
111111

112+
/// A description of the crates in this set, suitable for passing to `builder.info`.
113+
///
114+
/// `crates` should be generated by [`RunConfig::cargo_crates_in_set`].
115+
pub fn crate_description(crates: Interned<Vec<String>>) -> String {
116+
if crates.is_empty() {
117+
return "".into();
118+
}
119+
120+
let mut descr = String::from(": {");
121+
for krate in &*crates {
122+
write!(descr, "{}, ", krate.strip_prefix("-p=").unwrap()).unwrap();
123+
}
124+
125+
descr.pop();
126+
descr.pop();
127+
descr.push('}');
128+
descr
129+
}
130+
112131
struct StepDescription {
113132
default: bool,
114133
only_hosts: bool,

src/bootstrap/clean.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use std::fs;
99
use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

12-
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
12+
use crate::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
1313
use crate::cache::Interned;
14-
use crate::config::TargetSelection;
1514
use crate::util::t;
16-
use crate::{Build, Mode, Subcommand};
15+
use crate::{Build, Compiler, Mode, Subcommand};
1716

1817
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1918
pub struct CleanAll {}
@@ -40,7 +39,7 @@ macro_rules! clean_crate_tree {
4039
( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $(
4140
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4241
pub struct $name {
43-
target: TargetSelection,
42+
compiler: Compiler,
4443
crates: Interned<Vec<String>>,
4544
}
4645

@@ -54,22 +53,21 @@ macro_rules! clean_crate_tree {
5453

5554
fn make_run(run: RunConfig<'_>) {
5655
let builder = run.builder;
57-
if builder.top_stage != 0 {
58-
panic!("non-stage-0 clean not supported for individual crates");
59-
}
60-
builder.ensure(Self { crates: run.cargo_crates_in_set(), target: run.target });
56+
let compiler = builder.compiler(builder.top_stage, run.target);
57+
builder.ensure(Self { crates: run.cargo_crates_in_set(), compiler });
6158
}
6259

6360
fn run(self, builder: &Builder<'_>) -> Self::Output {
64-
let compiler = builder.compiler(0, self.target);
65-
let mut cargo = builder.bare_cargo(compiler, $mode, self.target, "clean");
61+
let compiler = self.compiler;
62+
let target = compiler.host;
63+
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
6664
for krate in &*self.crates {
6765
cargo.arg(krate);
6866
}
6967

7068
builder.info(&format!(
71-
"Cleaning stage{} {} artifacts ({} -> {})",
72-
compiler.stage, stringify!($name).to_lowercase(), &compiler.host, self.target
69+
"Cleaning stage{} {} artifacts ({} -> {}){}",
70+
compiler.stage, stringify!($name).to_lowercase(), &compiler.host, target, crate_description(self.crates),
7371
));
7472

7573
// NOTE: doesn't use `run_cargo` because we don't want to save a stamp file,

src/bootstrap/compile.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::str;
1818

1919
use serde::Deserialize;
2020

21+
use crate::builder::crate_description;
2122
use crate::builder::Cargo;
2223
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2324
use crate::cache::{Interned, INTERNER};
@@ -128,8 +129,11 @@ impl Step for Std {
128129
std_cargo(builder, target, compiler.stage, &mut cargo);
129130

130131
builder.info(&format!(
131-
"Building stage{} std artifacts ({} -> {})",
132-
compiler.stage, &compiler.host, target
132+
"Building stage{} std artifacts ({} -> {}){}",
133+
compiler.stage,
134+
&compiler.host,
135+
target,
136+
crate_description(self.crates),
133137
));
134138
run_cargo(
135139
builder,
@@ -715,8 +719,11 @@ impl Step for Rustc {
715719
}
716720

717721
builder.info(&format!(
718-
"Building stage{} compiler artifacts ({} -> {})",
719-
compiler.stage, &compiler.host, target
722+
"Building stage{} compiler artifacts ({} -> {}){}",
723+
compiler.stage,
724+
&compiler.host,
725+
target,
726+
crate_description(self.crates),
720727
));
721728
run_cargo(
722729
builder,

0 commit comments

Comments
 (0)