Skip to content

Commit

Permalink
Rollup merge of rust-lang#133817 - clubby789:bootstrap-eprintln, r=ji…
Browse files Browse the repository at this point in the history
…eyouxu

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`
  • Loading branch information
matthiaskrgr authored Dec 4, 2024
2 parents 5530869 + 8374f7c commit 0585134
Show file tree
Hide file tree
Showing 34 changed files with 210 additions and 206 deletions.
20 changes: 10 additions & 10 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn main() {
err => {
drop(err);
if let Ok(pid) = pid {
println!("WARNING: build directory locked by process {pid}, waiting for lock");
eprintln!("WARNING: build directory locked by process {pid}, waiting for lock");
} else {
println!("WARNING: build directory locked, waiting for lock");
eprintln!("WARNING: build directory locked, waiting for lock");
}
let mut lock = t!(build_lock.write());
t!(lock.write(process::id().to_string().as_ref()));
Expand All @@ -70,13 +70,13 @@ fn main() {
// changelog warning, not the `x.py setup` message.
let suggest_setup = config.config.is_none() && !matches!(config.cmd, Subcommand::Setup { .. });
if suggest_setup {
println!("WARNING: you have not made a `config.toml`");
println!(
eprintln!("WARNING: you have not made a `config.toml`");
eprintln!(
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{suggestion}");
eprintln!("{suggestion}");
}

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

if suggest_setup {
println!("WARNING: you have not made a `config.toml`");
println!(
eprintln!("WARNING: you have not made a `config.toml`");
eprintln!(
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{suggestion}");
eprintln!("{suggestion}");
}

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

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

if dump_bootstrap_shims {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn main() {
// should run on success, after this block.
}
if verbose > 0 {
println!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
eprintln!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
}

if let Some(mut on_fail) = on_fail {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Step for CodegenBackend {
fn run(self, builder: &Builder<'_>) {
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
if builder.build.config.vendor && self.backend == "gcc" {
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
eprintln!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ impl Step for Sysroot {
let sysroot = sysroot_dir(compiler.stage);

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

Expand Down Expand Up @@ -1681,7 +1681,7 @@ impl Step for Sysroot {
return true;
}
if !filtered_files.iter().all(|f| f != path.file_name().unwrap()) {
builder.verbose_than(1, || println!("ignoring {}", path.display()));
builder.verbose_than(1, || eprintln!("ignoring {}", path.display()));
false
} else {
true
Expand Down Expand Up @@ -2240,7 +2240,7 @@ pub fn stream_cargo(
cargo.arg(arg);
}

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

if builder.config.dry_run() {
return true;
Expand All @@ -2261,12 +2261,12 @@ pub fn stream_cargo(
Ok(msg) => {
if builder.config.json_output {
// Forward JSON to stdout.
println!("{line}");
eprintln!("{line}");
}
cb(msg)
}
// If this was informational, just print it out and continue
Err(_) => println!("{line}"),
Err(_) => eprintln!("{line}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ fn maybe_install_llvm(
{
let mut cmd = command(llvm_config);
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
builder.verbose(|| eprintln!("running {cmd:?}"));
let files = cmd.run_capture_stdout(builder).stdout();
let build_llvm_out = &builder.llvm_out(builder.config.build);
let target_llvm_out = &builder.llvm_out(target);
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
if let Some(adjective) = adjective { format!("{adjective} ") } else { String::new() };
if len <= 10 {
for path in paths {
println!("fmt: {verb} {adjective}file {path}");
eprintln!("fmt: {verb} {adjective}file {path}");
}
} else {
println!("fmt: {verb} {len} {adjective}files");
eprintln!("fmt: {verb} {len} {adjective}files");
}
}

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

Expand Down
40 changes: 20 additions & 20 deletions src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Step for Profile {
t!(fs::remove_file(path));
}
_ => {
println!("Exiting.");
eprintln!("Exiting.");
crate::exit!(1);
}
}
Expand Down Expand Up @@ -184,15 +184,15 @@ pub fn setup(config: &Config, profile: Profile) {
Profile::Dist => &["dist", "build"],
};

println!();
eprintln!();

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

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

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

/// Creates a toolchain link for stage1 using `rustup`
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Step for Link {
}

if !rustup_installed(builder) {
println!("WARNING: `rustup` is not installed; Skipping `stage1` toolchain linking.");
eprintln!("WARNING: `rustup` is not installed; Skipping `stage1` toolchain linking.");
return;
}

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

if try_link_toolchain(builder, stage_path) {
println!(
eprintln!(
"Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
);
} else {
Expand All @@ -321,14 +321,14 @@ fn toolchain_is_linked(builder: &Builder<'_>) -> bool {
return false;
}
// The toolchain has already been linked.
println!(
eprintln!(
"`stage1` toolchain already linked; not attempting to link `stage1` toolchain"
);
}
None => {
// In this case, we don't know if the `stage1` toolchain has been linked;
// but `rustup` failed, so let's not go any further.
println!(
eprintln!(
"`rustup` failed to list current toolchains; not attempting to link `stage1` toolchain"
);
}
Expand Down Expand Up @@ -389,9 +389,9 @@ pub fn interactive_path() -> io::Result<Profile> {
input.parse()
}

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

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

if prompt_user("Would you like to install the git hook?: [y/N]")? != Some(PromptResult::Yes) {
println!("Ok, skipping installation!");
eprintln!("Ok, skipping installation!");
return Ok(());
}
if !hooks_dir.exists() {
Expand All @@ -513,7 +513,7 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
);
return Err(e);
}
Ok(_) => println!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
Ok(_) => eprintln!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
};
Ok(())
}
Expand Down Expand Up @@ -654,7 +654,7 @@ impl Step for Editor {
if let Some(editor_kind) = editor_kind {
while !t!(create_editor_settings_maybe(config, editor_kind.clone())) {}
} else {
println!("Ok, skipping editor setup!");
eprintln!("Ok, skipping editor setup!");
}
}
Err(e) => eprintln!("Could not determine the editor: {e}"),
Expand Down Expand Up @@ -687,7 +687,7 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
mismatched_settings = Some(false);
}
}
println!(
eprintln!(
"\nx.py can automatically install the recommended `{settings_filename}` file for rustc development"
);

Expand All @@ -706,7 +706,7 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
Some(PromptResult::Yes) => true,
Some(PromptResult::Print) => false,
_ => {
println!("Ok, skipping settings!");
eprintln!("Ok, skipping settings!");
return Ok(true);
}
};
Expand All @@ -733,9 +733,9 @@ fn create_editor_settings_maybe(config: &Config, editor: EditorKind) -> io::Resu
_ => "Created",
};
fs::write(&settings_path, editor.settings_template())?;
println!("{verb} `{}`", settings_filename);
eprintln!("{verb} `{}`", settings_filename);
} else {
println!("\n{}", editor.settings_template());
eprintln!("\n{}", editor.settings_template());
}
Ok(should_create)
}
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
build.build();
}
} else {
println!("HELP: consider using the `--run` flag to automatically run suggested tests");
eprintln!("HELP: consider using the `--run` flag to automatically run suggested tests");
}
}
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ impl Miri {
// We re-use the `cargo` from above.
cargo.arg("--print-sysroot");

builder.verbose(|| println!("running: {cargo:?}"));
builder.verbose(|| eprintln!("running: {cargo:?}"));
let stdout = cargo.run_capture_stdout(builder).stdout();
// Output is "<sysroot>\n".
let sysroot = stdout.trim_end();
builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
builder.verbose(|| eprintln!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
PathBuf::from(sysroot)
}
}
Expand Down Expand Up @@ -2478,7 +2478,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
}
}

builder.verbose(|| println!("doc tests for: {}", markdown.display()));
builder.verbose(|| eprintln!("doc tests for: {}", markdown.display()));
let mut cmd = builder.rustdoc_cmd(compiler);
builder.add_rust_test_threads(&mut cmd);
// allow for unstable options such as new editions
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl Builder<'_> {

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

let mut rustflags = Rustflags::new(target);
Expand Down
14 changes: 8 additions & 6 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,14 @@ impl StepDescription {
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
if builder.config.skip.iter().any(|e| pathset.has(e, builder.kind)) {
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
println!("Skipping {pathset:?} because it is excluded");
eprintln!("Skipping {pathset:?} because it is excluded");
}
return true;
}

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

return out;
}
self.verbose_than(1, || println!("{}> {:?}", " ".repeat(stack.len()), step));
self.verbose_than(1, || eprintln!("{}> {:?}", " ".repeat(stack.len()), step));
stack.push(Box::new(step.clone()));
}

Expand All @@ -1462,7 +1462,7 @@ impl<'a> Builder<'a> {
let step_string = format!("{step:?}");
let brace_index = step_string.find('{').unwrap_or(0);
let type_string = type_name::<S>();
println!(
eprintln!(
"[TIMING] {} {} -- {}.{:03}",
&type_string.strip_prefix("bootstrap::").unwrap_or(type_string),
&step_string[brace_index..],
Expand All @@ -1479,7 +1479,9 @@ impl<'a> Builder<'a> {
let cur_step = stack.pop().expect("step stack empty");
assert_eq!(cur_step.downcast_ref(), Some(&step));
}
self.verbose_than(1, || println!("{}< {:?}", " ".repeat(self.stack.borrow().len()), step));
self.verbose_than(1, || {
eprintln!("{}< {:?}", " ".repeat(self.stack.borrow().len()), step)
});
self.cache.put(step, out.clone());
out
}
Expand Down
Loading

0 comments on commit 0585134

Please sign in to comment.