Auto merge of #1726 - hyd-dev:stub-d, r=RalfJung

cargo-miri: create stub .d files

Thanks `@RalfJung` for the discovery: https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693 ❤️
Fixes #1724.
This commit is contained in:
bors 2021-02-28 10:35:54 +00:00
commit 39ebb079a8
2 changed files with 19 additions and 7 deletions

View File

@ -609,6 +609,15 @@ fn phase_cargo_rustc(mut args: env::Args) {
let print = get_arg_flag_value("--print").is_some(); // whether this is cargo passing `--print` to get some infos
let store_json = |info: CrateRunInfo| {
// Create a stub .d file to stop Cargo from "rebuilding" the crate:
// https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693
// As we store a JSON file instead of building the crate here, an empty file is fine.
let dep_info_name = out_filename("", ".d");
if verbose {
eprintln!("[cargo-miri rustc] writing stub dep-info to `{}`", dep_info_name.display());
}
File::create(dep_info_name).expect("failed to create fake .d file");
let filename = out_filename("", "");
if verbose {
eprintln!("[cargo-miri rustc] writing run info to `{}`", filename.display());

View File

@ -50,12 +50,15 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
print("--- END stderr ---")
fail("exit code was {}".format(p.returncode))
def test_no_rebuild(name, cmd):
def test_no_rebuild(name, cmd, env={}):
print("Testing {}...".format(name))
p_env = os.environ.copy()
p_env.update(env)
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=p_env,
)
(stdout, stderr) = p.communicate()
stdout = stdout.decode("UTF-8")
@ -79,6 +82,12 @@ def test_cargo_miri_run():
'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence
},
)
# Special test: run it again *without* `-q` to make sure nothing is being rebuilt (Miri issue #1722)
test_no_rebuild("`cargo miri run` (no rebuild)",
cargo_miri("run", quiet=False) + ["--", ""],
env={'MIRITESTVAR': "wrongval"}, # changing the env var causes a rebuild (re-runs build.rs),
# so keep it set
)
test("`cargo miri run` (with arguments and target)",
cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'],
"run.args.stdout.ref", "run.args.stderr.ref",
@ -88,12 +97,6 @@ def test_cargo_miri_run():
"run.subcrate.stdout.ref", "run.subcrate.stderr.ref",
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
)
# Special test: run it again *without* `-q` to make sure nothing is being rebuilt (Miri issue #1722)
# FIXME: move this test up to right after the first `test`
# (currently that fails, only the 3rd and later runs are really clean... see Miri issue #1722)
test_no_rebuild("`cargo miri run` (no rebuild)",
cargo_miri("run", quiet=False) + ["--", ""],
)
def test_cargo_miri_test():
# rustdoc is not run on foreign targets