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}
```
This commit is contained in:
Joshua Nelson 2022-12-29 20:57:54 +00:00
parent e37ff7e71a
commit cbede85538
3 changed files with 40 additions and 16 deletions

View file

@ -109,6 +109,25 @@ impl RunConfig<'_> {
}
}
/// A description of the crates in this set, suitable for passing to `builder.info`.
///
/// `crates` should be generated by [`RunConfig::cargo_crates_in_set`].
pub fn crate_description(crates: Interned<Vec<String>>) -> String {
if crates.is_empty() {
return "".into();
}
let mut descr = String::from(": {");
for krate in &*crates {
write!(descr, "{}, ", krate.strip_prefix("-p=").unwrap()).unwrap();
}
descr.pop();
descr.pop();
descr.push('}');
descr
}
struct StepDescription {
default: bool,
only_hosts: bool,

View file

@ -9,11 +9,10 @@ use std::fs;
use std::io::{self, ErrorKind};
use std::path::Path;
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
use crate::cache::Interned;
use crate::config::TargetSelection;
use crate::util::t;
use crate::{Build, Mode, Subcommand};
use crate::{Build, Compiler, Mode, Subcommand};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CleanAll {}
@ -40,7 +39,7 @@ macro_rules! clean_crate_tree {
( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $(
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct $name {
target: TargetSelection,
compiler: Compiler,
crates: Interned<Vec<String>>,
}
@ -54,22 +53,21 @@ macro_rules! clean_crate_tree {
fn make_run(run: RunConfig<'_>) {
let builder = run.builder;
if builder.top_stage != 0 {
panic!("non-stage-0 clean not supported for individual crates");
}
builder.ensure(Self { crates: run.cargo_crates_in_set(), target: run.target });
let compiler = builder.compiler(builder.top_stage, run.target);
builder.ensure(Self { crates: run.cargo_crates_in_set(), compiler });
}
fn run(self, builder: &Builder<'_>) -> Self::Output {
let compiler = builder.compiler(0, self.target);
let mut cargo = builder.bare_cargo(compiler, $mode, self.target, "clean");
let compiler = self.compiler;
let target = compiler.host;
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
for krate in &*self.crates {
cargo.arg(krate);
}
builder.info(&format!(
"Cleaning stage{} {} artifacts ({} -> {})",
compiler.stage, stringify!($name).to_lowercase(), &compiler.host, self.target
"Cleaning stage{} {} artifacts ({} -> {}){}",
compiler.stage, stringify!($name).to_lowercase(), &compiler.host, target, crate_description(self.crates),
));
// NOTE: doesn't use `run_cargo` because we don't want to save a stamp file,

View file

@ -18,6 +18,7 @@ use std::str;
use serde::Deserialize;
use crate::builder::crate_description;
use crate::builder::Cargo;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
@ -128,8 +129,11 @@ impl Step for Std {
std_cargo(builder, target, compiler.stage, &mut cargo);
builder.info(&format!(
"Building stage{} std artifacts ({} -> {})",
compiler.stage, &compiler.host, target
"Building stage{} std artifacts ({} -> {}){}",
compiler.stage,
&compiler.host,
target,
crate_description(self.crates),
));
run_cargo(
builder,
@ -715,8 +719,11 @@ impl Step for Rustc {
}
builder.info(&format!(
"Building stage{} compiler artifacts ({} -> {})",
compiler.stage, &compiler.host, target
"Building stage{} compiler artifacts ({} -> {}){}",
compiler.stage,
&compiler.host,
target,
crate_description(self.crates),
));
run_cargo(
builder,