@@ -415,42 +415,27 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
415
415
// information about failed comparisons to aid in debugging.
416
416
let fingerprint = calculate ( cx, unit) ?;
417
417
let mtime_on_use = cx. bcx . config . cli_unstable ( ) . mtime_on_use ;
418
- let compare = compare_old_fingerprint ( unit, & loc, & * fingerprint, mtime_on_use) ;
418
+ let dirty_reason = compare_old_fingerprint ( unit, & loc, & * fingerprint, mtime_on_use, force ) ;
419
419
420
- // If our comparison failed or reported dirty (e.g., we're going to trigger
421
- // a rebuild of this crate), then we also ensure the source of the crate
422
- // passes all verification checks before we build it.
420
+ let Some ( dirty_reason) = dirty_reason else {
421
+ return Ok ( Job :: new_fresh ( ) ) ;
422
+ } ;
423
+
424
+ // We're going to rebuild, so ensure the source of the crate passes all
425
+ // verification checks before we build it.
423
426
//
424
427
// The `Source::verify` method is intended to allow sources to execute
425
428
// pre-build checks to ensure that the relevant source code is all
426
429
// up-to-date and as expected. This is currently used primarily for
427
430
// directory sources which will use this hook to perform an integrity check
428
431
// on all files in the source to ensure they haven't changed. If they have
429
432
// changed then an error is issued.
430
- if compare
431
- . as_ref ( )
432
- . map ( |dirty| dirty. is_some ( ) )
433
- . unwrap_or ( true )
434
- {
435
- let source_id = unit. pkg . package_id ( ) . source_id ( ) ;
436
- let sources = bcx. packages . sources ( ) ;
437
- let source = sources
438
- . get ( source_id)
439
- . ok_or_else ( || internal ( "missing package source" ) ) ?;
440
- source. verify ( unit. pkg . package_id ( ) ) ?;
441
- }
442
-
443
- let dirty_reason = match compare {
444
- Ok ( None ) => {
445
- if force {
446
- Some ( DirtyReason :: Forced )
447
- } else {
448
- return Ok ( Job :: new_fresh ( ) ) ;
449
- }
450
- }
451
- Ok ( reason) => reason,
452
- Err ( _) => None ,
453
- } ;
433
+ let source_id = unit. pkg . package_id ( ) . source_id ( ) ;
434
+ let sources = bcx. packages . sources ( ) ;
435
+ let source = sources
436
+ . get ( source_id)
437
+ . ok_or_else ( || internal ( "missing package source" ) ) ?;
438
+ source. verify ( unit. pkg . package_id ( ) ) ?;
454
439
455
440
// Clear out the old fingerprint file if it exists. This protects when
456
441
// compilation is interrupted leaving a corrupt file. For example, a
@@ -521,7 +506,7 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
521
506
Work :: new ( move |_| write_fingerprint ( & loc, & fingerprint) )
522
507
} ;
523
508
524
- Ok ( Job :: new_dirty ( write_fingerprint, dirty_reason) )
509
+ Ok ( Job :: new_dirty ( write_fingerprint, Some ( dirty_reason) ) )
525
510
}
526
511
527
512
/// Dependency edge information for fingerprints. This is generated for each
@@ -1755,10 +1740,15 @@ fn compare_old_fingerprint(
1755
1740
old_hash_path : & Path ,
1756
1741
new_fingerprint : & Fingerprint ,
1757
1742
mtime_on_use : bool ,
1758
- ) -> CargoResult < Option < DirtyReason > > {
1743
+ forced : bool ,
1744
+ ) -> Option < DirtyReason > {
1759
1745
let compare = _compare_old_fingerprint ( old_hash_path, new_fingerprint, mtime_on_use) ;
1760
1746
log_compare ( unit, & compare) ;
1761
- compare
1747
+ match compare {
1748
+ Ok ( None ) if forced => Some ( DirtyReason :: Forced ) ,
1749
+ Ok ( reason) => reason,
1750
+ Err ( _) => Some ( DirtyReason :: FreshBuild ) ,
1751
+ }
1762
1752
}
1763
1753
1764
1754
fn _compare_old_fingerprint (
0 commit comments