Auto merge of #3619 - RalfJung:print-sysroot, r=RalfJung
properly print error in 'cargo miri setup --print-sysroot' Based on rustc-build-sysroot now putting the stderr into the error message.
This commit is contained in:
commit
3c15681a48
@ -178,9 +178,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-build-sysroot"
|
name = "rustc-build-sysroot"
|
||||||
version = "0.5.0"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "de6077473f0c46779b49e4587a81f1b8919e0ec26630409ecfda0ba3259efb43"
|
checksum = "fa3ca63cc537c1cb69e4c2c0afc5fda2ccd36ac84c97d5a4ae05e69b1c834afb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
|
@ -18,7 +18,7 @@ directories = "5"
|
|||||||
rustc_version = "0.4"
|
rustc_version = "0.4"
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.40"
|
||||||
cargo_metadata = "0.18.0"
|
cargo_metadata = "0.18.0"
|
||||||
rustc-build-sysroot = "0.5.0"
|
rustc-build-sysroot = "0.5.2"
|
||||||
|
|
||||||
# Enable some feature flags that dev-dependencies need but dependencies
|
# Enable some feature flags that dev-dependencies need but dependencies
|
||||||
# do not. This makes `./miri install` after `./miri build` faster.
|
# do not. This makes `./miri install` after `./miri build` faster.
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt::Write;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{self, Command};
|
use std::process::{self, Command};
|
||||||
|
|
||||||
@ -24,6 +23,7 @@ pub fn setup(
|
|||||||
let only_setup = matches!(subcommand, MiriCommand::Setup);
|
let only_setup = matches!(subcommand, MiriCommand::Setup);
|
||||||
let ask_user = !only_setup;
|
let ask_user = !only_setup;
|
||||||
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
|
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
|
||||||
|
let show_setup = only_setup && !print_sysroot;
|
||||||
if !only_setup {
|
if !only_setup {
|
||||||
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
|
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
|
||||||
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
|
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
|
||||||
@ -115,18 +115,16 @@ pub fn setup(
|
|||||||
// `config.toml`.
|
// `config.toml`.
|
||||||
command.env("RUSTC_WRAPPER", "");
|
command.env("RUSTC_WRAPPER", "");
|
||||||
|
|
||||||
if only_setup && !print_sysroot {
|
if show_setup {
|
||||||
// Forward output. Even make it verbose, if requested.
|
// Forward output. Even make it verbose, if requested.
|
||||||
|
command.stdout(process::Stdio::inherit());
|
||||||
|
command.stderr(process::Stdio::inherit());
|
||||||
for _ in 0..verbose {
|
for _ in 0..verbose {
|
||||||
command.arg("-v");
|
command.arg("-v");
|
||||||
}
|
}
|
||||||
if quiet {
|
if quiet {
|
||||||
command.arg("--quiet");
|
command.arg("--quiet");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Suppress output.
|
|
||||||
command.stdout(process::Stdio::null());
|
|
||||||
command.stderr(process::Stdio::null());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
command
|
command
|
||||||
@ -137,22 +135,25 @@ pub fn setup(
|
|||||||
// not apply `RUSTFLAGS` to the sysroot either.
|
// not apply `RUSTFLAGS` to the sysroot either.
|
||||||
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
|
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
|
||||||
|
|
||||||
|
let mut after_build_output = String::new(); // what should be printed when the build is done.
|
||||||
let notify = || {
|
let notify = || {
|
||||||
let mut msg = String::new();
|
if !quiet {
|
||||||
write!(msg, "Preparing a sysroot for Miri (target: {target})").unwrap();
|
eprint!("Preparing a sysroot for Miri (target: {target})");
|
||||||
if verbose > 0 {
|
if verbose > 0 {
|
||||||
write!(msg, " in {}", sysroot_dir.display()).unwrap();
|
eprint!(" in {}", sysroot_dir.display());
|
||||||
}
|
}
|
||||||
write!(msg, "...").unwrap();
|
if show_setup {
|
||||||
|
// Cargo will print things, so we need to finish this line.
|
||||||
if print_sysroot || quiet {
|
eprintln!("...");
|
||||||
// Be silent.
|
after_build_output = format!(
|
||||||
} else if only_setup {
|
"A sysroot for Miri is now available in `{}`.\n",
|
||||||
// We want to be explicit.
|
sysroot_dir.display()
|
||||||
eprintln!("{msg}");
|
);
|
||||||
} else {
|
} else {
|
||||||
// We want to be quiet, but still let the user know that something is happening.
|
// Keep all output on a single line.
|
||||||
eprint!("{msg} ");
|
eprint!("... ");
|
||||||
|
after_build_output = format!("done\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,31 +168,17 @@ pub fn setup(
|
|||||||
.build_from_source(&rust_src);
|
.build_from_source(&rust_src);
|
||||||
match status {
|
match status {
|
||||||
Ok(SysrootStatus::AlreadyCached) =>
|
Ok(SysrootStatus::AlreadyCached) =>
|
||||||
if only_setup && !(print_sysroot || quiet) {
|
if !quiet && show_setup {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"A sysroot for Miri is already available in `{}`.",
|
"A sysroot for Miri is already available in `{}`.",
|
||||||
sysroot_dir.display()
|
sysroot_dir.display()
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Ok(SysrootStatus::SysrootBuilt) => {
|
Ok(SysrootStatus::SysrootBuilt) => {
|
||||||
if print_sysroot || quiet {
|
// Print what `notify` prepared.
|
||||||
// Be silent.
|
eprint!("{after_build_output}");
|
||||||
} else if only_setup {
|
|
||||||
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
|
|
||||||
} else {
|
|
||||||
eprintln!("done");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) =>
|
Err(err) => show_error!("failed to build sysroot: {err:?}"),
|
||||||
if print_sysroot {
|
|
||||||
show_error!("failed to build sysroot")
|
|
||||||
} else if only_setup {
|
|
||||||
show_error!("failed to build sysroot: {err:?}")
|
|
||||||
} else {
|
|
||||||
show_error!(
|
|
||||||
"failed to build sysroot; run `cargo miri setup` to see the error details"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if print_sysroot {
|
if print_sysroot {
|
||||||
|
@ -42,28 +42,19 @@ fn build_miri_sysroot(&mut self, quiet: bool, target: Option<&OsStr>) -> Result<
|
|||||||
let target_flag = &target_flag;
|
let target_flag = &target_flag;
|
||||||
|
|
||||||
if !quiet {
|
if !quiet {
|
||||||
|
eprint!("$ cargo miri setup");
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
eprintln!("$ (building Miri sysroot for {})", target.to_string_lossy());
|
eprint!(" --target {target}", target = target.to_string_lossy());
|
||||||
} else {
|
|
||||||
eprintln!("$ (building Miri sysroot)");
|
|
||||||
}
|
}
|
||||||
|
eprintln!();
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = cmd!(self.sh,
|
let mut cmd = cmd!(self.sh,
|
||||||
"cargo +{toolchain} --quiet run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
"cargo +{toolchain} --quiet run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
||||||
miri setup --print-sysroot {target_flag...}"
|
miri setup --print-sysroot {target_flag...}"
|
||||||
).read();
|
);
|
||||||
let Ok(output) = output else {
|
cmd.set_quiet(quiet);
|
||||||
// Run it again (without `--print-sysroot` or `--quiet`) so the user can see the error.
|
let output = cmd.read()?;
|
||||||
cmd!(
|
|
||||||
self.sh,
|
|
||||||
"cargo +{toolchain} run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
|
||||||
miri setup {target_flag...}"
|
|
||||||
)
|
|
||||||
.run()
|
|
||||||
.with_context(|| "`cargo miri setup` failed")?;
|
|
||||||
panic!("`cargo miri setup` didn't fail again the 2nd time?");
|
|
||||||
};
|
|
||||||
self.sh.set_var("MIRI_SYSROOT", &output);
|
self.sh.set_var("MIRI_SYSROOT", &output);
|
||||||
Ok(output.into())
|
Ok(output.into())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user