@@ -721,7 +721,7 @@ impl Step for Std {
721721 DocumentationFormat :: Html => {
722722 vec ! [ "--markdown-css" , "rust.css" , "--markdown-no-toc" , "--index-page" , & index_page]
723723 }
724- DocumentationFormat :: Json => vec ! [ "--output-format" , "json" ] ,
724+ DocumentationFormat :: Json => vec ! [ ] ,
725725 } ;
726726
727727 if !builder. config . docs_minification {
@@ -730,7 +730,47 @@ impl Step for Std {
730730 // For `--index-page` and `--output-format=json`.
731731 extra_args. push ( "-Zunstable-options" ) ;
732732
733- doc_std ( builder, self . format , self . build_compiler , target, & out, & extra_args, & crates) ;
733+ let target_doc_dir_name =
734+ if self . format == DocumentationFormat :: Json { "json-doc" } else { "doc" } ;
735+ let target_dir = builder
736+ . stage_out ( self . build_compiler , Mode :: Std )
737+ . join ( target)
738+ . join ( target_doc_dir_name) ;
739+
740+ // This is directory where the compiler will place the output of the command.
741+ // We will then copy the files from this directory into the final `out` directory, the specified
742+ // as a function parameter.
743+ let out_dir = target_dir. join ( target) . join ( "doc" ) ;
744+
745+ let mut cargo = doc_std (
746+ builder,
747+ self . format ,
748+ self . build_compiler ,
749+ target,
750+ & target_dir,
751+ & extra_args,
752+ & crates,
753+ ) ;
754+ match self . format {
755+ DocumentationFormat :: Html => { }
756+ DocumentationFormat :: Json => {
757+ // We have to pass these directly to cargo, rather than through RUSTDOCFLAGS,
758+ // otherwise Cargo will not detect freshness of the output correctly, and keep
759+ // rebuilding the docs on every invocation.
760+ cargo. args ( [ "-Zunstable-options" , "--output-format" , "json" ] ) ;
761+ }
762+ }
763+
764+ let description =
765+ format ! ( "library{} in {} format" , crate_description( & crates) , self . format. as_str( ) ) ;
766+
767+ {
768+ let _guard =
769+ builder. msg ( Kind :: Doc , description, Mode :: Std , self . build_compiler , target) ;
770+
771+ cargo. into_cmd ( ) . run ( builder) ;
772+ builder. cp_link_r ( & out_dir, & out) ;
773+ }
734774
735775 // Open if the format is HTML
736776 if let DocumentationFormat :: Html = self . format {
@@ -787,25 +827,16 @@ impl DocumentationFormat {
787827 }
788828}
789829
790- /// Build the documentation for public standard library crates.
830+ /// Prepare a Cargo command for building the documentation for public standard library crates.
791831fn doc_std (
792832 builder : & Builder < ' _ > ,
793833 format : DocumentationFormat ,
794834 build_compiler : Compiler ,
795835 target : TargetSelection ,
796- out : & Path ,
836+ target_dir : & Path ,
797837 extra_args : & [ & str ] ,
798838 requested_crates : & [ String ] ,
799- ) {
800- let target_doc_dir_name = if format == DocumentationFormat :: Json { "json-doc" } else { "doc" } ;
801- let target_dir =
802- builder. stage_out ( build_compiler, Mode :: Std ) . join ( target) . join ( target_doc_dir_name) ;
803-
804- // This is directory where the compiler will place the output of the command.
805- // We will then copy the files from this directory into the final `out` directory, the specified
806- // as a function parameter.
807- let out_dir = target_dir. join ( target) . join ( "doc" ) ;
808-
839+ ) -> builder:: Cargo {
809840 let mut cargo = builder:: Cargo :: new (
810841 builder,
811842 build_compiler,
@@ -836,13 +867,7 @@ fn doc_std(
836867 if format == DocumentationFormat :: Json || builder. config . library_docs_private_items {
837868 cargo. rustdocflag ( "--document-private-items" ) . rustdocflag ( "--document-hidden-items" ) ;
838869 }
839-
840- let description =
841- format ! ( "library{} in {} format" , crate_description( requested_crates) , format. as_str( ) ) ;
842- let _guard = builder. msg ( Kind :: Doc , description, Mode :: Std , build_compiler, target) ;
843-
844- cargo. into_cmd ( ) . run ( builder) ;
845- builder. cp_link_r ( & out_dir, out) ;
870+ cargo
846871}
847872
848873/// Prepare a compiler that will be able to document something for `target` at `stage`.
0 commit comments