Skip to content

Commit b2418e8

Browse files
committed
Auto merge of rust-lang#2425 - RalfJung:hide-xargo, r=RalfJung
don't dump xargo output onto users of 'cargo miri test' The xargo invocation prints a lot of details users probably won't care about, so let's hide them (unless the user did `cargo miri setup`, then we still print everything).
2 parents 302e9ae + 0c5392f commit b2418e8

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

cargo-miri/bin.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,26 @@ path = "lib.rs"
497497
// Disable debug assertions in the standard library -- Miri is already slow enough.
498498
// But keep the overflow checks, they are cheap.
499499
command.env("RUSTFLAGS", "-Cdebug-assertions=off -Coverflow-checks=on");
500+
// Manage the output the user sees.
501+
if only_setup {
502+
eprintln!("Preparing a sysroot for Miri...");
503+
} else {
504+
eprint!("Preparing a sysroot for Miri... ");
505+
command.stdout(process::Stdio::null());
506+
command.stderr(process::Stdio::null());
507+
}
500508
// Finally run it!
501509
if command.status().expect("failed to run xargo").success().not() {
502-
show_error(format!("failed to run xargo"));
510+
if only_setup {
511+
show_error(format!("failed to run xargo, see error details above"))
512+
} else {
513+
show_error(format!(
514+
"failed to run xargo; run `cargo miri setup` to see the error details"
515+
))
516+
}
517+
}
518+
if !only_setup {
519+
eprintln!("done");
503520
}
504521

505522
// That should be it! But we need to figure out where xargo built stuff.
@@ -510,10 +527,10 @@ path = "lib.rs"
510527
// Figure out what to print.
511528
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
512529
if print_sysroot {
513-
// Print just the sysroot and nothing else; this way we do not need any escaping.
530+
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
514531
println!("{}", sysroot.display());
515532
} else if only_setup {
516-
println!("A libstd for Miri is now available in `{}`.", sysroot.display());
533+
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot.display());
517534
}
518535
}
519536

ci.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function run_tests {
2121
echo "Testing host architecture"
2222
fi
2323

24+
## ui test suite
2425
./miri test --locked
2526
if [ -z "${MIRI_TEST_TARGET+exists}" ]; then
2627
# Only for host architecture: tests with optimizations (`-O` is what cargo passes, but crank MIR
@@ -30,15 +31,13 @@ function run_tests {
3031
MIRIFLAGS="-O -Zmir-opt-level=4" MIRI_SKIP_UI_CHECKS=1 ./miri test --locked -- tests/{pass,panic}
3132
fi
3233

34+
## test-cargo-miri
3335
# On Windows, there is always "python", not "python3" or "python2".
3436
if command -v python3 > /dev/null; then
3537
PYTHON=python3
3638
else
3739
PYTHON=python
3840
fi
39-
40-
# "miri test" has built the sysroot for us, now this should pass without
41-
# any interactive questions.
4241
${PYTHON} test-cargo-miri/run-test.py
4342
echo
4443

src/machine.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,14 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
367367
measureme::Profiler::new(out).expect("Couldn't create `measureme` profiler")
368368
});
369369
let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
370-
let stacked_borrows = if config.stacked_borrows {
371-
Some(RefCell::new(stacked_borrows::GlobalStateInner::new(
370+
let stacked_borrows = config.stacked_borrows.then(|| {
371+
RefCell::new(stacked_borrows::GlobalStateInner::new(
372372
config.tracked_pointer_tags.clone(),
373373
config.tracked_call_ids.clone(),
374374
config.retag_fields,
375-
)))
376-
} else {
377-
None
378-
};
379-
let data_race = if config.data_race_detector {
380-
Some(data_race::GlobalState::new(config))
381-
} else {
382-
None
383-
};
375+
))
376+
});
377+
let data_race = config.data_race_detector.then(|| data_race::GlobalState::new(config));
384378
Evaluator {
385379
stacked_borrows,
386380
data_race,
@@ -691,32 +685,24 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
691685
}
692686

693687
let alloc = alloc.into_owned();
694-
let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
695-
Some(Stacks::new_allocation(
688+
let stacks = ecx.machine.stacked_borrows.as_ref().map(|stacked_borrows| {
689+
Stacks::new_allocation(
696690
id,
697691
alloc.size(),
698692
stacked_borrows,
699693
kind,
700694
ecx.machine.current_span(),
701-
))
702-
} else {
703-
None
704-
};
705-
let race_alloc = if let Some(data_race) = &ecx.machine.data_race {
706-
Some(data_race::AllocExtra::new_allocation(
695+
)
696+
});
697+
let race_alloc = ecx.machine.data_race.as_ref().map(|data_race| {
698+
data_race::AllocExtra::new_allocation(
707699
data_race,
708700
&ecx.machine.threads,
709701
alloc.size(),
710702
kind,
711-
))
712-
} else {
713-
None
714-
};
715-
let buffer_alloc = if ecx.machine.weak_memory {
716-
Some(weak_memory::AllocExtra::new_allocation())
717-
} else {
718-
None
719-
};
703+
)
704+
});
705+
let buffer_alloc = ecx.machine.weak_memory.then(weak_memory::AllocExtra::new_allocation);
720706
let alloc: Allocation<Provenance, Self::AllocExtra> = alloc.adjust_from_tcx(
721707
&ecx.tcx,
722708
AllocExtra {

test-cargo-miri/run-test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def cargo_miri(cmd, quiet = True):
2525

2626
def normalize_stdout(str):
2727
str = str.replace("src\\", "src/") # normalize paths across platforms
28-
return re.sub("finished in \d+\.\d\ds", "finished in $TIME", str)
28+
str = re.sub("finished in \d+\.\d\ds", "finished in $TIME", str) # the time keeps changing, obviously
29+
return str
30+
31+
def normalize_stderr(str):
32+
str = str.replace("Preparing a sysroot for Miri... done\n", "") # remove leading cargo-miri setup output
33+
return str
2934

3035
def check_output(actual, path, name):
3136
expected = open(path).read()
@@ -51,9 +56,8 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
5156
env=p_env,
5257
)
5358
(stdout, stderr) = p.communicate(input=stdin)
54-
stdout = stdout.decode("UTF-8")
55-
stderr = stderr.decode("UTF-8")
56-
stdout = normalize_stdout(stdout)
59+
stdout = normalize_stdout(stdout.decode("UTF-8"))
60+
stderr = normalize_stderr(stderr.decode("UTF-8"))
5761

5862
stdout_matches = check_output(stdout, stdout_ref, "stdout")
5963
stderr_matches = check_output(stderr, stderr_ref, "stderr")
@@ -175,10 +179,6 @@ def test_cargo_miri_test():
175179
target_str = " for target {}".format(os.environ['MIRI_TEST_TARGET']) if 'MIRI_TEST_TARGET' in os.environ else ""
176180
print(CGREEN + CBOLD + "## Running `cargo miri` tests{}".format(target_str) + CEND)
177181

178-
if not 'MIRI_SYSROOT' in os.environ:
179-
# Make sure we got a working sysroot.
180-
# (If the sysroot gets built later when output is compared, that leads to test failures.)
181-
subprocess.run(cargo_miri("setup"), check=True)
182182
test_cargo_miri_run()
183183
test_cargo_miri_test()
184184
# Ensure we did not create anything outside the expected target dir.

0 commit comments

Comments
 (0)