@@ -16,7 +16,7 @@ use rustc_session::config::{
16
16
use rustc_session:: config:: { CFGuard , ExternEntry , LinkerPluginLto , LtoCli , SwitchWithOptPath } ;
17
17
use rustc_session:: lint:: Level ;
18
18
use rustc_session:: search_paths:: SearchPath ;
19
- use rustc_session:: utils:: { CanonicalizedPath , NativeLib , NativeLibKind } ;
19
+ use rustc_session:: utils:: { CanonicalizedPath , ContentHashedFilePath , NativeLib , NativeLibKind } ;
20
20
use rustc_session:: { build_session, getopts, DiagnosticOutput , Session } ;
21
21
use rustc_span:: edition:: { Edition , DEFAULT_EDITION } ;
22
22
use rustc_span:: symbol:: sym;
@@ -594,7 +594,6 @@ fn test_codegen_options_tracking_hash() {
594
594
tracked ! ( passes, vec![ String :: from( "1" ) , String :: from( "2" ) ] ) ;
595
595
tracked ! ( prefer_dynamic, true ) ;
596
596
tracked ! ( profile_generate, SwitchWithOptPath :: Enabled ( None ) ) ;
597
- tracked ! ( profile_use, Some ( PathBuf :: from( "abc" ) ) ) ;
598
597
tracked ! ( relocation_model, Some ( RelocModel :: Pic ) ) ;
599
598
tracked ! ( soft_float, true ) ;
600
599
tracked ! ( split_debuginfo, Some ( SplitDebuginfo :: Packed ) ) ;
@@ -777,7 +776,6 @@ fn test_unstable_options_tracking_hash() {
777
776
tracked ! ( profile, true ) ;
778
777
tracked ! ( profile_emit, Some ( PathBuf :: from( "abc" ) ) ) ;
779
778
tracked ! ( profiler_runtime, "abc" . to_string( ) ) ;
780
- tracked ! ( profile_sample_use, Some ( PathBuf :: from( "abc" ) ) ) ;
781
779
tracked ! ( relax_elf_relocations, Some ( true ) ) ;
782
780
tracked ! ( relro_level, Some ( RelroLevel :: Full ) ) ;
783
781
tracked ! ( remap_cwd_prefix, Some ( PathBuf :: from( "abc" ) ) ) ;
@@ -818,6 +816,41 @@ fn test_unstable_options_tracking_hash() {
818
816
tracked_no_crate_hash ! ( no_codegen, true ) ;
819
817
}
820
818
819
+ #[ test]
820
+ fn test_hashed_file_different_hash ( ) {
821
+ let tempdir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
822
+
823
+ let mut options = Options :: default ( ) ;
824
+
825
+ macro_rules! check {
826
+ ( $opt: expr, $file: expr) => {
827
+ let path = tempdir. path( ) . join( $file) ;
828
+
829
+ // Write some data into the file
830
+ std:: fs:: write( & path, & [ 1 , 2 , 3 ] ) . unwrap( ) ;
831
+
832
+ // The hash is calculated now
833
+ * $opt = Some ( ContentHashedFilePath :: new( path. clone( ) ) ) ;
834
+
835
+ let hash_no_crate = options. dep_tracking_hash( false ) ;
836
+ let hash_crate = options. dep_tracking_hash( true ) ;
837
+
838
+ // Write different data into the file
839
+ std:: fs:: write( & path, & [ 1 , 2 , 3 , 4 ] ) . unwrap( ) ;
840
+
841
+ // The hash is re-calculated now
842
+ * $opt = Some ( ContentHashedFilePath :: new( path) ) ;
843
+
844
+ // Check that the hash has changed
845
+ assert_ne!( options. dep_tracking_hash( true ) , hash_crate) ;
846
+ assert_ne!( options. dep_tracking_hash( false ) , hash_no_crate) ;
847
+ } ;
848
+ }
849
+
850
+ check ! ( & mut options. cg. profile_use, "profile-instr.profdata" ) ;
851
+ check ! ( & mut options. unstable_opts. profile_sample_use, "profile-sample.profdata" ) ;
852
+ }
853
+
821
854
#[ test]
822
855
fn test_edition_parsing ( ) {
823
856
// test default edition
0 commit comments