Skip to content

Commit 430e85a

Browse files
authored
Rollup merge of #106305 - jyn514:tail-args, r=Mark-Simulacrum
bootstrap: Get rid of tail_args in stream_cargo Based on #106303 for convenience. r? `@Mark-Simulacrum`
2 parents 14ff27f + 9dfe504 commit 430e85a

File tree

7 files changed

+82
-77
lines changed

7 files changed

+82
-77
lines changed

src/bootstrap/builder.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,36 @@ impl RunConfig<'_> {
9797
self.builder.build.build
9898
}
9999

100-
/// Return a `-p=x -p=y` string suitable for passing to a cargo invocation.
100+
/// Return a list of crate names selected by `run.paths`.
101101
pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> {
102102
let mut crates = Vec::new();
103103
for krate in &self.paths {
104104
let path = krate.assert_single_path();
105105
let crate_name = self.builder.crate_paths[&path.path];
106-
crates.push(format!("-p={crate_name}"));
106+
crates.push(crate_name.to_string());
107107
}
108108
INTERNER.intern_list(crates)
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: &[impl AsRef<str>]) -> String {
116+
if crates.is_empty() {
117+
return "".into();
118+
}
119+
120+
let mut descr = String::from(" {");
121+
descr.push_str(crates[0].as_ref());
122+
for krate in &crates[1..] {
123+
descr.push_str(", ");
124+
descr.push_str(krate.as_ref());
125+
}
126+
descr.push('}');
127+
descr
128+
}
129+
112130
struct StepDescription {
113131
default: bool,
114132
only_hosts: bool,

src/bootstrap/check.rs

+14-29
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,13 @@ impl Step for Std {
9999
cargo_subcommand(builder.kind),
100100
);
101101
std_cargo(builder, target, compiler.stage, &mut cargo);
102+
cargo.args(args(builder));
102103

103104
builder.info(&format!(
104-
"Checking stage{} std artifacts ({} -> {})",
105+
"Checking stage{} library artifacts ({} -> {})",
105106
builder.top_stage, &compiler.host, target
106107
));
107-
run_cargo(
108-
builder,
109-
cargo,
110-
args(builder),
111-
&libstd_stamp(builder, compiler, target),
112-
vec![],
113-
true,
114-
);
108+
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), vec![], true);
115109

116110
// We skip populating the sysroot in non-zero stage because that'll lead
117111
// to rlib/rmeta conflicts if std gets built during this session.
@@ -155,19 +149,13 @@ impl Step for Std {
155149
for krate in builder.in_tree_crates("test", Some(target)) {
156150
cargo.arg("-p").arg(krate.name);
157151
}
152+
cargo.args(args(builder));
158153

159154
builder.info(&format!(
160-
"Checking stage{} std test/bench/example targets ({} -> {})",
155+
"Checking stage{} library test/bench/example targets ({} -> {})",
161156
builder.top_stage, &compiler.host, target
162157
));
163-
run_cargo(
164-
builder,
165-
cargo,
166-
args(builder),
167-
&libstd_test_stamp(builder, compiler, target),
168-
vec![],
169-
true,
170-
);
158+
run_cargo(builder, cargo, &libstd_test_stamp(builder, compiler, target), vec![], true);
171159
}
172160
}
173161

@@ -231,19 +219,13 @@ impl Step for Rustc {
231219
for krate in builder.in_tree_crates("rustc-main", Some(target)) {
232220
cargo.arg("-p").arg(krate.name);
233221
}
222+
cargo.args(args(builder));
234223

235224
builder.info(&format!(
236225
"Checking stage{} compiler artifacts ({} -> {})",
237226
builder.top_stage, &compiler.host, target
238227
));
239-
run_cargo(
240-
builder,
241-
cargo,
242-
args(builder),
243-
&librustc_stamp(builder, compiler, target),
244-
vec![],
245-
true,
246-
);
228+
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], true);
247229

