1
Fork 0

Rollup merge of #106305 - jyn514:tail-args, r=Mark-Simulacrum

bootstrap: Get rid of tail_args in stream_cargo

Based on https://github.com/rust-lang/rust/pull/106303 for convenience.

r? ````@Mark-Simulacrum````
This commit is contained in:
Michael Goulet 2022-12-30 21:26:35 -08:00 committed by GitHub
commit 93032e8112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 77 deletions

View file

@ -97,18 +97,36 @@ impl RunConfig<'_> {
self.builder.build.build 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>> { pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> {
let mut crates = Vec::new(); let mut crates = Vec::new();
for krate in &self.paths { for krate in &self.paths {
let path = krate.assert_single_path(); let path = krate.assert_single_path();
let crate_name = self.builder.crate_paths[&path.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) 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('}');
descr
}
struct StepDescription { struct StepDescription {
default: bool, default: bool,
only_hosts: bool, only_hosts: bool,

View file

@ -99,19 +99,13 @@ impl Step for Std {
cargo_subcommand(builder.kind), cargo_subcommand(builder.kind),
); );
std_cargo(builder, target, compiler.stage, &mut cargo); std_cargo(builder, target, compiler.stage, &mut cargo);
cargo.args(args(builder));
builder.info(&format!( builder.info(&format!(
"Checking stage{} std artifacts ({} -> {})", "Checking stage{} library artifacts ({} -> {})",
builder.top_stage, &compiler.host, target builder.top_stage, &compiler.host, target
)); ));
run_cargo( run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), vec![], true);
builder,
cargo,
args(builder),
&libstd_stamp(builder, compiler, target),
vec![],
true,
);
// We skip populating the sysroot in non-zero stage because that'll lead // We skip populating the sysroot in non-zero stage because that'll lead
// to rlib/rmeta conflicts if std gets built during this session. // to rlib/rmeta conflicts if std gets built during this session.
@ -155,19 +149,13 @@ impl Step for Std {
for krate in builder.in_tree_crates("test", Some(target)) { for krate in builder.in_tree_crates("test", Some(target)) {
cargo.arg("-p").arg(krate.name); cargo.arg("-p").arg(krate.name);
} }
cargo.args(args(builder));
builder.info(&format!( builder.info(&format!(
"Checking stage{} std test/bench/example targets ({} -> {})", "Checking stage{} library test/bench/example targets ({} -> {})",
builder.top_stage, &compiler.host, target builder.top_stage, &compiler.host, target
)); ));
run_cargo( run_cargo(builder, cargo, &libstd_test_stamp(builder, compiler, target), vec![], true);
builder,
cargo,
args(builder),
&libstd_test_stamp(builder, compiler, target),
vec![],
true,
);
} }
} }
@ -231,19 +219,13 @@ impl Step for Rustc {
for krate in builder.in_tree_crates("rustc-main", Some(target)) { for krate in builder.in_tree_crates("rustc-main", Some(target)) {
cargo.arg("-p").arg(krate.name); cargo.arg("-p").arg(krate.name);
} }
cargo.args(args(builder));
builder.info(&format!( builder.info(&format!(
"Checking stage{} compiler artifacts ({} -> {})", "Checking stage{} compiler artifacts ({} -> {})",
builder.top_stage, &compiler.host, target builder.top_stage, &compiler.host, target
)); ));
run_cargo( run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], true);
builder,
cargo,
args(builder),
&librustc_stamp(builder, compiler, target),
vec![],
true,
);
let libdir = builder.sysroot_libdir(compiler, target); let libdir = builder.sysroot_libdir(compiler, target);
let hostdir = builder.sysroot_libdir(compiler, compiler.host); let hostdir = builder.sysroot_libdir(compiler, compiler.host);
@ -290,6 +272,7 @@ impl Step for CodegenBackend {
.arg("--manifest-path") .arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend))); .arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
rustc_cargo_env(builder, &mut cargo, target); rustc_cargo_env(builder, &mut cargo, target);
cargo.args(args(builder));
builder.info(&format!( builder.info(&format!(
"Checking stage{} {} artifacts ({} -> {})", "Checking stage{} {} artifacts ({} -> {})",
@ -299,7 +282,6 @@ impl Step for CodegenBackend {
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
args(builder),
&codegen_backend_stamp(builder, compiler, target, backend), &codegen_backend_stamp(builder, compiler, target, backend),
vec![], vec![],
true, true,
@ -355,11 +337,13 @@ impl Step for RustAnalyzer {
cargo.arg("--benches"); cargo.arg("--benches");
} }
cargo.args(args(builder));
builder.info(&format!( builder.info(&format!(
"Checking stage{} {} artifacts ({} -> {})", "Checking stage{} {} artifacts ({} -> {})",
compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple
)); ));
run_cargo(builder, cargo, args(builder), &stamp(builder, compiler, target), vec![], true); run_cargo(builder, cargo, &stamp(builder, compiler, target), vec![], true);
/// Cargo's output path in a given stage, compiled by a particular /// Cargo's output path in a given stage, compiled by a particular
/// compiler for the specified target. /// compiler for the specified target.
@ -413,6 +397,8 @@ macro_rules! tool_check_step {
cargo.arg("--all-targets"); cargo.arg("--all-targets");
} }
cargo.args(args(builder));
// Enable internal lints for clippy and rustdoc // Enable internal lints for clippy and rustdoc
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]` // NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776 // See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
@ -428,7 +414,6 @@ macro_rules! tool_check_step {
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
args(builder),
&stamp(builder, compiler, target), &stamp(builder, compiler, target),
vec![], vec![],
true, true,

View file

@ -9,11 +9,10 @@ use std::fs;
use std::io::{self, ErrorKind}; use std::io::{self, ErrorKind};
use std::path::Path; 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::cache::Interned;
use crate::config::TargetSelection;
use crate::util::t; use crate::util::t;
use crate::{Build, Mode, Subcommand}; use crate::{Build, Compiler, Mode, Subcommand};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CleanAll {} pub struct CleanAll {}
@ -40,7 +39,7 @@ macro_rules! clean_crate_tree {
( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $( ( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $(
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct $name { pub struct $name {
target: TargetSelection, compiler: Compiler,
crates: Interned<Vec<String>>, crates: Interned<Vec<String>>,
} }
@ -54,22 +53,21 @@ macro_rules! clean_crate_tree {
fn make_run(run: RunConfig<'_>) { fn make_run(run: RunConfig<'_>) {
let builder = run.builder; let builder = run.builder;
if builder.top_stage != 0 { let compiler = builder.compiler(builder.top_stage, run.target);
panic!("non-stage-0 clean not supported for individual crates"); builder.ensure(Self { crates: run.cargo_crates_in_set(), compiler });
}
builder.ensure(Self { crates: run.cargo_crates_in_set(), target: run.target });
} }
fn run(self, builder: &Builder<'_>) -> Self::Output { fn run(self, builder: &Builder<'_>) -> Self::Output {
let compiler = builder.compiler(0, self.target); let compiler = self.compiler;
let mut cargo = builder.bare_cargo(compiler, $mode, self.target, "clean"); let target = compiler.host;
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
for krate in &*self.crates { for krate in &*self.crates {
cargo.arg(krate); cargo.arg(krate);
} }
builder.info(&format!( builder.info(&format!(
"Cleaning stage{} {} artifacts ({} -> {})", "Cleaning{} stage{} {} artifacts ({} -> {})",
compiler.stage, stringify!($name).to_lowercase(), &compiler.host, self.target 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, // 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 serde::Deserialize;
use crate::builder::crate_description;
use crate::builder::Cargo; use crate::builder::Cargo;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER}; use crate::cache::{Interned, INTERNER};
@ -110,7 +111,10 @@ impl Step for Std {
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler { if compiler_to_use != compiler {
builder.ensure(Std::new(compiler_to_use, target)); 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 // Even if we're not building std this stage, the new sysroot must
// still contain the third party objects needed by various targets. // still contain the third party objects needed by various targets.
@ -126,19 +130,18 @@ impl Step for Std {
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build"); let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
std_cargo(builder, target, compiler.stage, &mut cargo); std_cargo(builder, target, compiler.stage, &mut cargo);
for krate in &*self.crates {
cargo.arg("-p").arg(krate);
}
builder.info(&format!( builder.info(&format!(
"Building stage{} std artifacts ({} -> {})", "Building{} stage{} library artifacts ({} -> {})",
compiler.stage, &compiler.host, target crate_description(&self.crates),
compiler.stage,
&compiler.host,
target,
)); ));
run_cargo( run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), target_deps, false);
builder,
cargo,
self.crates.to_vec(),
&libstd_stamp(builder, compiler, target),
target_deps,
false,
);
builder.ensure(StdLink::from_std( builder.ensure(StdLink::from_std(
self, self,
@ -425,7 +428,7 @@ impl Step for StdLink {
let target_compiler = self.target_compiler; let target_compiler = self.target_compiler;
let target = self.target; let target = self.target;
builder.info(&format!( builder.info(&format!(
"Copying stage{} std from stage{} ({} -> {} / {})", "Copying stage{} library from stage{} ({} -> {} / {})",
target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target
)); ));
let libdir = builder.sysroot_libdir(target_compiler, target); let libdir = builder.sysroot_libdir(target_compiler, target);
@ -714,18 +717,18 @@ impl Step for Rustc {
} }
} }
for krate in &*self.crates {
cargo.arg("-p").arg(krate);
}
builder.info(&format!( builder.info(&format!(
"Building stage{} compiler artifacts ({} -> {})", "Building{} stage{} compiler artifacts ({} -> {})",
compiler.stage, &compiler.host, target crate_description(&self.crates),
compiler.stage,
&compiler.host,
target,
)); ));
run_cargo( run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], false);
builder,
cargo,
self.crates.to_vec(),
&librustc_stamp(builder, compiler, target),
vec![],
false,
);
builder.ensure(RustcLink::from_rustc( builder.ensure(RustcLink::from_rustc(
self, self,
@ -981,7 +984,7 @@ impl Step for CodegenBackend {
"Building stage{} codegen backend {} ({} -> {})", "Building stage{} codegen backend {} ({} -> {})",
compiler.stage, backend, &compiler.host, target compiler.stage, backend, &compiler.host, target
)); ));
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false); let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false);
if builder.config.dry_run() { if builder.config.dry_run() {
return; return;
} }
@ -1405,7 +1408,6 @@ pub fn add_to_sysroot(
pub fn run_cargo( pub fn run_cargo(
builder: &Builder<'_>, builder: &Builder<'_>,
cargo: Cargo, cargo: Cargo,
tail_args: Vec<String>,
stamp: &Path, stamp: &Path,
additional_target_deps: Vec<(PathBuf, DependencyType)>, additional_target_deps: Vec<(PathBuf, DependencyType)>,
is_check: bool, is_check: bool,
@ -1431,7 +1433,7 @@ pub fn run_cargo(
// files we need to probe for later. // files we need to probe for later.
let mut deps = Vec::new(); let mut deps = Vec::new();
let mut toplevel = Vec::new(); let mut toplevel = Vec::new();
let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| { let ok = stream_cargo(builder, cargo, &mut |msg| {
let (filenames, crate_types) = match msg { let (filenames, crate_types) = match msg {
CargoMessage::CompilerArtifact { CargoMessage::CompilerArtifact {
filenames, filenames,
@ -1546,7 +1548,6 @@ pub fn run_cargo(
pub fn stream_cargo( pub fn stream_cargo(
builder: &Builder<'_>, builder: &Builder<'_>,
cargo: Cargo, cargo: Cargo,
tail_args: Vec<String>,
cb: &mut dyn FnMut(CargoMessage<'_>), cb: &mut dyn FnMut(CargoMessage<'_>),
) -> bool { ) -> bool {
let mut cargo = Command::from(cargo); let mut cargo = Command::from(cargo);
@ -1566,10 +1567,6 @@ pub fn stream_cargo(
} }
cargo.arg("--message-format").arg(message_format).stdout(Stdio::piped()); cargo.arg("--message-format").arg(message_format).stdout(Stdio::piped());
for arg in tail_args {
cargo.arg(arg);
}
builder.verbose(&format!("running: {:?}", cargo)); builder.verbose(&format!("running: {:?}", cargo));
let mut child = match cargo.spawn() { let mut child = match cargo.spawn() {
Ok(child) => child, Ok(child) => child,

View file

@ -12,6 +12,7 @@ use std::fs;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use crate::builder::crate_description;
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER}; use crate::cache::{Interned, INTERNER};
use crate::compile; use crate::compile;
@ -558,7 +559,8 @@ fn doc_std(
requested_crates: &[String], requested_crates: &[String],
) { ) {
builder.info(&format!( builder.info(&format!(
"Documenting stage{} std ({}) in {} format", "Documenting{} stage{} library ({}) in {} format",
crate_description(requested_crates),
stage, stage,
target, target,
format.as_str() format.as_str()

View file

@ -11,6 +11,7 @@ use std::iter;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::builder::crate_description;
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::cache::Interned; use crate::cache::Interned;
use crate::compile; use crate::compile;
@ -2154,8 +2155,12 @@ impl Step for Crate {
} }
builder.info(&format!( builder.info(&format!(
"{} {:?} stage{} ({} -> {})", "{}{} stage{} ({} -> {})",
test_kind, self.crates, compiler.stage, &compiler.host, target test_kind,
crate_description(&self.crates),
compiler.stage,
&compiler.host,
target
)); ));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, &mut cargo.into()); try_run(builder, &mut cargo.into());

View file

@ -72,7 +72,7 @@ impl Step for ToolBuild {
builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target)); builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target));
let mut duplicates = Vec::new(); let mut duplicates = Vec::new();
let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| { let is_expected = compile::stream_cargo(builder, cargo, &mut |msg| {
// Only care about big things like the RLS/Cargo for now // Only care about big things like the RLS/Cargo for now
match tool { match tool {
"rls" | "cargo" | "clippy-driver" | "miri" | "rustfmt" => {} "rls" | "cargo" | "clippy-driver" | "miri" | "rustfmt" => {}