Skip to content

Commit

Permalink
Ignore remap-path-prefix in metadata hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed May 20, 2019
1 parent 5a0c31d commit c8a9f88
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,24 @@ fn compute_metadata<'a, 'cfg>(
// Throw in the rustflags we're compiling with.
// This helps when the target directory is a shared cache for projects with different cargo configs,
// or if the user is experimenting with different rustflags manually.
if unit.mode.is_doc() {
cx.bcx.rustdocflags_args(unit).hash(&mut hasher);
let mut flags = if unit.mode.is_doc() {
cx.bcx.rustdocflags_args(unit)
} else {
cx.bcx.rustflags_args(unit).hash(&mut hasher);
cx.bcx.rustflags_args(unit)
}
.into_iter();

// Ignore some flags. These may affect reproducible builds if they affect
// the path. The fingerprint will handle recompilation if these change.
while let Some(flag) = flags.next() {
if flag.starts_with("--remap-path-prefix=") {
continue;
}
if flag == "--remap-path-prefix" {
flags.next();
continue;
}
flag.hash(&mut hasher);
}

// Artifacts compiled for the host should have a different metadata
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
//! Target flags (test/bench/for_host/edition) | ✓ |
//! -C incremental=… flag | ✓ |
//! mtime of sources | ✓[^3] |
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
//!
//! [^1]: Build script and bin dependencies are not included.
//!
Expand Down
25 changes: 25 additions & 0 deletions tests/testsuite/rustflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,3 +1359,28 @@ fn env_rustflags_misspelled_build_script() {
.with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?")
.run();
}

#[test]
fn reamp_path_prefix_ignored() {
// Ensure that --remap-path-prefix does not affect metadata hash.
let p = project().file("src/lib.rs", "").build();
p.cargo("build").run();
let rlibs = p
.glob("target/debug/deps/*.rlib")
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(rlibs.len(), 1);
p.cargo("clean").run();

p.cargo("build")
.env(
"RUSTFLAGS",
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo",
)
.run();
let rlibs2 = p
.glob("target/debug/deps/*.rlib")
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(rlibs, rlibs2);
}

0 comments on commit c8a9f88

Please sign in to comment.