248230
let libdir = builder.sysroot_libdir(compiler, target);
249231
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
@@ -290,6 +272,7 @@ impl Step for CodegenBackend {
290272
.arg("--manifest-path")
291273
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
292274
rustc_cargo_env(builder, &mut cargo, target);
275+
cargo.args(args(builder));
293276

294277
builder.info(&format!(
295278
"Checking stage{} {} artifacts ({} -> {})",
@@ -299,7 +282,6 @@ impl Step for CodegenBackend {
299282
run_cargo(
300283
builder,
301284
cargo,
302-
args(builder),
303285
&codegen_backend_stamp(builder, compiler, target, backend),
304286
vec![],
305287
true,
@@ -355,11 +337,13 @@ impl Step for RustAnalyzer {
355337
cargo.arg("--benches");
356338
}
357339

340+
cargo.args(args(builder));
341+
358342
builder.info(&format!(
359343
"Checking stage{} {} artifacts ({} -> {})",
360344
compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple
361345
));
362-
run_cargo(builder, cargo, args(builder), &stamp(builder, compiler, target), vec![], true);
346+
run_cargo(builder, cargo, &stamp(builder, compiler, target), vec![], true);
363347

364348
/// Cargo's output path in a given stage, compiled by a particular
365349
/// compiler for the specified target.
@@ -413,6 +397,8 @@ macro_rules! tool_check_step {
413397
cargo.arg("--all-targets");
414398
}
415399

400+
cargo.args(args(builder));
401+
416402
// Enable internal lints for clippy and rustdoc
417403
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
418404
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
@@ -428,7 +414,6 @@ macro_rules! tool_check_step {
428414
run_cargo(
429415
builder,
430416
cargo,
431-
args(builder),
432417
&stamp(builder, compiler, target),
433418
vec![],
434419
true,

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+
crate_description(&self.crates), compiler.stage, stringify!($name).to_lowercase(), &compiler.host, target,
7371
));
7472

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

src/bootstrap/compile.rs

+27-30
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};
@@ -110,7 +111,10 @@ impl Step for Std {
110111
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
111112
if compiler_to_use != compiler {
112113
builder.ensure(Std::new(compiler_to_use, target));
113-
builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target));
114+
builder.info(&format!(
115+
"Uplifting stage1 library ({} -> {})",
116+
compiler_to_use.host, target
117+
));
114118

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

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

130137
builder.info(&format!(
131-
"Building stage{} std artifacts ({} -> {})",
132-
compiler.stage, &compiler.host, target
138+
"Building{} stage{} library artifacts ({} -> {})",
139+
crate_description(&self.crates),
140+
compiler.stage,
141+
&compiler.host,
142+
target,
133143
));
134-
run_cargo(
135-
builder,
136-
cargo,
137-
self.crates.to_vec(),
138-
&libstd_stamp(builder, compiler, target),
139-
target_deps,
140-
false,
141-
);
144+
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), target_deps, false);
142145

143146
builder.ensure(StdLink::from_std(
144147
self,
@@ -425,7 +428,7 @@ impl Step for StdLink {
425428
let target_compiler = self.target_compiler;
426429
let target = self.target;
427430
builder.info(&format!(
428-
"Copying stage{} std from stage{} ({} -> {} / {})",
431+
"Copying stage{} library from stage{} ({} -> {} / {})",
429432
target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target
430433
));
431434
let libdir = builder.sysroot_libdir(target_compiler, target);
@@ -714,18 +717,18 @@ impl Step for Rustc {
714717
}
715718
}
716719

720+
for krate in &*self.crates {
721+
cargo.arg("-p").arg(krate);
722+
}
723+
717724
builder.info(&format!(
718-
"Building stage{} compiler artifacts ({} -> {})",
719-
compiler.stage, &compiler.host, target
725+
"Building{} stage{} compiler artifacts ({} -> {})",
726+
crate_description(&self.crates),
727+
compiler.stage,
728+
&compiler.host,
729+
target,
720730
));
721-
run_cargo(
722-
builder,
723-
cargo,
724-
self.crates.to_vec(),
725-
&librustc_stamp(builder, compiler, target),
726-
vec![],
727-
false,
728-
);
731+
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], false);
729732

730733
builder.ensure(RustcLink::from_rustc(
731734
self,
@@ -981,7 +984,7 @@ impl Step for CodegenBackend {
981984
"Building stage{} codegen backend {} ({} -> {})",
982985
compiler.stage, backend, &compiler.host, target
983986
));
984-
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false);
987+
let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false);
985988
if builder.config.dry_run() {
986989
return;
987990
}
@@ -1405,7 +1408,6 @@ pub fn add_to_sysroot(
14051408
pub fn run_cargo(
14061409
builder: &Builder<'_>,
14071410
cargo: Cargo,
1408-
tail_args: Vec<String>,
14091411
stamp: &Path,
14101412
additional_target_deps: Vec<(PathBuf, DependencyType)>,
14111413
is_check: bool,
@@ -1431,7 +1433,7 @@ pub fn run_cargo(
14311433
// files we need to probe for later.
14321434
let mut deps = Vec::new();
14331435
let mut toplevel = Vec::new();
1434-
let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| {
1436+
let ok = stream_cargo(builder, cargo, &mut |msg| {
14351437
let (filenames, crate_types) = match msg {
14361438
CargoMessage::CompilerArtifact {
14371439
filenames,
@@ -1546,7 +1548,6 @@ pub fn run_cargo(
15461548
pub fn stream_cargo(
15471549
builder: &Builder<'_>,
15481550
cargo: Cargo,
1549-
tail_args: Vec<String>,
15501551
cb: &mut dyn FnMut(CargoMessage<'_>),
15511552
) -> bool {
15521553
let mut cargo = Command::from(cargo);
@@ -1566,10 +1567,6 @@ pub fn stream_cargo(
15661567
}
15671568
cargo.arg("--message-format").arg(message_format).stdout(Stdio::piped());
15681569

1569-
for arg in tail_args {
1570-
cargo.arg(arg);
1571-
}
1572-
15731570
builder.verbose(&format!("running: {:?}", cargo));
15741571
let mut child = match cargo.spawn() {
15751572
Ok(child) => child,

src/bootstrap/doc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::fs;
1212
use std::io;
1313
use std::path::{Path, PathBuf};
1414

15+
use crate::builder::crate_description;
1516
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1617
use crate::cache::{Interned, INTERNER};
1718
use crate::compile;
@@ -558,7 +559,8 @@ fn doc_std(
558559
requested_crates: &[String],
559560
) {
560561
builder.info(&format!(
561-
"Documenting stage{} std ({}) in {} format",
562+
"Documenting{} stage{} library ({}) in {} format",
563+
crate_description(requested_crates),
562564
stage,
563565
target,
564566
format.as_str()

src/bootstrap/test.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::iter;
1111
use std::path::{Path, PathBuf};
1212
use std::process::{Command, Stdio};
1313

14+
use crate::builder::crate_description;
1415
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1516
use crate::cache::Interned;
1617
use crate::compile;
@@ -2154,8 +2155,12 @@ impl Step for Crate {
21542155
}
21552156

21562157
builder.info(&format!(
2157-
"{} {:?} stage{} ({} -> {})",
2158-
test_kind, self.crates, compiler.stage, &compiler.host, target
2158+
"{}{} stage{} ({} -> {})",
2159+
test_kind,
2160+
crate_description(&self.crates),
2161+
compiler.stage,
2162+
&compiler.host,
2163+
target
21592164
));
21602165
let _time = util::timeit(&builder);
21612166
try_run(builder, &mut cargo.into());

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Step for ToolBuild {
7272

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

0 commit comments

Comments
 (0)