Skip to content

Use more consistent progress messages in bootstrap #106303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,36 @@ impl RunConfig<'_> {
self.builder.build.build
}

/// Return a `-p=x -p=y` string suitable for passing to a cargo invocation.
/// Return a list of crate names selected by `run.paths`.
pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> {
let mut crates = Vec::new();
for krate in &self.paths {
let path = krate.assert_single_path();
let crate_name = self.builder.crate_paths[&path.path];
crates.push(format!("-p={crate_name}"));
crates.push(crate_name.to_string());
}
INTERNER.intern_list(crates)
}
}

/// 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: &[impl AsRef<str>]) -> String {
if crates.is_empty() {
return "".into();
}

let mut descr = String::from(" {");
descr.push_str(crates[0].as_ref());
for krate in &crates[1..] {
descr.push_str(", ");
descr.push_str(krate.as_ref());
}
descr.push('}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this seems like it could be near-identically replicated with https://doc.rust-lang.org/nightly/std/fmt/struct.DebugSet.html, at the cost of {"rustc_interface"} rather than {rustc_interface}.

But 🤷 either way -- the implementation is pretty simple.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the fmt::Debug* types only work inside a fmt::Debug impl unfortunately, since we need access to a fmt::Formatter 😞 and at that point it doesn't make the code much shorter.

descr
}

struct StepDescription {
default: bool,
only_hosts: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Step for Std {
std_cargo(builder, target, compiler.stage, &mut cargo);

builder.info(&format!(
"Checking stage{} std artifacts ({} -> {})",
"Checking stage{} library artifacts ({} -> {})",
builder.top_stage, &compiler.host, target
));
run_cargo(
Expand Down Expand Up @@ -157,7 +157,7 @@ impl Step for Std {
}

builder.info(&format!(
"Checking stage{} std test/bench/example targets ({} -> {})",
"Checking stage{} library test/bench/example targets ({} -> {})",
builder.top_stage, &compiler.host, target
));
run_cargo(
Expand Down
22 changes: 10 additions & 12 deletions src/bootstrap/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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>>,
}

Expand All @@ -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 ({} -> {})",
crate_description(&self.crates), compiler.stage, stringify!($name).to_lowercase(), &compiler.host, target,
));

// NOTE: doesn't use `run_cargo` because we don't want to save a stamp file,
Expand Down
33 changes: 25 additions & 8 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -110,7 +111,10 @@ impl Step for Std {
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
builder.ensure(Std::new(compiler_to_use, target));
builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target));
builder.info(&format!(
"Uplifting stage1 library ({} -> {})",
compiler_to_use.host, target
));

// Even if we're not building std this stage, the new sysroot must
// still contain the third party objects needed by various targets.
Expand All @@ -126,15 +130,21 @@ impl Step for Std {

let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
std_cargo(builder, target, compiler.stage, &mut cargo);
for krate in &*self.crates {
cargo.arg("-p").arg(krate);
}

builder.info(&format!(
"Building stage{} std artifacts ({} -> {})",
compiler.stage, &compiler.host, target
"Building{} stage{} library artifacts ({} -> {})",
crate_description(&self.crates),
compiler.stage,
&compiler.host,
target,
));
run_cargo(
builder,
cargo,
self.crates.to_vec(),
vec![],
&libstd_stamp(builder, compiler, target),
target_deps,
false,
Expand Down Expand Up @@ -425,7 +435,7 @@ impl Step for StdLink {
let target_compiler = self.target_compiler;
let target = self.target;
builder.info(&format!(
"Copying stage{} std from stage{} ({} -> {} / {})",
"Copying stage{} library from stage{} ({} -> {} / {})",
target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target
));
let libdir = builder.sysroot_libdir(target_compiler, target);
Expand Down Expand Up @@ -714,14 +724,21 @@ impl Step for Rustc {
}
}

for krate in &*self.crates {
cargo.arg("-p").arg(krate);
}

builder.info(&format!(
"Building stage{} compiler artifacts ({} -> {})",
compiler.stage, &compiler.host, target
"Building{} stage{} compiler artifacts ({} -> {})",
crate_description(&self.crates),
compiler.stage,
&compiler.host,
target,
));
run_cargo(
builder,
cargo,
self.crates.to_vec(),
vec![],
&librustc_stamp(builder, compiler, target),
vec![],
false,
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fs;
use std::io;
use std::path::{Path, PathBuf};

use crate::builder::crate_description;
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
use crate::compile;
Expand Down Expand Up @@ -554,7 +555,8 @@ fn doc_std(
requested_crates: &[String],
) {
builder.info(&format!(
"Documenting stage{} std ({}) in {} format",
"Documenting{} stage{} library ({}) in {} format",
crate_description(requested_crates),
stage,
target,
format.as_str()
Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::iter;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use crate::builder::crate_description;
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::cache::Interned;
use crate::compile;
Expand Down Expand Up @@ -2154,8 +2155,12 @@ impl Step for Crate {
}

builder.info(&format!(
"{} {:?} stage{} ({} -> {})",
test_kind, self.crates, compiler.stage, &compiler.host, target
"{}{} stage{} ({} -> {})",
test_kind,
crate_description(&self.crates),
compiler.stage,
&compiler.host,
target
));
let _time = util::timeit(&builder);
try_run(builder, &mut cargo.into());
Expand Down