Skip to content

Commit 0397fc1

Browse files
Handle path prefix mapping in a more stable way when computing the crate hash.
1 parent 16362c7 commit 0397fc1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/librustc/hir/map/collector.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// except according to those terms.
1010

1111
use super::*;
12-
1312
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
13+
use hir::def_id::{LOCAL_CRATE, CrateNum};
1414
use hir::intravisit::{Visitor, NestedVisitorMap};
1515
use hir::svh::Svh;
1616
use middle::cstore::CrateStore;
1717
use session::CrateDisambiguator;
1818
use std::iter::repeat;
1919
use syntax::ast::{NodeId, CRATE_NODE_ID};
20+
use syntax::codemap::CodeMap;
2021
use syntax_pos::Span;
2122

2223
use ich::StableHashingContext;
@@ -123,6 +124,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
123124
pub(super) fn finalize_and_compute_crate_hash(self,
124125
crate_disambiguator: CrateDisambiguator,
125126
cstore: &CrateStore,
127+
codemap: &CodeMap,
126128
commandline_args_hash: u64)
127129
-> (Vec<MapEntry<'hir>>, Svh) {
128130
let mut node_hashes: Vec<_> = self
@@ -147,11 +149,25 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
147149
(name1, dis1).cmp(&(name2, dis2))
148150
});
149151

152+
// We hash the final, remapped names of all local source files so we
153+
// don't have to include the path prefix remapping commandline args.
154+
// If we included the full mapping in the SVH, we could only have
155+
// reproducible builds by compiling from the same directory. So we just
156+
// hash the result of the mapping instead of the mapping itself.
157+
let mut source_file_names: Vec<_> = codemap
158+
.files()
159+
.iter()
160+
.filter(|filemap| CrateNum::from_u32(filemap.crate_of_origin) == LOCAL_CRATE)
161+
.map(|filemap| filemap.name_hash)
162+
.collect();
163+
164+
source_file_names.sort_unstable();
165+
150166
let (_, crate_dep_node_index) = self
151167
.dep_graph
152168
.with_task(DepNode::new_no_params(DepKind::Krate),
153169
&self.hcx,
154-
((node_hashes, upstream_crates),
170+
(((node_hashes, upstream_crates), source_file_names),
155171
(commandline_args_hash,
156172
crate_disambiguator.to_fingerprint())),
157173
identity_fn);

src/librustc/hir/map/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
10651065
let cmdline_args = sess.opts.dep_tracking_hash();
10661066
collector.finalize_and_compute_crate_hash(crate_disambiguator,
10671067
cstore,
1068+
sess.codemap(),
10681069
cmdline_args)
10691070
};
10701071

src/librustc/session/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12691269
"set the optimization fuel quota for a crate"),
12701270
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
12711271
"make Rustc print the total optimization fuel used by a crate"),
1272-
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [TRACKED],
1272+
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
12731273
"add a source pattern to the file path remapping config"),
1274-
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [TRACKED],
1274+
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
12751275
"add a mapping target to the file path remapping config"),
12761276
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
12771277
"force all crates to be `rustc_private` unstable"),
@@ -1717,7 +1717,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17171717
}
17181718

17191719
let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
1720-
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_from.len();
1720+
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len();
17211721

17221722
if remap_path_prefix_targets < remap_path_prefix_sources {
17231723
for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {

0 commit comments

Comments
 (0)