@@ -16,7 +16,7 @@ use rustc_session::config::{
1616use rustc_session:: config:: { CFGuard , ExternEntry , LinkerPluginLto , LtoCli , SwitchWithOptPath } ;
1717use rustc_session:: lint:: Level ;
1818use rustc_session:: search_paths:: SearchPath ;
19- use rustc_session:: utils:: { CanonicalizedPath , NativeLib , NativeLibKind } ;
19+ use rustc_session:: utils:: { CanonicalizedPath , ContentHashedFilePath , NativeLib , NativeLibKind } ;
2020use rustc_session:: { build_session, getopts, DiagnosticOutput , Session } ;
2121use rustc_span:: edition:: { Edition , DEFAULT_EDITION } ;
2222use rustc_span:: symbol:: sym;
@@ -594,7 +594,6 @@ fn test_codegen_options_tracking_hash() {
594594 tracked ! ( passes, vec![ String :: from( "1" ) , String :: from( "2" ) ] ) ;
595595 tracked ! ( prefer_dynamic, true ) ;
596596 tracked ! ( profile_generate, SwitchWithOptPath :: Enabled ( None ) ) ;
597- tracked ! ( profile_use, Some ( PathBuf :: from( "abc" ) ) ) ;
598597 tracked ! ( relocation_model, Some ( RelocModel :: Pic ) ) ;
599598 tracked ! ( soft_float, true ) ;
600599 tracked ! ( split_debuginfo, Some ( SplitDebuginfo :: Packed ) ) ;
@@ -777,7 +776,6 @@ fn test_unstable_options_tracking_hash() {
777776 tracked ! ( profile, true ) ;
778777 tracked ! ( profile_emit, Some ( PathBuf :: from( "abc" ) ) ) ;
779778 tracked ! ( profiler_runtime, "abc" . to_string( ) ) ;
780- tracked ! ( profile_sample_use, Some ( PathBuf :: from( "abc" ) ) ) ;
781779 tracked ! ( relax_elf_relocations, Some ( true ) ) ;
782780 tracked ! ( relro_level, Some ( RelroLevel :: Full ) ) ;
783781 tracked ! ( remap_cwd_prefix, Some ( PathBuf :: from( "abc" ) ) ) ;
@@ -818,6 +816,41 @@ fn test_unstable_options_tracking_hash() {
818816 tracked_no_crate_hash ! ( no_codegen, true ) ;
819817}
820818
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+
821854#[ test]
822855fn test_edition_parsing ( ) {
823856 // test default edition
0 commit comments