11// ignore-tidy-filelength
22
3+ use std:: borrow:: Cow ;
34use std:: collections:: { HashMap , HashSet } ;
45use std:: ffi:: { OsStr , OsString } ;
56use std:: fs:: { self , create_dir_all, File , OpenOptions } ;
@@ -723,7 +724,7 @@ impl<'test> TestCx<'test> {
723724 self . maybe_add_external_args ( & mut rustc, & self . config . target_rustcflags ) ;
724725 rustc. args ( & self . props . compile_flags ) ;
725726
726- self . compose_and_run_compiler ( rustc, Some ( src) )
727+ self . compose_and_run_compiler ( rustc, Some ( src) , self . testpaths )
727728 }
728729
729730 fn run_debuginfo_test ( & self ) {
@@ -1579,13 +1580,15 @@ impl<'test> TestCx<'test> {
15791580 passes,
15801581 ) ;
15811582
1582- self . compose_and_run_compiler ( rustc, None )
1583+ self . compose_and_run_compiler ( rustc, None , self . testpaths )
15831584 }
15841585
1585- fn document ( & self , out_dir : & Path ) -> ProcRes {
1586+ /// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run.
1587+ /// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
1588+ fn document ( & self , root_out_dir : & Path , root_testpaths : & TestPaths ) -> ProcRes {
15861589 if self . props . build_aux_docs {
15871590 for rel_ab in & self . props . aux_builds {
1588- let aux_testpaths = self . compute_aux_test_paths ( & self . testpaths , rel_ab) ;
1591+ let aux_testpaths = self . compute_aux_test_paths ( root_testpaths , rel_ab) ;
15891592 let aux_props =
15901593 self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
15911594 let aux_cx = TestCx {
@@ -1596,7 +1599,9 @@ impl<'test> TestCx<'test> {
15961599 } ;
15971600 // Create the directory for the stdout/stderr files.
15981601 create_dir_all ( aux_cx. output_base_dir ( ) ) . unwrap ( ) ;
1599- let auxres = aux_cx. document ( out_dir) ;
1602+ // use root_testpaths here, because aux-builds should have the
1603+ // same --out-dir and auxiliary directory.
1604+ let auxres = aux_cx. document ( & root_out_dir, root_testpaths) ;
16001605 if !auxres. status . success ( ) {
16011606 return auxres;
16021607 }
@@ -1606,21 +1611,40 @@ impl<'test> TestCx<'test> {
16061611 let aux_dir = self . aux_output_dir_name ( ) ;
16071612
16081613 let rustdoc_path = self . config . rustdoc_path . as_ref ( ) . expect ( "--rustdoc-path not passed" ) ;
1609- let mut rustdoc = Command :: new ( rustdoc_path) ;
16101614
1615+ // actual --out-dir given to the auxiliary or test, as opposed to the root out dir for the entire
1616+ // test
1617+ let out_dir: Cow < ' _ , Path > = if self . props . unique_doc_out_dir {
1618+ let file_name = self . testpaths . file . file_stem ( ) . expect ( "file name should not be empty" ) ;
1619+ let out_dir = PathBuf :: from_iter ( [
1620+ root_out_dir,
1621+ Path :: new ( "docs" ) ,
1622+ Path :: new ( file_name) ,
1623+ Path :: new ( "doc" ) ,
1624+ ] ) ;
1625+ create_dir_all ( & out_dir) . unwrap ( ) ;
1626+ Cow :: Owned ( out_dir)
1627+ } else {
1628+ Cow :: Borrowed ( root_out_dir)
1629+ } ;
1630+
1631+ let mut rustdoc = Command :: new ( rustdoc_path) ;
1632+ let current_dir = output_base_dir ( self . config , root_testpaths, self . safe_revision ( ) ) ;
1633+ rustdoc. current_dir ( current_dir) ;
16111634 rustdoc
16121635 . arg ( "-L" )
16131636 . arg ( self . config . run_lib_path . to_str ( ) . unwrap ( ) )
16141637 . arg ( "-L" )
16151638 . arg ( aux_dir)
16161639 . arg ( "-o" )
1617- . arg ( out_dir)
1640+ . arg ( out_dir. as_ref ( ) )
16181641 . arg ( "--deny" )
16191642 . arg ( "warnings" )
16201643 . arg ( & self . testpaths . file )
16211644 . arg ( "-A" )
16221645 . arg ( "internal_features" )
1623- . args ( & self . props . compile_flags ) ;
1646+ . args ( & self . props . compile_flags )
1647+ . args ( & self . props . doc_flags ) ;
16241648
16251649 if self . config . mode == RustdocJson {
16261650 rustdoc. arg ( "--output-format" ) . arg ( "json" ) . arg ( "-Zunstable-options" ) ;
@@ -1630,7 +1654,7 @@ impl<'test> TestCx<'test> {
16301654 rustdoc. arg ( format ! ( "-Clinker={}" , linker) ) ;
16311655 }
16321656
1633- self . compose_and_run_compiler ( rustdoc, None )
1657+ self . compose_and_run_compiler ( rustdoc, None , root_testpaths )
16341658 }
16351659
16361660 fn exec_compiled_test ( & self ) -> ProcRes {
@@ -1828,9 +1852,16 @@ impl<'test> TestCx<'test> {
18281852 }
18291853 }
18301854
1831- fn compose_and_run_compiler ( & self , mut rustc : Command , input : Option < String > ) -> ProcRes {
1855+ /// `root_testpaths` refers to the path of the original test.
1856+ /// the auxiliary and the test with an aux-build have the same `root_testpaths`.
1857+ fn compose_and_run_compiler (
1858+ & self ,
1859+ mut rustc : Command ,
1860+ input : Option < String > ,
1861+ root_testpaths : & TestPaths ,
1862+ ) -> ProcRes {
18321863 let aux_dir = self . aux_output_dir ( ) ;
1833- self . build_all_auxiliary ( & self . testpaths , & aux_dir, & mut rustc) ;
1864+ self . build_all_auxiliary ( root_testpaths , & aux_dir, & mut rustc) ;
18341865
18351866 rustc. envs ( self . props . rustc_env . clone ( ) ) ;
18361867 self . props . unset_rustc_env . iter ( ) . fold ( & mut rustc, Command :: env_remove) ;
@@ -2545,7 +2576,7 @@ impl<'test> TestCx<'test> {
25452576 Vec :: new ( ) ,
25462577 ) ;
25472578
2548- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2579+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
25492580 let output_path = self . get_filecheck_file ( "ll" ) ;
25502581 ( proc_res, output_path)
25512582 }
@@ -2581,7 +2612,7 @@ impl<'test> TestCx<'test> {
25812612 Vec :: new ( ) ,
25822613 ) ;
25832614
2584- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2615+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
25852616 let output_path = self . get_filecheck_file ( "s" ) ;
25862617 ( proc_res, output_path)
25872618 }
@@ -2664,7 +2695,7 @@ impl<'test> TestCx<'test> {
26642695 let out_dir = self . output_base_dir ( ) ;
26652696 remove_and_create_dir_all ( & out_dir) ;
26662697
2667- let proc_res = self . document ( & out_dir) ;
2698+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
26682699 if !proc_res. status . success ( ) {
26692700 self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
26702701 }
@@ -2723,7 +2754,7 @@ impl<'test> TestCx<'test> {
27232754 let aux_dir = new_rustdoc. aux_output_dir ( ) ;
27242755 new_rustdoc. build_all_auxiliary ( & new_rustdoc. testpaths , & aux_dir, & mut rustc) ;
27252756
2726- let proc_res = new_rustdoc. document ( & compare_dir) ;
2757+ let proc_res = new_rustdoc. document ( & compare_dir, & new_rustdoc . testpaths ) ;
27272758 if !proc_res. status . success ( ) {
27282759 eprintln ! ( "failed to run nightly rustdoc" ) ;
27292760 return ;
@@ -2847,7 +2878,7 @@ impl<'test> TestCx<'test> {
28472878 let out_dir = self . output_base_dir ( ) ;
28482879 remove_and_create_dir_all ( & out_dir) ;
28492880
2850- let proc_res = self . document ( & out_dir) ;
2881+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
28512882 if !proc_res. status . success ( ) {
28522883 self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
28532884 }
@@ -2923,31 +2954,24 @@ impl<'test> TestCx<'test> {
29232954 fn check_rustdoc_test_option ( & self , res : ProcRes ) {
29242955 let mut other_files = Vec :: new ( ) ;
29252956 let mut files: HashMap < String , Vec < usize > > = HashMap :: new ( ) ;
2926- let cwd = env:: current_dir ( ) . unwrap ( ) ;
2927- files. insert (
2928- self . testpaths
2929- . file
2930- . strip_prefix ( & cwd)
2931- . unwrap_or ( & self . testpaths . file )
2932- . to_str ( )
2933- . unwrap ( )
2934- . replace ( '\\' , "/" ) ,
2935- self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ,
2936- ) ;
2957+ let normalized = fs:: canonicalize ( & self . testpaths . file ) . expect ( "failed to canonicalize" ) ;
2958+ let normalized = normalized. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2959+ files. insert ( normalized, self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ) ;
29372960 for other_file in other_files {
29382961 let mut path = self . testpaths . file . clone ( ) ;
29392962 path. set_file_name ( & format ! ( "{}.rs" , other_file) ) ;
2940- files. insert (
2941- path. strip_prefix ( & cwd) . unwrap_or ( & path) . to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ,
2942- self . get_lines ( & path, None ) ,
2943- ) ;
2963+ let path = fs:: canonicalize ( path) . expect ( "failed to canonicalize" ) ;
2964+ let normalized = path. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2965+ files. insert ( normalized, self . get_lines ( & path, None ) ) ;
29442966 }
29452967
29462968 let mut tested = 0 ;
29472969 for _ in res. stdout . split ( '\n' ) . filter ( |s| s. starts_with ( "test " ) ) . inspect ( |s| {
29482970 if let Some ( ( left, right) ) = s. split_once ( " - " ) {
29492971 let path = left. rsplit ( "test " ) . next ( ) . unwrap ( ) ;
2950- if let Some ( ref mut v) = files. get_mut ( & path. replace ( '\\' , "/" ) ) {
2972+ let path = fs:: canonicalize ( & path) . expect ( "failed to canonicalize" ) ;
2973+ let path = path. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2974+ if let Some ( ref mut v) = files. get_mut ( & path) {
29512975 tested += 1 ;
29522976 let mut iter = right. split ( "(line " ) ;
29532977 iter. next ( ) ;
@@ -3779,7 +3803,7 @@ impl<'test> TestCx<'test> {
37793803 if let Some ( nodejs) = & self . config . nodejs {
37803804 let out_dir = self . output_base_dir ( ) ;
37813805
3782- self . document ( & out_dir) ;
3806+ self . document ( & out_dir, & self . testpaths ) ;
37833807
37843808 let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
37853809 let file_stem =
@@ -4095,7 +4119,7 @@ impl<'test> TestCx<'test> {
40954119 rustc. arg ( crate_name) ;
40964120 }
40974121
4098- let res = self . compose_and_run_compiler ( rustc, None ) ;
4122+ let res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
40994123 if !res. status . success ( ) {
41004124 self . fatal_proc_rec ( "failed to compile fixed code" , & res) ;
41014125 }
0 commit comments