Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
} 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;
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);
}
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 {
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
Expand Down
21 changes: 15 additions & 6 deletions tests/testsuite/rustflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}