Skip to content

Commit 98e1cbb

Browse files
committed
phase_rustdoc: add a heuristic to make us more certain that this is really rustdoc
1 parent 8afc486 commit 98e1cbb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/tools/miri/cargo-miri/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ use std::{env, iter};
1111

1212
use crate::phases::*;
1313

14+
/// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to
15+
/// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that
16+
/// would let us get a clear signal.
17+
fn looks_like_rustdoc() -> bool {
18+
// The `--test-run-directory` flag only exists for rustdoc and cargo always passes it. Perfect!
19+
env::args().any(|arg| arg == "--test-run-directory")
20+
}
21+
1422
fn main() {
1523
// Rustc does not support non-UTF-8 arguments so we make no attempt either.
1624
// (We do support non-UTF-8 environment variables though.)
17-
let mut args = std::env::args();
25+
let mut args = env::args();
1826
// Skip binary name.
1927
args.next().unwrap();
2028

@@ -91,10 +99,16 @@ fn main() {
9199
// (see https://github.com/rust-lang/cargo/issues/10886).
92100
phase_rustc(args, RustcPhase::Build)
93101
}
94-
_ => {
95-
// Everything else must be rustdoc. But we need to get `first` "back onto the iterator",
102+
_ if looks_like_rustdoc() => {
103+
// This is probably rustdoc. But we need to get `first` "back onto the iterator",
96104
// it is some part of the rustdoc invocation.
97105
phase_rustdoc(iter::once(first).chain(args));
98106
}
107+
_ => {
108+
show_error!(
109+
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\nThe command-line arguments were: {:#?}",
110+
Vec::from_iter(env::args()),
111+
);
112+
}
99113
}
100114
}

src/tools/miri/cargo-miri/src/phases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
620620

621621
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
622622
// which are disabled by default. We first need to enable them explicitly:
623-
cmd.arg("-Z").arg("unstable-options");
623+
cmd.arg("-Zunstable-options");
624624

625625
// rustdoc needs to know the right sysroot.
626626
cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());

0 commit comments

Comments
 (0)