@@ -685,19 +685,6 @@ impl Step for Rustc {
685
685
target,
686
686
) ;
687
687
688
- // This uses a shared directory so that librustdoc documentation gets
689
- // correctly built and merged with the rustc documentation. This is
690
- // needed because rustdoc is built in a different directory from
691
- // rustc. rustdoc needs to be able to see everything, for example when
692
- // merging the search index, or generating local (relative) links.
693
- let out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( target. triple ) . join ( "doc" ) ;
694
- t ! ( fs:: create_dir_all( out_dir. parent( ) . unwrap( ) ) ) ;
695
- symlink_dir_force ( & builder. config , & out, & out_dir) ;
696
- // Cargo puts proc macros in `target/doc` even if you pass `--target`
697
- // explicitly (https://github.com/rust-lang/cargo/issues/7677).
698
- let proc_macro_out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( "doc" ) ;
699
- symlink_dir_force ( & builder. config , & out, & proc_macro_out_dir) ;
700
-
701
688
// Build cargo command.
702
689
let mut cargo = builder. cargo ( compiler, Mode :: Rustc , SourceType :: InTree , target, "doc" ) ;
703
690
cargo. rustdocflag ( "--document-private-items" ) ;
@@ -724,6 +711,7 @@ impl Step for Rustc {
724
711
725
712
let mut to_open = None ;
726
713
714
+ let out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( target. triple ) . join ( "doc" ) ;
727
715
for krate in & * self . crates {
728
716
// Create all crate output directories first to make sure rustdoc uses
729
717
// relative links.
@@ -736,8 +724,29 @@ impl Step for Rustc {
736
724
}
737
725
}
738
726
727
+ // This uses a shared directory so that librustdoc documentation gets
728
+ // correctly built and merged with the rustc documentation.
729
+ //
730
+ // This is needed because rustdoc is built in a different directory from
731
+ // rustc. rustdoc needs to be able to see everything, for example when
732
+ // merging the search index, or generating local (relative) links.
733
+ symlink_dir_force ( & builder. config , & out, & out_dir) ;
734
+ // Cargo puts proc macros in `target/doc` even if you pass `--target`
735
+ // explicitly (https://github.com/rust-lang/cargo/issues/7677).
736
+ let proc_macro_out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( "doc" ) ;
737
+ symlink_dir_force ( & builder. config , & out, & proc_macro_out_dir) ;
738
+
739
739
builder. run ( & mut cargo. into ( ) ) ;
740
740
741
+ if !builder. config . dry_run ( ) {
742
+ // Sanity check on linked compiler crates
743
+ for krate in & * self . crates {
744
+ let dir_name = krate. replace ( "-" , "_" ) ;
745
+ // Making sure the directory exists and is not empty.
746
+ assert ! ( out. join( & * dir_name) . read_dir( ) . unwrap( ) . next( ) . is_some( ) ) ;
747
+ }
748
+ }
749
+
741
750
if builder. paths . iter ( ) . any ( |path| path. ends_with ( "compiler" ) ) {
742
751
// For `x.py doc compiler --open`, open `rustc_middle` by default.
743
752
let index = out. join ( "rustc_middle" ) . join ( "index.html" ) ;
@@ -756,10 +765,10 @@ macro_rules! tool_doc {
756
765
$should_run: literal,
757
766
$path: literal,
758
767
$( rustc_tool = $rustc_tool: literal, ) ?
759
- $( in_tree = $in_tree: literal, ) ?
760
- [ $ ( $extra_arg : literal ) ,+ $ ( , ) ?]
761
- $( , ) ?
762
- ) => {
768
+ $( in_tree = $in_tree: literal , ) ?
769
+ $ ( is_library = $is_library : expr , ) ?
770
+ $( crates = $crates : expr ) ?
771
+ ) => {
763
772
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
764
773
pub struct $tool {
765
774
target: TargetSelection ,
@@ -812,17 +821,6 @@ macro_rules! tool_doc {
812
821
SourceType :: Submodule
813
822
} ;
814
823
815
- // Symlink compiler docs to the output directory of rustdoc documentation.
816
- let out_dirs = [
817
- builder. stage_out( compiler, Mode :: ToolRustc ) . join( target. triple) . join( "doc" ) ,
818
- // Cargo uses a different directory for proc macros.
819
- builder. stage_out( compiler, Mode :: ToolRustc ) . join( "doc" ) ,
820
- ] ;
821
- for out_dir in out_dirs {
822
- t!( fs:: create_dir_all( & out_dir) ) ;
823
- symlink_dir_force( & builder. config, & out, & out_dir) ;
824
- }
825
-
826
824
// Build cargo command.
827
825
let mut cargo = prepare_tool_cargo(
828
826
builder,
@@ -839,9 +837,13 @@ macro_rules! tool_doc {
839
837
// Only include compiler crates, no dependencies of those, such as `libc`.
840
838
cargo. arg( "--no-deps" ) ;
841
839
842
- $(
843
- cargo. arg( $extra_arg) ;
844
- ) +
840
+ if false $( || $is_library) ? {
841
+ cargo. arg( "--lib" ) ;
842
+ }
843
+
844
+ $( for krate in $crates {
845
+ cargo. arg( "-p" ) . arg( krate) ;
846
+ } ) ?
845
847
846
848
cargo. rustdocflag( "--document-private-items" ) ;
847
849
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
@@ -851,62 +853,69 @@ macro_rules! tool_doc {
851
853
cargo. rustdocflag( "--generate-link-to-definition" ) ;
852
854
cargo. rustdocflag( "-Zunstable-options" ) ;
853
855
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
+
854
867
let _guard = builder. msg_doc( compiler, stringify!( $tool) . to_lowercase( ) , target) ;
855
868
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
+ }
856
878
}
857
879
}
858
880
}
859
881
}
860
882
861
- tool_doc ! (
862
- Rustdoc ,
863
- "rustdoc-tool" ,
864
- "src/tools/rustdoc" ,
865
- [ "-p" , "rustdoc" , "-p" , "rustdoc-json-types" ]
866
- ) ;
883
+ tool_doc ! ( Rustdoc , "rustdoc-tool" , "src/tools/rustdoc" , crates = [ "rustdoc" , "rustdoc-json-types" ] ) ;
867
884
tool_doc ! (
868
885
Rustfmt ,
869
886
"rustfmt-nightly" ,
870
887
"src/tools/rustfmt" ,
871
- [ "-p" , " rustfmt-nightly", "-p" , " rustfmt-config_proc_macro"] ,
888
+ crates = [ " rustfmt-nightly", "rustfmt-config_proc_macro" ]
872
889
) ;
873
- tool_doc ! ( Clippy , "clippy" , "src/tools/clippy" , [ "-p" , "clippy_utils" ] ) ;
874
- 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" ] ) ;
875
892
tool_doc ! (
876
893
Cargo ,
877
894
"cargo" ,
878
895
"src/tools/cargo" ,
879
896
rustc_tool = false ,
880
897
in_tree = false ,
881
- [
882
- "-p" ,
898
+ crates = [
883
899
"cargo" ,
884
- "-p" ,
885
900
"cargo-platform" ,
886
- "-p" ,
887
901
"cargo-util" ,
888
- "-p" ,
889
902
"crates-io" ,
890
- "-p" ,
891
903
"cargo-test-macro" ,
892
- "-p" ,
893
904
"cargo-test-support" ,
894
- "-p" ,
895
905
"cargo-credential" ,
896
- "-p" ,
897
906
"mdman" ,
898
907
// FIXME: this trips a license check in tidy.
899
- // "-p",
900
908
// "resolver-tests",
901
909
]
902
910
) ;
903
- 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" ] ) ;
904
912
tool_doc ! (
905
913
Bootstrap ,
906
914
"bootstrap" ,
907
915
"src/bootstrap" ,
908
916
rustc_tool = false ,
909
- [ "--lib" , "-p" , "bootstrap" ]
917
+ is_library = true ,
918
+ crates = [ "bootstrap" ]
910
919
) ;
911
920
912
921
#[ derive( Ord , PartialOrd , Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
0 commit comments