Skip to content

Commit 0585134

Browse files
authored
Rollup merge of rust-lang#133817 - clubby789:bootstrap-eprintln, r=jieyouxu
Use `eprintln` instead of `println` in bootstrap/compiletest/tidy A big unconditional CTRL-F replace to start with to check if there's anything that CI expects to be on stdout r? `@jieyouxu`
2 parents 5530869 + 8374f7c commit 0585134

34 files changed

+210
-206
lines changed

src/bootstrap/src/bin/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ fn main() {
4848
err => {
4949
drop(err);
5050
if let Ok(pid) = pid {
51-
println!("WARNING: build directory locked by process {pid}, waiting for lock");
51+
eprintln!("WARNING: build directory locked by process {pid}, waiting for lock");
5252
} else {
53-
println!("WARNING: build directory locked, waiting for lock");
53+
eprintln!("WARNING: build directory locked, waiting for lock");
5454
}
5555
let mut lock = t!(build_lock.write());
5656
t!(lock.write(process::id().to_string().as_ref()));
@@ -70,13 +70,13 @@ fn main() {
7070
// changelog warning, not the `x.py setup` message.
7171
let suggest_setup = config.config.is_none() && !matches!(config.cmd, Subcommand::Setup { .. });
7272
if suggest_setup {
73-
println!("WARNING: you have not made a `config.toml`");
74-
println!(
73+
eprintln!("WARNING: you have not made a `config.toml`");
74+
eprintln!(
7575
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
7676
`cp config.example.toml config.toml`"
7777
);
7878
} else if let Some(suggestion) = &changelog_suggestion {
79-
println!("{suggestion}");
79+
eprintln!("{suggestion}");
8080
}
8181

8282
let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
@@ -86,13 +86,13 @@ fn main() {
8686
Build::new(config).build();
8787

8888
if suggest_setup {
89-
println!("WARNING: you have not made a `config.toml`");
90-
println!(
89+
eprintln!("WARNING: you have not made a `config.toml`");
90+
eprintln!(
9191
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
9292
`cp config.example.toml config.toml`"
9393
);
9494
} else if let Some(suggestion) = &changelog_suggestion {
95-
println!("{suggestion}");
95+
eprintln!("{suggestion}");
9696
}
9797

9898
// Give a warning if the pre-commit script is in pre-commit and not pre-push.
@@ -102,14 +102,14 @@ fn main() {
102102
if fs::read_to_string(pre_commit).is_ok_and(|contents| {
103103
contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
104104
}) {
105-
println!(
105+
eprintln!(
106106
"WARNING: You have the pre-push script installed to .git/hooks/pre-commit. \
107107
Consider moving it to .git/hooks/pre-push instead, which runs less often."
108108
);
109109
}
110110

111111
if suggest_setup || changelog_suggestion.is_some() {
112-
println!("NOTE: this message was printed twice to make it more likely to be seen");
112+
eprintln!("NOTE: this message was printed twice to make it more likely to be seen");
113113
}
114114

115115
if dump_bootstrap_shims {

src/bootstrap/src/bin/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn main() {
306306
// should run on success, after this block.
307307
}
308308
if verbose > 0 {
309-
println!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
309+
eprintln!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
310310
}
311311

312312
if let Some(mut on_fail) = on_fail {

src/bootstrap/src/core/build_steps/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl Step for CodegenBackend {
287287
fn run(self, builder: &Builder<'_>) {
288288
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
289289
if builder.build.config.vendor && self.backend == "gcc" {
290-
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
290+
eprintln!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
291291
return;
292292
}
293293

src/bootstrap/src/core/build_steps/compile.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl Step for Sysroot {
16111611
let sysroot = sysroot_dir(compiler.stage);
16121612

16131613
builder
1614-
.verbose(|| println!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
1614+
.verbose(|| eprintln!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
16151615
let _ = fs::remove_dir_all(&sysroot);
16161616
t!(fs::create_dir_all(&sysroot));
16171617

@@ -1681,7 +1681,7 @@ impl Step for Sysroot {
16811681
return true;
16821682
}
16831683
if !filtered_files.iter().all(|f| f != path.file_name().unwrap()) {
1684-
builder.verbose_than(1, || println!("ignoring {}", path.display()));
1684+
builder.verbose_than(1, || eprintln!("ignoring {}", path.display()));
16851685
false
16861686
} else {
16871687
true
@@ -2240,7 +2240,7 @@ pub fn stream_cargo(
22402240
cargo.arg(arg);
22412241
}
22422242

2243-
builder.verbose(|| println!("running: {cargo:?}"));
2243+
builder.verbose(|| eprintln!("running: {cargo:?}"));
22442244

22452245
if builder.config.dry_run() {
22462246
return true;
@@ -2261,12 +2261,12 @@ pub fn stream_cargo(
22612261
Ok(msg) => {
22622262
if builder.config.json_output {
22632263
// Forward JSON to stdout.
2264-
println!("{line}");
2264+
eprintln!("{line}");
22652265
}
22662266
cb(msg)
22672267
}
22682268
// If this was informational, just print it out and continue
2269-
Err(_) => println!("{line}"),
2269+
Err(_) => eprintln!("{line}"),
22702270
}
22712271
}
22722272

src/bootstrap/src/core/build_steps/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ fn maybe_install_llvm(
20802080
{
20812081
let mut cmd = command(llvm_config);
20822082
cmd.arg("--libfiles");
2083-
builder.verbose(|| println!("running {cmd:?}"));
2083+
builder.verbose(|| eprintln!("running {cmd:?}"));
20842084
let files = cmd.run_capture_stdout(builder).stdout();
20852085
let build_llvm_out = &builder.llvm_out(builder.config.build);
20862086
let target_llvm_out = &builder.llvm_out(target);

src/bootstrap/src/core/build_steps/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
107107
if let Some(adjective) = adjective { format!("{adjective} ") } else { String::new() };
108108
if len <= 10 {
109109
for path in paths {
110-
println!("fmt: {verb} {adjective}file {path}");
110+
eprintln!("fmt: {verb} {adjective}file {path}");
111111
}
112112
} else {
113-
println!("fmt: {verb} {len} {adjective}files");
113+
eprintln!("fmt: {verb} {len} {adjective}files");
114114
}
115115
}
116116

@@ -199,7 +199,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
199199
match get_modified_rs_files(build) {
200200
Ok(Some(files)) => {
201201
if files.is_empty() {
202-
println!("fmt info: No modified files detected for formatting.");
202+
eprintln!("fmt info: No modified files detected for formatting.");
203203
return;
204204
}
205205

src/bootstrap/src/core/build_steps/setup.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Step for Profile {
134134
t!(fs::remove_file(path));
135135
}
136136
_ => {
137-
println!("Exiting.");
137+
eprintln!("Exiting.");
138138
crate::exit!(1);
139139
}
140140
}
@@ -184,15 +184,15 @@ pub fn setup(config: &Config, profile: Profile) {
184184
Profile::Dist => &["dist", "build"],
185185
};
186186

187-
println!();
187+
eprintln!();
188188

189-
println!("To get started, try one of the following commands:");
189+
eprintln!("To get started, try one of the following commands:");
190190
for cmd in suggestions {
191-
println!("- `x.py {cmd}`");
191+
eprintln!("- `x.py {cmd}`");
192192
}
193193

194194
if profile != Profile::Dist {
195-
println!(
195+
eprintln!(
196196
"For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html"
197197
);
198198
}
@@ -224,7 +224,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
224224
t!(fs::write(path, settings));
225225

226226
let include_path = profile.include_path(&config.src);
227-
println!("`x.py` will now use the configuration at {}", include_path.display());
227+
eprintln!("`x.py` will now use the configuration at {}", include_path.display());
228228
}
229229

230230
/// Creates a toolchain link for stage1 using `rustup`
@@ -256,7 +256,7 @@ impl Step for Link {
256256
}
257257

258258
if !rustup_installed(builder) {
259-
println!("WARNING: `rustup` is not installed; Skipping `stage1` toolchain linking.");
259+
eprintln!("WARNING: `rustup` is not installed; Skipping `stage1` toolchain linking.");
260260
return;
261261
}
262262

@@ -296,7 +296,7 @@ fn attempt_toolchain_link(builder: &Builder<'_>, stage_path: &str) {
296296
}
297297

298298
if try_link_toolchain(builder, stage_path) {
299-
println!(
299+
eprintln!(
300300
"Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
301301
);
302302
} else {
@@ -321,14 +321,14 @@ fn toolchain_is_linked(builder: &Builder<'_>) -> bool {
321321
return false;
322322
}
323323
// The toolchain has already been linked.
324-
println!(
324+
eprintln!(
325325
"`stage1` toolchain already linked; not attempting to link `stage1` toolchain"
326326
);
327327
}
328328
None => {
329329
// In this case, we don't know if the `stage1` toolchain has been linked;
330330
// but `rustup` failed, so let's not go any further.
331-
println!(
331+
eprintln!(
332332
"`rustup` failed to list current toolchains; not attempting to link `stage1` toolchain"
333333
);
334334
}
@@ -389,9 +389,9 @@ pub fn interactive_path() -> io::Result<Profile> {
389389
input.parse()
390390
}
391391

392-
println!("Welcome to the Rust project! What do you want to do with x.py?");
392+
eprintln!("Welcome to the Rust project! What do you want to do with x.py?");
393393
for ((letter, _), profile) in abbrev_all() {
394-
println!("{}) {}: {}", letter, profile, profile.purpose());
394+
eprintln!("{}) {}: {}", letter, profile, profile.purpose());
395395
}
396396
let template = loop {
397397
print!(
@@ -488,15 +488,15 @@ fn install_git_hook_maybe(builder: &Builder<'_>, config: &Config) -> io::Result<
488488
return Ok(());
489489
}
490490

491-
println!(
491+
eprintln!(
492492
"\nRust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
493493
If you'd like, x.py can install a git hook for you that will automatically run `test tidy` before
494494
pushing your code to ensure your code is up to par. If you decide later that this behavior is
495495
undesirable, simply delete the `pre-push` file from .git/hooks."
496496
);
497497

498498
if prompt_user("Would you like to install the git hook?: [y/N]")? != Some(PromptResult::Yes) {
499-
println!("Ok, skipping installation!");
499+
eprintln!("Ok, skipping installation!");
500500
return Ok(());
501501
}
502502
if !hooks_dir.exists() {
@@ -513,7 +513,7 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
513513
);
514514
return Err(e);
515515
}
516-
Ok(_) => println!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
516+
Ok(_) => eprintln!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
517517
};
518518
Ok(())
519519
}
@@ -654,7 +654,7 @@ impl Step for Editor {
654654
if let Some(editor_kind) = editor_kind {
655655
while !t!(create_editor_settings_maybe(config, editor_kind.clone())) {}
656656
} else {
657-
println!("Ok, skipping editor setup!");
657+
eprintln!("Ok, skipping editor setup!");
658658
}
659659
}
660660
Err(e) => eprintln!("Could not determine the editor: {e}"),
@@ -687,7 +687,7 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
687687
mismatched_settings = Some(false);
688688
}
689689
}
690-
println!(
690+
eprintln!(
691691
"\nx.py can automatically install the recommended `{settings_filename}` file for rustc development"
692692
);
693693

@@ -706,7 +706,7 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
706706
Some(PromptResult::Yes) => true,
707707
Some(PromptResult::Print) => false,
708708
_ => {
709-
println!("Ok, skipping settings!");
709+
eprintln!("Ok, skipping settings!");
710710
return Ok(true);
711711
}
712712
};
@@ -733,9 +733,9 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
733733
_ => "Created",
734734
};
735735
fs::write(&settings_path, editor.settings_template())?;
736-
println!("{verb} `{}`", settings_filename);
736+
eprintln!("{verb} `{}`", settings_filename);
737737
} else {
738-
println!("\n{}", editor.settings_template());
738+
eprintln!("\n{}", editor.settings_template());
739739
}
740740
Ok(should_create)
741741
}

src/bootstrap/src/core/build_steps/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
6666
build.build();
6767
}
6868
} else {
69-
println!("HELP: consider using the `--run` flag to automatically run suggested tests");
69+
eprintln!("HELP: consider using the `--run` flag to automatically run suggested tests");
7070
}
7171
}

src/bootstrap/src/core/build_steps/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,11 @@ impl Miri {
471471
// We re-use the `cargo` from above.
472472
cargo.arg("--print-sysroot");
473473

474-
builder.verbose(|| println!("running: {cargo:?}"));
474+
builder.verbose(|| eprintln!("running: {cargo:?}"));
475475
let stdout = cargo.run_capture_stdout(builder).stdout();
476476
// Output is "<sysroot>\n".
477477
let sysroot = stdout.trim_end();
478-
builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
478+
builder.verbose(|| eprintln!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
479479
PathBuf::from(sysroot)
480480
}
481481
}
@@ -2478,7 +2478,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
24782478
}
24792479
}
24802480

2481-
builder.verbose(|| println!("doc tests for: {}", markdown.display()));
2481+
builder.verbose(|| eprintln!("doc tests for: {}", markdown.display()));
24822482
let mut cmd = builder.rustdoc_cmd(compiler);
24832483
builder.add_rust_test_threads(&mut cmd);
24842484
// allow for unstable options such as new editions

src/bootstrap/src/core/builder/cargo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl Builder<'_> {
523523

524524
let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
525525
if self.is_verbose() && !matches!(self.config.dry_run, DryRun::SelfCheck) {
526-
println!("using sysroot {sysroot_str}");
526+
eprintln!("using sysroot {sysroot_str}");
527527
}
528528

529529
let mut rustflags = Rustflags::new(target);

src/bootstrap/src/core/builder/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,14 @@ impl StepDescription {
392392
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
393393
if builder.config.skip.iter().any(|e| pathset.has(e, builder.kind)) {
394394
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
395-
println!("Skipping {pathset:?} because it is excluded");
395+
eprintln!("Skipping {pathset:?} because it is excluded");
396396
}
397397
return true;
398398
}
399399

400400
if !builder.config.skip.is_empty() && !matches!(builder.config.dry_run, DryRun::SelfCheck) {
401401
builder.verbose(|| {
402-
println!(
402+
eprintln!(
403403
"{:?} not skipped for {:?} -- not in {:?}",
404404
pathset, self.name, builder.config.skip
405405
)
@@ -1437,11 +1437,11 @@ impl<'a> Builder<'a> {
14371437
panic!("{}", out);
14381438
}
14391439
if let Some(out) = self.cache.get(&step) {
1440-
self.verbose_than(1, || println!("{}c {:?}", " ".repeat(stack.len()), step));
1440+
self.verbose_than(1, || eprintln!("{}c {:?}", " ".repeat(stack.len()), step));
14411441

14421442
return out;
14431443
}
1444-
self.verbose_than(1, || println!("{}> {:?}", " ".repeat(stack.len()), step));
1444+
self.verbose_than(1, || eprintln!("{}> {:?}", " ".repeat(stack.len()), step));
14451445
stack.push(Box::new(step.clone()));
14461446
}
14471447

@@ -1462,7 +1462,7 @@ impl<'a> Builder<'a> {
14621462
let step_string = format!("{step:?}");
14631463
let brace_index = step_string.find('{').unwrap_or(0);
14641464
let type_string = type_name::<S>();
1465-
println!(
1465+
eprintln!(
14661466
"[TIMING] {} {} -- {}.{:03}",
14671467
&type_string.strip_prefix("bootstrap::").unwrap_or(type_string),
14681468
&step_string[brace_index..],
@@ -1479,7 +1479,9 @@ impl<'a> Builder<'a> {
14791479
let cur_step = stack.pop().expect("step stack empty");
14801480
assert_eq!(cur_step.downcast_ref(), Some(&step));
14811481
}
1482-
self.verbose_than(1, || println!("{}< {:?}", " ".repeat(self.stack.borrow().len()), step));
1482+
self.verbose_than(1, || {
1483+
eprintln!("{}< {:?}", " ".repeat(self.stack.borrow().len()), step)
1484+
});
14831485
self.cache.put(step, out.clone());
14841486
out
14851487
}

0 commit comments

Comments
 (0)