Skip to content

Commit

Permalink
Auto merge of #7134 - ehuss:remap-rustc, r=Eh2406
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 14, 2019
2 parents 705009e + d99b7fe commit 1140c52
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
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();
}

0 comments on commit 1140c52

Please sign in to comment.