Skip to content

Commit 29bc8a5

Browse files
committed
add test for compile_fail; de-duplicate sysroot forwarding
1 parent 6559795 commit 29bc8a5

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

cargo-miri/bin.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
163163
}
164164
}
165165

166+
fn forward_miri_sysroot(cmd: &mut Command) {
167+
let sysroot =
168+
env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
169+
cmd.arg("--sysroot");
170+
cmd.arg(sysroot);
171+
}
172+
166173
/// Returns the path to the `miri` binary
167174
fn find_miri() -> PathBuf {
168175
if let Some(path) = env::var_os("MIRI") {
@@ -679,13 +686,6 @@ fn phase_cargo_rustc(mut args: env::Args) {
679686
return;
680687
};
681688

682-
// use our own sysroot
683-
if !has_arg_flag("--sysroot") {
684-
let sysroot = env::var_os("MIRI_SYSROOT")
685-
.expect("the wrapper should have set MIRI_SYSROOT");
686-
cmd.arg("--sysroot").arg(sysroot);
687-
}
688-
689689
// ensure --emit argument for a check-only build is present
690690
if let Some(i) = env.args.iter().position(|arg| arg.starts_with("--emit=")) {
691691
// We need to make sure we're not producing a binary that overwrites the JSON file.
@@ -750,10 +750,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
750750
}
751751

752752
// Use our custom sysroot.
753-
let sysroot =
754-
env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
755-
cmd.arg("--sysroot");
756-
cmd.arg(sysroot);
753+
forward_miri_sysroot(&mut cmd);
757754
} else {
758755
// For host crates or when we are printing, just forward everything.
759756
cmd.args(args);
@@ -842,11 +839,8 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
842839
}
843840
}
844841
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_none() {
845-
// Set sysroot.
846-
let sysroot =
847-
env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
848-
cmd.arg("--sysroot");
849-
cmd.arg(sysroot);
842+
// Set sysroot (if we are inside rustdoc, we already did that in `phase_cargo_rustdoc`).
843+
forward_miri_sysroot(&mut cmd);
850844
}
851845
// Respect `MIRIFLAGS`.
852846
if let Ok(a) = env::var("MIRIFLAGS") {
@@ -930,12 +924,10 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
930924
// which are disabled by default. We first need to enable them explicitly:
931925
cmd.arg("-Z").arg("unstable-options");
932926

933-
// Use our custom sysroot.
934-
let sysroot =
935-
env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
936-
cmd.arg("--sysroot");
937-
cmd.arg(sysroot);
927+
// rustdoc needs to know the right sysroot.
928+
forward_miri_sysroot(&mut cmd);
938929

930+
// Make rustdoc call us back.
939931
let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
940932
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
941933
cmd.arg("--runtool").arg(&cargo_miri_path); // invoked with just a single path argument

test-cargo-miri/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/// ```rust
33
/// assert!(cargo_miri_test::make_true());
44
/// ```
5+
/// ```rust,compile_fail
6+
/// assert!(cargo_miri_test::make_true() == 5);
7+
/// ```
58
pub fn make_true() -> bool {
69
issue_1567::use_the_dependency();
710
issue_1705::use_the_dependency();

test-cargo-miri/test.default.stdout.ref

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ running 7 tests
99
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
1010

1111

12-
running 1 test
12+
running 2 tests
13+
test src/lib.rs - make_true (line 5) ... ok
1314
test src/lib.rs - make_true (line 2) ... ok
1415

15-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
16+
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
1617

0 commit comments

Comments
 (0)