9
9
// except according to those terms.
10
10
11
11
use super :: * ;
12
-
13
12
use dep_graph:: { DepGraph , DepKind , DepNodeIndex } ;
13
+ use hir:: def_id:: { LOCAL_CRATE , CrateNum } ;
14
14
use hir:: intravisit:: { Visitor , NestedVisitorMap } ;
15
15
use hir:: svh:: Svh ;
16
16
use middle:: cstore:: CrateStore ;
17
17
use session:: CrateDisambiguator ;
18
18
use std:: iter:: repeat;
19
19
use syntax:: ast:: { NodeId , CRATE_NODE_ID } ;
20
+ use syntax:: codemap:: CodeMap ;
20
21
use syntax_pos:: Span ;
21
22
22
23
use ich:: StableHashingContext ;
@@ -123,6 +124,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
123
124
pub ( super ) fn finalize_and_compute_crate_hash ( self ,
124
125
crate_disambiguator : CrateDisambiguator ,
125
126
cstore : & CrateStore ,
127
+ codemap : & CodeMap ,
126
128
commandline_args_hash : u64 )
127
129
-> ( Vec < MapEntry < ' hir > > , Svh ) {
128
130
let mut node_hashes: Vec < _ > = self
@@ -147,11 +149,25 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
147
149
( name1, dis1) . cmp ( & ( name2, dis2) )
148
150
} ) ;
149
151
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
+
150
166
let ( _, crate_dep_node_index) = self
151
167
. dep_graph
152
168
. with_task ( DepNode :: new_no_params ( DepKind :: Krate ) ,
153
169
& self . hcx ,
154
- ( ( node_hashes, upstream_crates) ,
170
+ ( ( ( node_hashes, upstream_crates) , source_file_names ) ,
155
171
( commandline_args_hash,
156
172
crate_disambiguator. to_fingerprint ( ) ) ) ,
157
173
identity_fn) ;
0 commit comments