@@ -80,6 +80,17 @@ impl fmt::Debug for Metadata {
80
80
}
81
81
}
82
82
83
+ /// Information about the metadata hashes used for a `Unit`.
84
+ struct MetaInfo {
85
+ /// The symbol hash to use.
86
+ meta_hash : Metadata ,
87
+ /// Whether or not the `-C extra-filename` flag is used to generate unique
88
+ /// output filenames for this `Unit`.
89
+ ///
90
+ /// If this is `true`, the `meta_hash` is used for the filename.
91
+ use_extra_filename : bool ,
92
+ }
93
+
83
94
/// Collection of information about the files emitted by the compiler, and the
84
95
/// output directory structure.
85
96
pub struct CompilationFiles < ' a , ' cfg > {
@@ -94,7 +105,7 @@ pub struct CompilationFiles<'a, 'cfg> {
94
105
roots : Vec < Unit > ,
95
106
ws : & ' a Workspace < ' cfg > ,
96
107
/// Metadata hash to use for each unit.
97
- metas : HashMap < Unit , Option < Metadata > > ,
108
+ metas : HashMap < Unit , MetaInfo > ,
98
109
/// For each Unit, a list all files produced.
99
110
outputs : HashMap < Unit , LazyCell < Arc < Vec < OutputFile > > > > ,
100
111
}
@@ -160,11 +171,14 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
160
171
/// Gets the metadata for the given unit.
161
172
///
162
173
/// See module docs for more details.
163
- ///
164
- /// Returns `None` if the unit should not use a metadata hash (like
165
- /// rustdoc, or some dylibs).
166
- pub fn metadata ( & self , unit : & Unit ) -> Option < Metadata > {
167
- self . metas [ unit]
174
+ pub fn metadata ( & self , unit : & Unit ) -> Metadata {
175
+ self . metas [ unit] . meta_hash
176
+ }
177
+
178
+ /// Returns whether or not `-C extra-filename` is used to extend the
179
+ /// output filenames to make them unique.
180
+ pub fn use_extra_filename ( & self , unit : & Unit ) -> bool {
181
+ self . metas [ unit] . use_extra_filename
168
182
}
169
183
170
184
/// Gets the short hash based only on the `PackageId`.
@@ -201,9 +215,11 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
201
215
/// taken in those cases!
202
216
fn pkg_dir ( & self , unit : & Unit ) -> String {
203
217
let name = unit. pkg . package_id ( ) . name ( ) ;
204
- match self . metas [ unit] {
205
- Some ( ref meta) => format ! ( "{}-{}" , name, meta) ,
206
- None => format ! ( "{}-{}" , name, self . target_short_hash( unit) ) ,
218
+ let meta = & self . metas [ unit] ;
219
+ if meta. use_extra_filename {
220
+ format ! ( "{}-{}" , name, meta. meta_hash)
221
+ } else {
222
+ format ! ( "{}-{}" , name, self . target_short_hash( unit) )
207
223
}
208
224
}
209
225
@@ -448,8 +464,9 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
448
464
// Convert FileType to OutputFile.
449
465
let mut outputs = Vec :: new ( ) ;
450
466
for file_type in file_types {
451
- let meta = self . metadata ( unit) . map ( |m| m. to_string ( ) ) ;
452
- let path = out_dir. join ( file_type. output_filename ( & unit. target , meta. as_deref ( ) ) ) ;
467
+ let meta = & self . metas [ unit] ;
468
+ let meta_opt = meta. use_extra_filename . then ( || meta. meta_hash . to_string ( ) ) ;
469
+ let path = out_dir. join ( file_type. output_filename ( & unit. target , meta_opt. as_deref ( ) ) ) ;
453
470
let hardlink = self . uplift_to ( unit, & file_type, & path) ;
454
471
let export_path = if unit. target . is_custom_build ( ) {
455
472
None
@@ -471,30 +488,27 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
471
488
}
472
489
}
473
490
474
- fn metadata_of (
491
+ fn metadata_of < ' a > (
475
492
unit : & Unit ,
476
493
cx : & Context < ' _ , ' _ > ,
477
- metas : & mut HashMap < Unit , Option < Metadata > > ,
478
- ) -> Option < Metadata > {
494
+ metas : & ' a mut HashMap < Unit , MetaInfo > ,
495
+ ) -> & ' a MetaInfo {
479
496
if !metas. contains_key ( unit) {
480
497
let meta = compute_metadata ( unit, cx, metas) ;
481
498
metas. insert ( unit. clone ( ) , meta) ;
482
499
for dep in cx. unit_deps ( unit) {
483
500
metadata_of ( & dep. unit , cx, metas) ;
484
501
}
485
502
}
486
- metas[ unit]
503
+ & metas[ unit]
487
504
}
488
505
489
506
fn compute_metadata (
490
507
unit : & Unit ,
491
508
cx : & Context < ' _ , ' _ > ,
492
- metas : & mut HashMap < Unit , Option < Metadata > > ,
493
- ) -> Option < Metadata > {
509
+ metas : & mut HashMap < Unit , MetaInfo > ,
510
+ ) -> MetaInfo {
494
511
let bcx = & cx. bcx ;
495
- if !should_use_metadata ( bcx, unit) {
496
- return None ;
497
- }
498
512
let mut hasher = StableHasher :: new ( ) ;
499
513
500
514
METADATA_VERSION . hash ( & mut hasher) ;
@@ -514,7 +528,7 @@ fn compute_metadata(
514
528
let mut deps_metadata = cx
515
529
. unit_deps ( unit)
516
530
. iter ( )
517
- . map ( |dep| metadata_of ( & dep. unit , cx, metas) )
531
+ . map ( |dep| metadata_of ( & dep. unit , cx, metas) . meta_hash )
518
532
. collect :: < Vec < _ > > ( ) ;
519
533
deps_metadata. sort ( ) ;
520
534
deps_metadata. hash ( & mut hasher) ;
@@ -561,7 +575,10 @@ fn compute_metadata(
561
575
// with user dependencies.
562
576
unit. is_std . hash ( & mut hasher) ;
563
577
564
- Some ( Metadata ( hasher. finish ( ) ) )
578
+ MetaInfo {
579
+ meta_hash : Metadata ( hasher. finish ( ) ) ,
580
+ use_extra_filename : should_use_metadata ( bcx, unit) ,
581
+ }
565
582
}
566
583
567
584
fn hash_rustc_version ( bcx : & BuildContext < ' _ , ' _ > , hasher : & mut StableHasher ) {
0 commit comments