@@ -734,17 +734,10 @@ enum LocalFingerprint {
734
734
/// The `dep_info` file, when present, also lists a number of other files
735
735
/// for us to look at. If any of those files are newer than this file then
736
736
/// we need to recompile.
737
- CheckDepInfo { dep_info : PathBuf } ,
738
-
739
- /// This is used for crate compilations. The `dep_info` file is a relative
740
- /// path anchored at `target_root(...)` to the dep-info file that Cargo
741
- /// generates (which is a custom serialization after parsing rustc's own
742
- /// `dep-info` output).
743
737
///
744
- /// The `dep_info` file, when present, also lists a number of other files
745
- /// for us to look at. If any of those files have a different checksum then
746
- /// we need to recompile.
747
- CheckDepInfoChecksums { dep_info : PathBuf } ,
738
+ /// If the `checksum` bool is true then the dep_info file is expected to
739
+ /// contain file checksums instead of file mtimes.
740
+ CheckDepInfo { dep_info : PathBuf , checksum : bool } ,
748
741
749
742
/// This represents a nonempty set of `rerun-if-changed` annotations printed
750
743
/// out by a build script. The `output` file is a relative file anchored at
@@ -837,42 +830,56 @@ impl LocalFingerprint {
837
830
// matches, and for each file we see if any of them are newer than
838
831
// the `dep_info` file itself whose mtime represents the start of
839
832
// rustc.
840
- LocalFingerprint :: CheckDepInfo { dep_info } => {
833
+ LocalFingerprint :: CheckDepInfo { dep_info, checksum } => {
841
834
let dep_info = target_root. join ( dep_info) ;
842
- let info = match dep_info_shared ( pkg_root, target_root, & dep_info, cargo_exe, gctx) ?
843
- {
844
- Either :: Left ( stale) => {
845
- return Ok ( Some ( stale) ) ;
846
- }
847
- Either :: Right ( info) => info,
835
+ let cargo_exe = cargo_exe;
836
+ let Some ( info) = parse_dep_info ( pkg_root, target_root, & dep_info) ? else {
837
+ return Ok ( Some ( StaleItem :: MissingFile ( dep_info. clone ( ) ) ) ) ;
848
838
} ;
849
- Ok ( find_stale_file (
850
- mtime_cache,
851
- checksum_cache,
852
- & dep_info,
853
- info. files . iter ( ) . map ( |p| ( p, None ) ) ,
854
- false ,
855
- ) )
856
- }
857
-
858
- LocalFingerprint :: CheckDepInfoChecksums { dep_info } => {
859
- let dep_info = target_root. join ( dep_info) ;
860
- let info = match dep_info_shared ( pkg_root, target_root, & dep_info, cargo_exe, gctx) ?
861
- {
862
- Either :: Left ( stale) => {
863
- return Ok ( Some ( stale) ) ;
839
+ for ( key, previous) in info. env . iter ( ) {
840
+ let current = if key == CARGO_ENV {
841
+ Some (
842
+ cargo_exe
843
+ . to_str ( )
844
+ . ok_or_else ( || {
845
+ format_err ! (
846
+ "cargo exe path {} must be valid UTF-8" ,
847
+ cargo_exe. display( )
848
+ )
849
+ } ) ?
850
+ . to_string ( ) ,
851
+ )
852
+ } else {
853
+ gctx. get_env ( key) . ok ( )
854
+ } ;
855
+ if current == * previous {
856
+ continue ;
864
857
}
865
- Either :: Right ( info) => info,
866
- } ;
867
- Ok ( find_stale_file (
868
- mtime_cache,
869
- checksum_cache,
870
- & dep_info,
871
- info. files
858
+ return Ok ( Some ( StaleItem :: ChangedEnv {
859
+ var : key. clone ( ) ,
860
+ previous : previous. clone ( ) ,
861
+ current,
862
+ } ) ) ;
863
+ }
864
+ macro_rules! find_stale_file {
865
+ ( $iter: expr) => {
866
+ Ok ( find_stale_file(
867
+ mtime_cache,
868
+ checksum_cache,
869
+ & dep_info,
870
+ $iter,
871
+ * checksum,
872
+ ) )
873
+ } ;
874
+ }
875
+ if * checksum {
876
+ find_stale_file ! ( info
877
+ . files
872
878
. iter( )
873
- . map ( |file| ( file. clone ( ) , info. checksum . get ( file) . cloned ( ) ) ) ,
874
- true ,
875
- ) )
879
+ . map( |file| ( file. clone( ) , info. checksum. get( file) . cloned( ) ) ) )
880
+ } else {
881
+ find_stale_file ! ( info. files. into_iter( ) . map( |p| ( p, None ) ) )
882
+ }
876
883
}
877
884
878
885
// We need to verify that no paths listed in `paths` are newer than
@@ -897,48 +904,12 @@ impl LocalFingerprint {
897
904
match self {
898
905
LocalFingerprint :: Precalculated ( ..) => "precalculated" ,
899
906
LocalFingerprint :: CheckDepInfo { .. } => "dep-info" ,
900
- LocalFingerprint :: CheckDepInfoChecksums { .. } => "dep-info-checksums" ,
901
907
LocalFingerprint :: RerunIfChanged { .. } => "rerun-if-changed" ,
902
908
LocalFingerprint :: RerunIfEnvChanged { .. } => "rerun-if-env-changed" ,
903
909
}
904
910
}
905
911
}
906
912
907
- fn dep_info_shared (
908
- pkg_root : & Path ,
909
- target_root : & Path ,
910
- dep_info : & PathBuf ,
911
- cargo_exe : & Path ,
912
- gctx : & GlobalContext ,
913
- ) -> Result < Either < StaleItem , RustcDepInfo > , anyhow:: Error > {
914
- let Some ( info) = parse_dep_info ( pkg_root, target_root, dep_info) ? else {
915
- return Ok ( Either :: Left ( StaleItem :: MissingFile ( dep_info. clone ( ) ) ) ) ;
916
- } ;
917
- for ( key, previous) in info. env . iter ( ) {
918
- let current = if key == CARGO_ENV {
919
- Some (
920
- cargo_exe
921
- . to_str ( )
922
- . ok_or_else ( || {
923
- format_err ! ( "cargo exe path {} must be valid UTF-8" , cargo_exe. display( ) )
924
- } ) ?
925
- . to_string ( ) ,
926
- )
927
- } else {
928
- gctx. get_env ( key) . ok ( )
929
- } ;
930
- if current == * previous {
931
- continue ;
932
- }
933
- return Ok ( Either :: Left ( StaleItem :: ChangedEnv {
934
- var : key. clone ( ) ,
935
- previous : previous. clone ( ) ,
936
- current,
937
- } ) ) ;
938
- }
939
- Ok ( Either :: Right ( info) )
940
- }
941
-
942
913
impl Fingerprint {
943
914
fn new ( ) -> Fingerprint {
944
915
Fingerprint {
@@ -1040,24 +1011,25 @@ impl Fingerprint {
1040
1011
}
1041
1012
}
1042
1013
(
1043
- LocalFingerprint :: CheckDepInfo { dep_info : adep } ,
1044
- LocalFingerprint :: CheckDepInfo { dep_info : bdep } ,
1014
+ LocalFingerprint :: CheckDepInfo {
1015
+ dep_info : adep,
1016
+ checksum : checksum_a,
1017
+ } ,
1018
+ LocalFingerprint :: CheckDepInfo {
1019
+ dep_info : bdep,
1020
+ checksum : checksum_b,
1021
+ } ,
1045
1022
) => {
1046
1023
if adep != bdep {
1047
1024
return DirtyReason :: DepInfoOutputChanged {
1048
1025
old : bdep. clone ( ) ,
1049
1026
new : adep. clone ( ) ,
1050
1027
} ;
1051
1028
}
1052
- }
1053
- (
1054
- LocalFingerprint :: CheckDepInfoChecksums { dep_info : adep } ,
1055
- LocalFingerprint :: CheckDepInfoChecksums { dep_info : bdep } ,
1056
- ) => {
1057
- if adep != bdep {
1058
- return DirtyReason :: DepInfoOutputChanged {
1059
- old : bdep. clone ( ) ,
1060
- new : adep. clone ( ) ,
1029
+ if checksum_a != checksum_b {
1030
+ return DirtyReason :: ChecksumUseChanged {
1031
+ old : * checksum_b,
1032
+ new : * checksum_a,
1061
1033
} ;
1062
1034
}
1063
1035
}
@@ -1516,11 +1488,10 @@ fn calculate_normal(
1516
1488
} else {
1517
1489
let dep_info = dep_info_loc ( build_runner, unit) ;
1518
1490
let dep_info = dep_info. strip_prefix ( & target_root) . unwrap ( ) . to_path_buf ( ) ;
1519
- if build_runner. bcx . gctx . cli_unstable ( ) . checksum_freshness {
1520
- vec ! [ LocalFingerprint :: CheckDepInfoChecksums { dep_info } ]
1521
- } else {
1522
- vec ! [ LocalFingerprint :: CheckDepInfo { dep_info } ]
1523
- }
1491
+ vec ! [ LocalFingerprint :: CheckDepInfo {
1492
+ dep_info,
1493
+ checksum: build_runner. bcx. gctx. cli_unstable( ) . checksum_freshness,
1494
+ } ]
1524
1495
} ;
1525
1496
1526
1497
// Figure out what the outputs of our unit is, and we'll be storing them
0 commit comments