@@ -685,8 +685,6 @@ impl Step for Rustc {
685685 target,
686686 ) ;
687687
688- let out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( target. triple ) . join ( "doc" ) ;
689-
690688 // Build cargo command.
691689 let mut cargo = builder. cargo ( compiler, Mode :: Rustc , SourceType :: InTree , target, "doc" ) ;
692690 cargo. rustdocflag ( "--document-private-items" ) ;
@@ -713,6 +711,7 @@ impl Step for Rustc {
713711
714712 let mut to_open = None ;
715713
714+ let out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( target. triple ) . join ( "doc" ) ;
716715 for krate in & * self . crates {
717716 // Create all crate output directories first to make sure rustdoc uses
718717 // relative links.
@@ -766,10 +765,10 @@ macro_rules! tool_doc {
766765 $should_run: literal,
767766 $path: literal,
768767 $( rustc_tool = $rustc_tool: literal, ) ?
769- $( in_tree = $in_tree: literal, ) ?
770- [ $ ( $extra_arg : literal ) ,+ $ ( , ) ?]
771- $( , ) ?
772- ) => {
768+ $( in_tree = $in_tree: literal , ) ?
769+ $ ( is_library = $is_library : expr , ) ?
770+ $( crates = $crates : expr ) ?
771+ ) => {
773772 #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
774773 pub struct $tool {
775774 target: TargetSelection ,
@@ -822,17 +821,6 @@ macro_rules! tool_doc {
822821 SourceType :: Submodule
823822 } ;
824823
825- // Symlink compiler docs to the output directory of rustdoc documentation.
826- let out_dirs = [
827- builder. stage_out( compiler, Mode :: ToolRustc ) . join( target. triple) . join( "doc" ) ,
828- // Cargo uses a different directory for proc macros.
829- builder. stage_out( compiler, Mode :: ToolRustc ) . join( "doc" ) ,
830- ] ;
831- for out_dir in out_dirs {
832- t!( fs:: create_dir_all( & out_dir) ) ;
833- symlink_dir_force( & builder. config, & out, & out_dir) ;
834- }
835-
836824 // Build cargo command.
837825 let mut cargo = prepare_tool_cargo(
838826 builder,
@@ -849,9 +837,13 @@ macro_rules! tool_doc {
849837 // Only include compiler crates, no dependencies of those, such as `libc`.
850838 cargo. arg( "--no-deps" ) ;
851839
852- $(
853- cargo. arg( $extra_arg) ;
854- ) +
840+ if false $( || $is_library) ? {
841+ cargo. arg( "--lib" ) ;
842+ }
843+
844+ $( for krate in $crates {
845+ cargo. arg( "-p" ) . arg( krate) ;
846+ } ) ?
855847
856848 cargo. rustdocflag( "--document-private-items" ) ;
857849 // Since we always pass --document-private-items, there's no need to warn about linking to private items.
@@ -861,62 +853,69 @@ macro_rules! tool_doc {
861853 cargo. rustdocflag( "--generate-link-to-definition" ) ;
862854 cargo. rustdocflag( "-Zunstable-options" ) ;
863855
856+ let out_dir = builder. stage_out( compiler, Mode :: ToolRustc ) . join( target. triple) . join( "doc" ) ;
857+ $( for krate in $crates {
858+ let dir_name = krate. replace( "-" , "_" ) ;
859+ t!( fs:: create_dir_all( out_dir. join( & * dir_name) ) ) ;
860+ } ) ?
861+
862+ // Symlink compiler docs to the output directory of rustdoc documentation.
863+ symlink_dir_force( & builder. config, & out, & out_dir) ;
864+ let proc_macro_out_dir = builder. stage_out( compiler, Mode :: ToolRustc ) . join( "doc" ) ;
865+ symlink_dir_force( & builder. config, & out, & proc_macro_out_dir) ;
866+
864867 let _guard = builder. msg_doc( compiler, stringify!( $tool) . to_lowercase( ) , target) ;
865868 builder. run( & mut cargo. into( ) ) ;
869+
870+ if !builder. config. dry_run( ) {
871+ // Sanity check on linked doc directories
872+ $( for krate in $crates {
873+ let dir_name = krate. replace( "-" , "_" ) ;
874+ // Making sure the directory exists and is not empty.
875+ assert!( out. join( & * dir_name) . read_dir( ) . unwrap( ) . next( ) . is_some( ) ) ;
876+ } ) ?
877+ }
866878 }
867879 }
868880 }
869881}
870882
871- tool_doc ! (
872- Rustdoc ,
873- "rustdoc-tool" ,
874- "src/tools/rustdoc" ,
875- [ "-p" , "rustdoc" , "-p" , "rustdoc-json-types" ]
876- ) ;
883+ tool_doc ! ( Rustdoc , "rustdoc-tool" , "src/tools/rustdoc" , crates = [ "rustdoc" , "rustdoc-json-types" ] ) ;
877884tool_doc ! (
878885 Rustfmt ,
879886 "rustfmt-nightly" ,
880887 "src/tools/rustfmt" ,
881- [ "-p" , " rustfmt-nightly", "-p" , " rustfmt-config_proc_macro"] ,
888+ crates = [ " rustfmt-nightly", "rustfmt-config_proc_macro" ]
882889) ;
883- tool_doc ! ( Clippy , "clippy" , "src/tools/clippy" , [ "-p" , "clippy_utils" ] ) ;
884- tool_doc ! ( Miri , "miri" , "src/tools/miri" , [ "-p" , "miri" ] ) ;
890+ tool_doc ! ( Clippy , "clippy" , "src/tools/clippy" , crates = [ "clippy_utils" ] ) ;
891+ tool_doc ! ( Miri , "miri" , "src/tools/miri" , crates = [ "miri" ] ) ;
885892tool_doc ! (
886893 Cargo ,
887894 "cargo" ,
888895 "src/tools/cargo" ,
889896 rustc_tool = false ,
890897 in_tree = false ,
891- [
892- "-p" ,
898+ crates = [
893899 "cargo" ,
894- "-p" ,
895900 "cargo-platform" ,
896- "-p" ,
897901 "cargo-util" ,
898- "-p" ,
899902 "crates-io" ,
900- "-p" ,
901903 "cargo-test-macro" ,
902- "-p" ,
903904 "cargo-test-support" ,
904- "-p" ,
905905 "cargo-credential" ,
906- "-p" ,
907906 "mdman" ,
908907 // FIXME: this trips a license check in tidy.
909- // "-p",
910908 // "resolver-tests",
911909 ]
912910) ;
913- tool_doc ! ( Tidy , "tidy" , "src/tools/tidy" , rustc_tool = false , [ "-p" , "tidy" ] ) ;
911+ tool_doc ! ( Tidy , "tidy" , "src/tools/tidy" , rustc_tool = false , crates = [ "tidy" ] ) ;
914912tool_doc ! (
915913 Bootstrap ,
916914 "bootstrap" ,
917915 "src/bootstrap" ,
918916 rustc_tool = false ,
919- [ "--lib" , "-p" , "bootstrap" ]
917+ is_library = true ,
918+ crates = [ "bootstrap" ]
920919) ;
921920
922921#[ derive( Ord , PartialOrd , Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
0 commit comments