From d99b7fede7eaff781c9160331f5bb005f00b530f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 14 Jul 2019 14:38:47 -0700 Subject: [PATCH] Also ignore remap-path-prefix in metadata for `cargo rustc`. --- .../compiler/context/compilation_files.rs | 44 ++++++++++--------- tests/testsuite/rustflags.rs | 21 ++++++--- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index ed3232ea48e..caf7c5f8be0 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -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 diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index ee21fbeeda5..008bee0f45a 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -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::, _>>() + .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::, _>>() - .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(); }