From 49cd383537580861f6bfd2daa6765409ca15b119 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Sun, 28 Feb 2021 04:52:27 +0800 Subject: [PATCH] Create stub .d files --- cargo-miri/bin.rs | 8 ++++++++ test-cargo-miri/run-test.py | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 051f3dd3b6fc..535acf36df73 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -609,6 +609,14 @@ 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 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()); diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index b9259b7d0d22..3a8a32db1ede 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -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") @@ -70,14 +73,20 @@ def test_no_rebuild(name, cmd): fail("Something was being rebuilt when it should not be (or we got no output)"); def test_cargo_miri_run(): + default_env={ + 'MIRIFLAGS': "-Zmiri-disable-isolation", + 'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence + } test("`cargo miri run` (no isolation)", cargo_miri("run"), "run.default.stdout.ref", "run.default.stderr.ref", stdin=b'12\n21\n', - env={ - 'MIRIFLAGS': "-Zmiri-disable-isolation", - 'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence - }, + env=default_env, + ) + # 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, no isolation)", + cargo_miri("run", quiet=False) + ["--", ""], + env=default_env, ) test("`cargo miri run` (with arguments and target)", cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'], @@ -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