Skip to content

Commit ace4c6e

Browse files
committed
fix for doctest-xcompile stabilization
1 parent b99daba commit ace4c6e

7 files changed

+40
-53
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,37 @@ fn main() {
6363
return;
6464
}
6565

66+
let Some(first) = args.next() else {
67+
show_error!(
68+
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
69+
)
70+
};
71+
6672
// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
6773
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
6874
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
6975
// ...however, we then also see this variable when rustdoc invokes us as the testrunner!
70-
// The runner is invoked as `$runtool ($runtool-arg)* output_file`;
71-
// since we don't specify any runtool-args, and rustdoc supplies multiple arguments to
72-
// the test-builder unconditionally, we can just check the number of remaining arguments:
73-
if args.len() == 1 {
74-
phase_runner(args, RunnerPhase::Rustdoc);
75-
} else {
76-
phase_rustc(args, RustcPhase::Rustdoc);
76+
// In that case the first argument is `runner` and there are no more arguments.
77+
match first.as_str() {
78+
"runner" => phase_runner(args, RunnerPhase::Rustdoc),
79+
flag if flag.starts_with("--") || flag.starts_with("@") => {
80+
// This is probably rustdoc invoking us to build the test. But we need to get `first`
81+
// "back onto the iterator", it is some part of the rustc invocation.
82+
phase_rustc(iter::once(first).chain(args), RustcPhase::Rustdoc);
83+
}
84+
_ => {
85+
show_error!(
86+
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\n\
87+
We are inside MIRI_CALLED_FROM_RUSTDOC.\n\
88+
The command-line arguments were: {:#?}",
89+
Vec::from_iter(env::args()),
90+
);
91+
}
7792
}
7893

7994
return;
8095
}
8196

82-
let Some(first) = args.next() else {
83-
show_error!(
84-
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
85-
)
86-
};
8797
match first.as_str() {
8898
"miri" => phase_cargo_miri(args),
8999
"runner" => phase_runner(args, RunnerPhase::Cargo),

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
666666
if arg == "--extern" {
667667
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
668668
forward_patched_extern_arg(&mut args, &mut cmd);
669-
} else if arg == "--test-runtool" {
670-
// An existing --test-runtool flag indicates cargo is running in cross-target mode, which we don't support.
671-
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
672-
// otherwise, we won't be called as rustdoc at all.
673-
show_error!("cross-interpreting doctests is not currently supported by Miri.");
674669
} else {
675670
cmd.arg(arg);
676671
}
@@ -702,10 +697,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
702697
// make sure the 'miri' flag is set for rustdoc
703698
cmd.arg("--cfg").arg("miri");
704699

705-
// Make rustdoc call us back.
700+
// Make rustdoc call us back for the build.
701+
// (cargo already sets `--test-runtool` to us since we are the cargo test runner.)
706702
let cargo_miri_path = env::current_exe().expect("current executable path invalid");
707703
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
708-
cmd.arg("--test-runtool").arg(&cargo_miri_path); // invoked with just a single path argument
709704

710705
debug_cmd("[cargo-miri rustdoc]", verbose, &cmd);
711706
exec(cmd)

src/tools/miri/test-cargo-miri/run-test.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,19 @@ def test_cargo_miri_run():
142142
)
143143

144144
def test_cargo_miri_test():
145-
# rustdoc is not run on foreign targets
146-
is_foreign = ARGS.target is not None
147-
default_ref = "test.cross-target.stdout.ref" if is_foreign else "test.default.stdout.ref"
148-
filter_ref = "test.filter.cross-target.stdout.ref" if is_foreign else "test.filter.stdout.ref"
149-
150145
test("`cargo miri test`",
151146
cargo_miri("test"),
152-
default_ref, "test.empty.ref",
147+
"test.default.stdout.ref", "test.empty.ref",
153148
env={'MIRIFLAGS': "-Zmiri-seed=4242"},
154149
)
155150
test("`cargo miri test` (no isolation, no doctests)",
156151
cargo_miri("test") + ["--bins", "--tests"], # no `--lib`, we disabled that in `Cargo.toml`
157-
"test.cross-target.stdout.ref", "test.empty.ref",
152+
"test.no-doc.stdout.ref", "test.empty.ref",
158153
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
159154
)
160155
test("`cargo miri test` (with filter)",
161156
cargo_miri("test") + ["--", "--format=pretty", "pl"],
162-
filter_ref, "test.empty.ref",
157+
"test.filter.stdout.ref", "test.empty.ref",
163158
)
164159
test("`cargo miri test` (test target)",
165160
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
@@ -171,7 +166,7 @@ def test_cargo_miri_test():
171166
)
172167
test("`cargo miri t` (subcrate, no isolation)",
173168
cargo_miri("t") + ["-p", "subcrate"],
174-
"test.subcrate.cross-target.stdout.ref" if is_foreign else "test.subcrate.stdout.ref",
169+
"test.subcrate.stdout.ref",
175170
"test.empty.ref",
176171
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
177172
)
@@ -181,12 +176,12 @@ def test_cargo_miri_test():
181176
)
182177
test("`cargo miri test` (custom target dir)",
183178
cargo_miri("test") + ["--target-dir=custom-test"],
184-
default_ref, "test.empty.ref",
179+
"test.default.stdout.ref", "test.empty.ref",
185180
)
186181
del os.environ["CARGO_TARGET_DIR"] # this overrides `build.target-dir` passed by `--config`, so unset it
187182
test("`cargo miri test` (config-cli)",
188183
cargo_miri("test") + ["--config=build.target-dir=\"config-cli\""],
189-
default_ref, "test.empty.ref",
184+
"test.default.stdout.ref", "test.empty.ref",
190185
)
191186
if ARGS.multi_target:
192187
test_cargo_miri_multi_target()

src/tools/miri/test-cargo-miri/test.filter.cross-target.stdout.ref

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ running 6 tests
2020
...i..
2121
test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
2222

23+
24+
running 5 tests
25+
.....
26+
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
27+
28+
29+
running 5 tests
30+
.....
31+
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
32+

src/tools/miri/test-cargo-miri/test.subcrate.cross-target.stdout.ref

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)