diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 0e1c6627716..99b1e5783e0 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -9,14 +9,15 @@ // except according to those terms. use super::*; - use dep_graph::{DepGraph, DepKind, DepNodeIndex}; +use hir::def_id::{LOCAL_CRATE, CrateNum}; use hir::intravisit::{Visitor, NestedVisitorMap}; use hir::svh::Svh; use middle::cstore::CrateStore; use session::CrateDisambiguator; use std::iter::repeat; use syntax::ast::{NodeId, CRATE_NODE_ID}; +use syntax::codemap::CodeMap; use syntax_pos::Span; use ich::StableHashingContext; @@ -123,6 +124,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { pub(super) fn finalize_and_compute_crate_hash(self, crate_disambiguator: CrateDisambiguator, cstore: &CrateStore, + codemap: &CodeMap, commandline_args_hash: u64) -> (Vec>, Svh) { let mut node_hashes: Vec<_> = self @@ -147,11 +149,25 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { (name1, dis1).cmp(&(name2, dis2)) }); + // We hash the final, remapped names of all local source files so we + // don't have to include the path prefix remapping commandline args. + // If we included the full mapping in the SVH, we could only have + // reproducible builds by compiling from the same directory. So we just + // hash the result of the mapping instead of the mapping itself. + let mut source_file_names: Vec<_> = codemap + .files() + .iter() + .filter(|filemap| CrateNum::from_u32(filemap.crate_of_origin) == LOCAL_CRATE) + .map(|filemap| filemap.name_hash) + .collect(); + + source_file_names.sort_unstable(); + let (_, crate_dep_node_index) = self .dep_graph .with_task(DepNode::new_no_params(DepKind::Krate), &self.hcx, - ((node_hashes, upstream_crates), + (((node_hashes, upstream_crates), source_file_names), (commandline_args_hash, crate_disambiguator.to_fingerprint())), identity_fn); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5feea602d28..b6b3e895535 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1065,6 +1065,7 @@ pub fn map_crate<'hir>(sess: &::session::Session, let cmdline_args = sess.opts.dep_tracking_hash(); collector.finalize_and_compute_crate_hash(crate_disambiguator, cstore, + sess.codemap(), cmdline_args) }; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 5b8092e86da..82ee7e31dae 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1269,9 +1269,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "set the optimization fuel quota for a crate"), print_fuel: Option = (None, parse_opt_string, [TRACKED], "make Rustc print the total optimization fuel used by a crate"), - remap_path_prefix_from: Vec = (vec![], parse_pathbuf_push, [TRACKED], + remap_path_prefix_from: Vec = (vec![], parse_pathbuf_push, [UNTRACKED], "add a source pattern to the file path remapping config"), - remap_path_prefix_to: Vec = (vec![], parse_pathbuf_push, [TRACKED], + remap_path_prefix_to: Vec = (vec![], parse_pathbuf_push, [UNTRACKED], "add a mapping target to the file path remapping config"), force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED], "force all crates to be `rustc_private` unstable"), @@ -1717,7 +1717,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) } let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len(); - let remap_path_prefix_targets = debugging_opts.remap_path_prefix_from.len(); + let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len(); if remap_path_prefix_targets < remap_path_prefix_sources { for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {