Skip to content

Commit

Permalink
Auto merge of #1723 - RalfJung:cargo-miri, r=RalfJung
Browse files Browse the repository at this point in the history
cargo-miri: avoid unnecessary rebuilds

Fixes #1722
  • Loading branch information
bors committed Feb 27, 2021
2 parents e29f137 + 3e987e1 commit 74b7714
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
13 changes: 9 additions & 4 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,17 @@ fn phase_cargo_rustc(mut args: env::Args) {
exec(cmd);

// Create a stub .rlib file if "link" was requested by cargo.
// This is necessary to prevent cargo from doing rebuilds all the time.
if emit_link_hack {
// Some platforms prepend "lib", some do not... let's just create both files.
let filename = out_filename("lib", ".rlib");
File::create(filename).expect("failed to create rlib file");
let filename = out_filename("", ".rlib");
File::create(filename).expect("failed to create rlib file");
File::create(out_filename("lib", ".rlib")).expect("failed to create fake .rlib file");
File::create(out_filename("", ".rlib")).expect("failed to create fake .rlib file");
// Just in case this is a cdylib or staticlib, also create those fake files.
File::create(out_filename("lib", ".so")).expect("failed to create fake .so file");
File::create(out_filename("lib", ".a")).expect("failed to create fake .a file");
File::create(out_filename("lib", ".dylib")).expect("failed to create fake .dylib file");
File::create(out_filename("", ".dll")).expect("failed to create fake .dll file");
File::create(out_filename("", ".lib")).expect("failed to create fake .lib file");
}
}

Expand Down
31 changes: 29 additions & 2 deletions test-cargo-miri/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def fail(msg):
print("\nTEST FAIL: {}".format(msg))
sys.exit(1)

def cargo_miri(cmd):
args = ["cargo", "miri", cmd, "-q"]
def cargo_miri(cmd, quiet = True):
args = ["cargo", "miri", cmd]
if quiet:
args += ["-q"]
if 'MIRI_TEST_TARGET' in os.environ:
args += ["--target", os.environ['MIRI_TEST_TARGET']]
return args
Expand Down Expand Up @@ -48,6 +50,25 @@ 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):
print("Testing {}...".format(name))
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout, stderr) = p.communicate()
stdout = stdout.decode("UTF-8")
stderr = stderr.decode("UTF-8")
if p.returncode != 0:
fail("rebuild failed");
# Also check for 'Running' as a sanity check.
if stderr.count(" Compiling ") > 0 or stderr.count(" Running ") == 0:
print("--- BEGIN stderr ---")
print(stderr, end="")
print("--- END stderr ---")
fail("Something was being rebuilt when it should not be (or we got no output)");

def test_cargo_miri_run():
test("`cargo miri run` (no isolation)",
cargo_miri("run"),
Expand All @@ -67,6 +88,12 @@ 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
Expand Down

0 comments on commit 74b7714

Please sign in to comment.