@@ -2548,95 +2548,74 @@ LLVM version: 9.0
25482548
25492549#[ cargo_test]
25502550fn doc_fingerprint_respects_target_paths ( ) {
2551+ let host = rustc_host ( ) ;
25512552 // Random rustc verbose version
25522553 let old_rustc_verbose_version = format ! (
25532554 "\
25542555 rustc 1.41.1 (f3e1a954d 2020-02-24)
25552556binary: rustc
25562557commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
25572558commit-date: 2020-02-24
2558- host: {}
2559+ host: {host }
25592560release: 1.41.1
25602561LLVM version: 9.0
25612562" ,
2562- rustc_host( )
25632563 ) ;
25642564
2565- // Create the dummy project.
2566- let dummy_project = project ( )
2565+ let p = project ( )
25672566 . file (
25682567 "Cargo.toml" ,
25692568 r#"
25702569 [package]
25712570 name = "foo"
2572- version = "1.2.4"
2573- edition = "2015"
2574- authors = []
2571+ edition = "2021"
25752572 "# ,
25762573 )
25772574 . file ( "src/lib.rs" , "//! These are the docs!" )
25782575 . build ( ) ;
25792576
2580- dummy_project. cargo ( "doc --target" ) . arg ( rustc_host ( ) ) . run ( ) ;
2577+ // generate `target/doc` and `target/<host>/doc
2578+ p. cargo ( "doc --target" ) . arg ( host) . run ( ) ;
2579+ p. cargo ( "doc" ) . run ( ) ;
25812580
2582- let fingerprint: RustDocFingerprint =
2583- serde_json:: from_str ( & dummy_project. read_file ( "target/.rustdoc_fingerprint.json" ) )
2581+ let host_fingerprint_path = p. build_dir ( ) . join ( ".rustdoc_fingerprint.json" ) ;
2582+
2583+ let target_fingerprint_path = p. build_dir ( ) . join ( host) . join ( ".rustdoc_fingerprint.json" ) ;
2584+
2585+ let host_fingerprint: RustDocFingerprint =
2586+ serde_json:: from_str ( & fs:: read_to_string ( & host_fingerprint_path) . unwrap ( ) )
25842587 . expect ( "JSON Serde fail" ) ;
25852588
2589+ assert ! ( !target_fingerprint_path. exists( ) ) ;
2590+
25862591 // Check that the fingerprint contains the actual rustc version
25872592 // which has been used to compile the docs.
2588- let output = std:: process:: Command :: new ( "rustc" )
2589- . arg ( "-vV" )
2590- . output ( )
2591- . expect ( "Failed to get actual rustc verbose version" ) ;
2592- assert_eq ! (
2593- fingerprint. rustc_vv,
2594- ( String :: from_utf8_lossy( & output. stdout) . as_ref( ) )
2595- ) ;
2596-
2597- // As the test shows above. Now we have generated the `doc/` folder and inside
2598- // the rustdoc fingerprint file is located with the correct rustc version.
2599- // So we will remove it and create a new fingerprint with an old rustc version
2600- // inside it. We will also place a bogus file inside of the `doc/` folder to ensure
2601- // it gets removed as we expect on the next doc compilation.
2602- dummy_project. change_file (
2603- "target/.rustdoc_fingerprint.json" ,
2604- & old_rustc_verbose_version,
2605- ) ;
2593+ let current_rustc_version = String :: from_utf8 (
2594+ std:: process:: Command :: new ( "rustc" )
2595+ . arg ( "-vV" )
2596+ . output ( )
2597+ . unwrap ( )
2598+ . stdout ,
2599+ )
2600+ . unwrap ( ) ;
2601+ assert_eq ! ( & host_fingerprint. rustc_vv, & current_rustc_version) ;
26062602
2603+ // Write random `rustc -vV` output and bogus file for host
2604+ fs:: write ( & host_fingerprint_path, & old_rustc_verbose_version) . unwrap ( ) ;
26072605 fs:: write (
2608- dummy_project
2609- . build_dir ( )
2610- . join ( rustc_host ( ) )
2611- . join ( "doc/bogus_file" ) ,
2612- String :: from ( "This is a bogus file and should be removed!" ) ,
2606+ p. build_dir ( ) . join ( "doc/bogus_file" ) ,
2607+ "This is a bogus file and should be removed!" ,
26132608 )
2614- . expect ( "Error writing test bogus file" ) ;
2615-
2616- // Now if we trigger another compilation, since the fingerprint contains an old version
2617- // of rustc, cargo should remove the entire `/doc` folder (including the fingerprint)
2618- // and generating another one with the actual version.
2619- // It should also remove the bogus file we created above.
2620- dummy_project. cargo ( "doc --target" ) . arg ( rustc_host ( ) ) . run ( ) ;
2609+ . unwrap ( ) ;
26212610
2622- assert ! (
2623- !dummy_project
2624- . build_dir( )
2625- . join( rustc_host( ) )
2626- . join( "doc/bogus_file" )
2627- . exists( )
2628- ) ;
2611+ // ...but run only target
2612+ p. cargo ( "doc --target" ) . arg ( host) . run ( ) ;
26292613
2614+ // host doc dir got cleaned
2615+ assert ! ( !p. build_dir( ) . join( "doc/bogus_file" ) . exists( ) ) ;
26302616 let fingerprint: RustDocFingerprint =
2631- serde_json:: from_str ( & dummy_project. read_file ( "target/.rustdoc_fingerprint.json" ) )
2632- . expect ( "JSON Serde fail" ) ;
2633-
2634- // Check that the fingerprint contains the actual rustc version
2635- // which has been used to compile the docs.
2636- assert_eq ! (
2637- fingerprint. rustc_vv,
2638- ( String :: from_utf8_lossy( & output. stdout) . as_ref( ) )
2639- ) ;
2617+ serde_json:: from_str ( & fs:: read_to_string ( & host_fingerprint_path) . unwrap ( ) ) . unwrap ( ) ;
2618+ assert_eq ! ( & fingerprint. rustc_vv, & current_rustc_version) ;
26402619}
26412620
26422621#[ cargo_test]
0 commit comments