From cbede85538d3ee59819c5d069ffe8d2dd7931749 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 29 Dec 2022 20:57:54 +0000 Subject: [PATCH] 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} ``` --- src/bootstrap/builder.rs | 19 +++++++++++++++++++ src/bootstrap/clean.rs | 22 ++++++++++------------ src/bootstrap/compile.rs | 15 +++++++++++---- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 707e4169002d9..97b353b5462f5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -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>) -> 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, diff --git a/src/bootstrap/clean.rs b/src/bootstrap/clean.rs index 8e363ee1290ee..d887495d633f0 100644 --- a/src/bootstrap/clean.rs +++ b/src/bootstrap/clean.rs @@ -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>, } @@ -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, diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 1030247b890c3..5bf5683f85dea 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -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,