Skip to content

Commit

Permalink
./miri run: support -v flag to print what it is doing
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 3, 2024
1 parent 8a31014 commit eaf30ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
21 changes: 12 additions & 9 deletions src/tools/miri/miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Command {
Command::Build { flags } => Self::build(flags),
Command::Check { flags } => Self::check(flags),
Command::Test { bless, flags } => Self::test(bless, flags),
Command::Run { dep, flags } => Self::run(dep, flags),
Command::Run { dep, verbose, flags } => Self::run(dep, verbose, flags),
Command::Fmt { flags } => Self::fmt(flags),
Command::Clippy { flags } => Self::clippy(flags),
Command::Cargo { flags } => Self::cargo(flags),
Expand Down Expand Up @@ -495,7 +495,7 @@ impl Command {
Ok(())
}

fn run(dep: bool, mut flags: Vec<OsString>) -> Result<()> {
fn run(dep: bool, verbose: bool, mut flags: Vec<OsString>) -> Result<()> {
let mut e = MiriEnv::new()?;
// Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
// that we set the MIRI_SYSROOT up the right way. We must make sure that
Expand All @@ -522,7 +522,7 @@ impl Command {
}

// Prepare a sysroot, and add it to the flags.
let miri_sysroot = e.build_miri_sysroot(/* quiet */ true)?;
let miri_sysroot = e.build_miri_sysroot(/* quiet */ !verbose)?;
flags.push("--sysroot".into());
flags.push(miri_sysroot.into());

Expand All @@ -532,17 +532,20 @@ impl Command {
let miri_flags = flagsplit(&miri_flags);
let toolchain = &e.toolchain;
let extra_flags = &e.cargo_extra_flags;
if dep {
let quiet_flag = if verbose { None } else { Some("--quiet") };
let mut cmd = if dep {
cmd!(
e.sh,
"cargo +{toolchain} --quiet test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {flags...}"
).quiet().run()?;
"cargo +{toolchain} {quiet_flag...} test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {flags...}"
)
} else {
cmd!(
e.sh,
"cargo +{toolchain} --quiet run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}"
).quiet().run()?;
}
"cargo +{toolchain} {quiet_flag...} run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}"
)
};
cmd.set_quiet(!verbose);
cmd.run()?;
Ok(())
}

Expand Down
32 changes: 17 additions & 15 deletions src/tools/miri/miri-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum Command {
/// (Also respects MIRIFLAGS environment variable.)
Run {
dep: bool,
verbose: bool,
/// Flags that are passed through to `miri`.
flags: Vec<OsString>,
},
Expand Down Expand Up @@ -90,7 +91,7 @@ Just check miri. <flags> are passed to `cargo check`.
Build miri, set up a sysroot and then run the test suite. <flags> are passed
to the final `cargo test` invocation.
./miri run [--dep] <flags>:
./miri run [--dep] [-v|--verbose] <flags>:
Build miri, set up a sysroot and then run the driver with the given <flags>.
(Also respects MIRIFLAGS environment variable.)
Expand Down Expand Up @@ -132,10 +133,10 @@ Pull and merge Miri changes from the rustc repo. Defaults to fetching the latest
rustc commit. The fetched commit is stored in the `rust-version` file, so the
next `./miri toolchain` will install the rustc that just got pulled.
./miri rustc-push <github user> <branch>:
./miri rustc-push <github user> [<branch>]:
Push Miri changes back to the rustc repo. This will pull a copy of the rustc
history into the Miri repo, unless you set the RUSTC_GIT env var to an existing
clone of the rustc repo.
clone of the rustc repo. The branch defaults to `miri-sync`.
ENVIRONMENT VARIABLES
Expand All @@ -162,12 +163,18 @@ fn main() -> Result<()> {
Command::Test { bless, flags: args.collect() }
}
Some("run") => {
let dep = args.peek().is_some_and(|a| a.to_str() == Some("--dep"));
if dep {
// Consume the flag.
let mut dep = false;
let mut verbose = false;
while let Some(arg) = args.peek().and_then(|a| a.to_str()) {
match arg {
"--dep" => dep = true,
"-v" | "--verbose" => verbose = true,
_ => break, // not for us
}
// Consume the flag, look at the next one.
args.next().unwrap();
}
Command::Run { dep, flags: args.collect() }
Command::Run { dep, verbose, flags: args.collect() }
}
Some("fmt") => Command::Fmt { flags: args.collect() },
Some("clippy") => Command::Clippy { flags: args.collect() },
Expand All @@ -187,17 +194,12 @@ fn main() -> Result<()> {
let github_user = args
.next()
.ok_or_else(|| {
anyhow!("Missing first argument for `./miri rustc-push GITHUB_USER BRANCH`")
})?
.to_string_lossy()
.into_owned();
let branch = args
.next()
.ok_or_else(|| {
anyhow!("Missing second argument for `./miri rustc-push GITHUB_USER BRANCH`")
anyhow!("Missing first argument for `./miri rustc-push GITHUB_USER [BRANCH]`")
})?
.to_string_lossy()
.into_owned();
let branch =
args.next().unwrap_or_else(|| "miri-sync".into()).to_string_lossy().into_owned();
if args.next().is_some() {
bail!("Too many arguments for `./miri rustc-push GITHUB_USER BRANCH`");
}
Expand Down

0 comments on commit eaf30ce

Please sign in to comment.