Auto merge of #7134 - ehuss:remap-rustc, r=Eh2406

Also ignore remap-path-prefix in metadata for `cargo rustc`.

Also ignore `--remap-path-prefix` in `cargo rustc`.  Who knew that `BuildContext` had 3 sets of arguments?

Closes #7133
This commit is contained in:
bors 2019-07-14 22:04:26 +00:00
commit 1140c527c4
2 changed files with 40 additions and 27 deletions

View File

@ -547,32 +547,36 @@ fn compute_metadata<'a, 'cfg>(
// settings like debuginfo and whatnot.
unit.profile.hash(&mut hasher);
unit.mode.hash(&mut hasher);
if let Some(args) = bcx.extra_args_for(unit) {
args.hash(&mut hasher);
}
// 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.
let mut flags = if unit.mode.is_doc() {
cx.bcx.rustdocflags_args(unit)
let mut hash_flags = |flags: &[String]| {
// Ignore some flags. These may affect reproducible builds if they affect
// the path. The fingerprint will handle recompilation if these change.
let mut iter = flags.iter();
while let Some(flag) = iter.next() {
if flag.starts_with("--remap-path-prefix=") {
continue;
}
if flag == "--remap-path-prefix" {
iter.next();
continue;
}
flag.hash(&mut hasher);
}
};
if let Some(args) = bcx.extra_args_for(unit) {
// Arguments passed to `cargo rustc`.
hash_flags(args);
}
// Arguments passed in via RUSTFLAGS env var.
let flags = if unit.mode.is_doc() {
bcx.rustdocflags_args(unit)
} else {
cx.bcx.rustflags_args(unit)
}
.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);
}
bcx.rustflags_args(unit)
};
hash_flags(flags);
// Artifacts compiled for the host should have a different metadata
// piece than those compiled for the target, so make sure we throw in

View File

@ -1361,7 +1361,7 @@ fn env_rustflags_misspelled_build_script() {
}
#[cargo_test]
fn reamp_path_prefix_ignored() {
fn remap_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();
@ -1372,15 +1372,24 @@ fn reamp_path_prefix_ignored() {
assert_eq!(rlibs.len(), 1);
p.cargo("clean").run();
let check_metadata_same = || {
let rlibs2 = p
.glob("target/debug/deps/*.rlib")
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(rlibs, rlibs2);
};
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);
check_metadata_same();
p.cargo("clean").run();
p.cargo("rustc -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo")
.run();
check_metadata_same();
}