@@ -275,8 +275,6 @@ pub fn prepare_target<'a, 'cfg>(
275
275
return Ok ( Job :: new ( Work :: noop ( ) , Fresh ) ) ;
276
276
}
277
277
278
- let pkg_root = unit. pkg . root ( ) . to_path_buf ( ) ;
279
- let target_root = target_root ( cx, unit) ;
280
278
let write_fingerprint = if unit. mode . is_run_custom_build ( ) {
281
279
// For build scripts the `local` field of the fingerprint may change
282
280
// while we're executing it. For example it could be in the legacy
@@ -295,30 +293,20 @@ pub fn prepare_target<'a, 'cfg>(
295
293
let outputs = state. outputs . lock ( ) . unwrap ( ) ;
296
294
let outputs = & outputs[ & key] ;
297
295
let deps = BuildDeps :: new ( & output_path, Some ( outputs) ) ;
296
+
297
+ // FIXME: it's basically buggy that we pass `None` to `call_box`
298
+ // here. See documentation on `build_script_local_fingerprints`
299
+ // below for more information. Despite this just try to proceed and
300
+ // hobble along if it happens to return `Some`.
298
301
if let Some ( new_local) = gen_local. call_box ( & deps, None ) ? {
299
- // Note that the fingerprint status here is also somewhat
300
- // tricky. We can't actually modify the `fingerprint`'s `local`
301
- // field, so we create a new fingerprint with the appropriate
302
- // `local`. To ensure the old version is used correctly we
303
- // force its memoized hash to be equal to our
304
- // `new_fingerprint`. This means usages of `fingerprint` in
305
- // various dependencies should work correctly because the hash
306
- // is still memoized to the correct value.
307
- let mut new_fingerprint = fingerprint. with_local ( new_local) ;
308
- new_fingerprint. check_filesystem ( & pkg_root, & target_root, false ) ?;
309
- * fingerprint. memoized_hash . lock ( ) . unwrap ( ) = Some ( new_fingerprint. hash ( ) ) ;
310
- write_fingerprint ( & loc, & new_fingerprint)
311
- } else {
312
- // FIXME: it's basically buggy that we pass `None` to
313
- // `call_box` above. See documentation on
314
- // `build_script_local_fingerprints` below for more
315
- // information. Despite this just try to proceed and hobble
316
- // along.
317
- write_fingerprint ( & loc, & fingerprint)
302
+ * fingerprint. local . lock ( ) . unwrap ( ) = new_local;
303
+ * fingerprint. memoized_hash . lock ( ) . unwrap ( ) = None ;
318
304
}
305
+
306
+ write_fingerprint ( & loc, & fingerprint)
319
307
} )
320
308
} else {
321
- Work :: new ( move |_| write_fingerprint ( & loc, & * fingerprint) )
309
+ Work :: new ( move |_| write_fingerprint ( & loc, & fingerprint) )
322
310
} ;
323
311
324
312
Ok ( Job :: new ( write_fingerprint, Dirty ) )
@@ -375,7 +363,7 @@ pub struct Fingerprint {
375
363
deps : Vec < DepFingerprint > ,
376
364
/// Information about the inputs that affect this Unit (such as source
377
365
/// file mtimes or build script environment variables).
378
- local : Vec < LocalFingerprint > ,
366
+ local : Mutex < Vec < LocalFingerprint > > ,
379
367
/// Cached hash of the `Fingerprint` struct. Used to improve performance
380
368
/// for hashing.
381
369
#[ serde( skip) ]
@@ -446,7 +434,6 @@ impl<'de> Deserialize<'de> for DepFingerprint {
446
434
pkg_id,
447
435
name,
448
436
fingerprint : Arc :: new ( Fingerprint {
449
- local : vec ! [ LocalFingerprint :: Precalculated ( String :: new( ) ) ] ,
450
437
memoized_hash : Mutex :: new ( Some ( hash) ) ,
451
438
..Fingerprint :: new ( )
452
439
} ) ,
@@ -591,7 +578,7 @@ impl Fingerprint {
591
578
path : 0 ,
592
579
features : String :: new ( ) ,
593
580
deps : Vec :: new ( ) ,
594
- local : Vec :: new ( ) ,
581
+ local : Mutex :: new ( Vec :: new ( ) ) ,
595
582
memoized_hash : Mutex :: new ( None ) ,
596
583
rustflags : Vec :: new ( ) ,
597
584
metadata : 0 ,
@@ -600,23 +587,6 @@ impl Fingerprint {
600
587
}
601
588
}
602
589
603
- fn with_local ( & self , local : Vec < LocalFingerprint > ) -> Fingerprint {
604
- Fingerprint {
605
- fs_status : FsStatus :: Stale ,
606
- rustc : self . rustc ,
607
- target : self . target ,
608
- profile : self . profile ,
609
- path : self . path ,
610
- features : self . features . clone ( ) ,
611
- deps : self . deps . clone ( ) ,
612
- local,
613
- memoized_hash : Mutex :: new ( None ) ,
614
- rustflags : self . rustflags . clone ( ) ,
615
- metadata : self . metadata ,
616
- outputs : self . outputs . clone ( ) ,
617
- }
618
- }
619
-
620
590
fn hash ( & self ) -> u64 {
621
591
if let Some ( s) = * self . memoized_hash . lock ( ) . unwrap ( ) {
622
592
return s;
@@ -655,13 +625,15 @@ impl Fingerprint {
655
625
if self . rustflags != old. rustflags {
656
626
bail ! ( "RUSTFLAGS has changed" )
657
627
}
658
- if self . local . len ( ) != old. local . len ( ) {
659
- bail ! ( "local lens changed" ) ;
660
- }
661
628
if self . metadata != old. metadata {
662
629
bail ! ( "metadata changed" )
663
630
}
664
- for ( new, old) in self . local . iter ( ) . zip ( & old. local ) {
631
+ let my_local = self . local . lock ( ) . unwrap ( ) ;
632
+ let old_local = old. local . lock ( ) . unwrap ( ) ;
633
+ if my_local. len ( ) != old_local. len ( ) {
634
+ bail ! ( "local lens changed" ) ;
635
+ }
636
+ for ( new, old) in my_local. iter ( ) . zip ( old_local. iter ( ) ) {
665
637
match ( new, old) {
666
638
( LocalFingerprint :: Precalculated ( a) , LocalFingerprint :: Precalculated ( b) ) => {
667
639
if a != b {
@@ -840,7 +812,7 @@ impl Fingerprint {
840
812
// all our `LocalFingerprint` information to see if we have any stale
841
813
// files for this package itself. If we do find something log a helpful
842
814
// message and bail out so we stay stale.
843
- for local in self . local . iter ( ) {
815
+ for local in self . local . get_mut ( ) . unwrap ( ) . iter ( ) {
844
816
if let Some ( file) = local. find_stale_file ( pkg_root, target_root) ? {
845
817
file. log ( ) ;
846
818
return Ok ( ( ) ) ;
@@ -868,8 +840,9 @@ impl hash::Hash for Fingerprint {
868
840
ref rustflags,
869
841
..
870
842
} = * self ;
843
+ let local = local. lock ( ) . unwrap ( ) ;
871
844
(
872
- rustc, features, target, path, profile, local, metadata, rustflags,
845
+ rustc, features, target, path, profile, & * local, metadata, rustflags,
873
846
)
874
847
. hash ( h) ;
875
848
@@ -1089,7 +1062,7 @@ fn calculate_normal<'a, 'cfg>(
1089
1062
cx. bcx. resolve. features_sorted( unit. pkg. package_id( ) )
1090
1063
) ,
1091
1064
deps,
1092
- local,
1065
+ local : Mutex :: new ( local ) ,
1093
1066
memoized_hash : Mutex :: new ( None ) ,
1094
1067
metadata,
1095
1068
rustflags : extra_flags,
@@ -1141,7 +1114,7 @@ fn calculate_run_custom_build<'a, 'cfg>(
1141
1114
} ;
1142
1115
1143
1116
Ok ( Fingerprint {
1144
- local,
1117
+ local : Mutex :: new ( local ) ,
1145
1118
rustc : util:: hash_u64 ( & cx. bcx . rustc . verbose_version ) ,
1146
1119
deps,
1147
1120
outputs : if overridden { Vec :: new ( ) } else { vec ! [ output] } ,
0 commit comments