@@ -415,43 +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 ( & loc, & * fingerprint, mtime_on_use) ;
419
- log_compare ( unit, & compare) ;
418
+ let dirty_reason = compare_old_fingerprint ( unit, & loc, & * fingerprint, mtime_on_use, force) ;
420
419
421
- // If our comparison failed or reported dirty (e.g., we're going to trigger
422
- // a rebuild of this crate), then we also ensure the source of the crate
423
- // 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.
424
426
//
425
427
// The `Source::verify` method is intended to allow sources to execute
426
428
// pre-build checks to ensure that the relevant source code is all
427
429
// up-to-date and as expected. This is currently used primarily for
428
430
// directory sources which will use this hook to perform an integrity check
429
431
// on all files in the source to ensure they haven't changed. If they have
430
432
// changed then an error is issued.
431
- if compare
432
- . as_ref ( )
433
- . map ( |dirty| dirty. is_some ( ) )
434
- . unwrap_or ( true )
435
- {
436
- let source_id = unit. pkg . package_id ( ) . source_id ( ) ;
437
- let sources = bcx. packages . sources ( ) ;
438
- let source = sources
439
- . get ( source_id)
440
- . ok_or_else ( || internal ( "missing package source" ) ) ?;
441
- source. verify ( unit. pkg . package_id ( ) ) ?;
442
- }
443
-
444
- let dirty_reason = match compare {
445
- Ok ( None ) => {
446
- if force {
447
- Some ( DirtyReason :: Forced )
448
- } else {
449
- return Ok ( Job :: new_fresh ( ) ) ;
450
- }
451
- }
452
- Ok ( reason) => reason,
453
- Err ( _) => None ,
454
- } ;
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 ( ) ) ?;
455
439
456
440
// Clear out the old fingerprint file if it exists. This protects when
457
441
// compilation is interrupted leaving a corrupt file. For example, a
@@ -1752,19 +1736,52 @@ fn target_root(cx: &Context<'_, '_>) -> PathBuf {
1752
1736
/// If dirty, it then restores the detailed information
1753
1737
/// from the fingerprint JSON file, and provides an rich dirty reason.
1754
1738
fn compare_old_fingerprint (
1739
+ unit : & Unit ,
1755
1740
old_hash_path : & Path ,
1756
1741
new_fingerprint : & Fingerprint ,
1757
1742
mtime_on_use : bool ,
1758
- ) -> CargoResult < Option < DirtyReason > > {
1759
- let old_fingerprint_short = paths:: read ( old_hash_path) ?;
1760
-
1743
+ forced : bool ,
1744
+ ) -> Option < DirtyReason > {
1761
1745
if mtime_on_use {
1762
1746
// update the mtime so other cleaners know we used it
1763
1747
let t = FileTime :: from_system_time ( SystemTime :: now ( ) ) ;
1764
1748
debug ! ( "mtime-on-use forcing {:?} to {}" , old_hash_path, t) ;
1765
1749
paths:: set_file_time_no_err ( old_hash_path, t) ;
1766
1750
}
1767
1751
1752
+ let compare = _compare_old_fingerprint ( old_hash_path, new_fingerprint) ;
1753
+
1754
+ match compare. as_ref ( ) {
1755
+ Ok ( None ) => { }
1756
+ Ok ( Some ( reason) ) => {
1757
+ info ! (
1758
+ "fingerprint dirty for {}/{:?}/{:?}" ,
1759
+ unit. pkg, unit. mode, unit. target,
1760
+ ) ;
1761
+ info ! ( " dirty: {reason:?}" ) ;
1762
+ }
1763
+ Err ( e) => {
1764
+ info ! (
1765
+ "fingerprint error for {}/{:?}/{:?}" ,
1766
+ unit. pkg, unit. mode, unit. target,
1767
+ ) ;
1768
+ info ! ( " err: {e:?}" ) ;
1769
+ }
1770
+ }
1771
+
1772
+ match compare {
1773
+ Ok ( None ) if forced => Some ( DirtyReason :: Forced ) ,
1774
+ Ok ( reason) => reason,
1775
+ Err ( _) => Some ( DirtyReason :: FreshBuild ) ,
1776
+ }
1777
+ }
1778
+
1779
+ fn _compare_old_fingerprint (
1780
+ old_hash_path : & Path ,
1781
+ new_fingerprint : & Fingerprint ,
1782
+ ) -> CargoResult < Option < DirtyReason > > {
1783
+ let old_fingerprint_short = paths:: read ( old_hash_path) ?;
1784
+
1768
1785
let new_hash = new_fingerprint. hash_u64 ( ) ;
1769
1786
1770
1787
if util:: to_hex ( new_hash) == old_fingerprint_short && new_fingerprint. fs_status . up_to_date ( ) {
@@ -1785,29 +1802,6 @@ fn compare_old_fingerprint(
1785
1802
Ok ( Some ( new_fingerprint. compare ( & old_fingerprint) ) )
1786
1803
}
1787
1804
1788
- /// Logs the result of fingerprint comparison.
1789
- ///
1790
- /// TODO: Obsolete and mostly superseded by [`DirtyReason`]. Could be removed.
1791
- fn log_compare ( unit : & Unit , compare : & CargoResult < Option < DirtyReason > > ) {
1792
- match compare {
1793
- Ok ( None ) => { }
1794
- Ok ( Some ( reason) ) => {
1795
- info ! (
1796
- "fingerprint dirty for {}/{:?}/{:?}" ,
1797
- unit. pkg, unit. mode, unit. target,
1798
- ) ;
1799
- info ! ( " dirty: {reason:?}" ) ;
1800
- }
1801
- Err ( e) => {
1802
- info ! (
1803
- "fingerprint error for {}/{:?}/{:?}" ,
1804
- unit. pkg, unit. mode, unit. target,
1805
- ) ;
1806
- info ! ( " err: {e:?}" ) ;
1807
- }
1808
- }
1809
- }
1810
-
1811
1805
/// Parses Cargo's internal [`EncodedDepInfo`] structure that was previously
1812
1806
/// serialized to disk.
1813
1807
///
0 commit comments