@@ -420,6 +420,7 @@ impl Step for SharedAssets {
420420pub struct Std {
421421 pub stage : u32 ,
422422 pub target : TargetSelection ,
423+ pub format : DocumentationFormat ,
423424}
424425
425426impl Step for Std {
@@ -432,7 +433,15 @@ impl Step for Std {
432433 }
433434
434435 fn make_run ( run : RunConfig < ' _ > ) {
435- run. builder . ensure ( Std { stage : run. builder . top_stage , target : run. target } ) ;
436+ run. builder . ensure ( Std {
437+ stage : run. builder . top_stage ,
438+ target : run. target ,
439+ format : if run. builder . config . cmd . json ( ) {
440+ DocumentationFormat :: JSON
441+ } else {
442+ DocumentationFormat :: HTML
443+ } ,
444+ } ) ;
436445 }
437446
438447 /// Compile all standard library documentation.
@@ -442,19 +451,26 @@ impl Step for Std {
442451 fn run ( self , builder : & Builder < ' _ > ) {
443452 let stage = self . stage ;
444453 let target = self . target ;
445- let out = builder. doc_out ( target) ;
454+ let out = match self . format {
455+ DocumentationFormat :: HTML => builder. doc_out ( target) ,
456+ DocumentationFormat :: JSON => builder. json_doc_out ( target) ,
457+ } ;
458+
446459 t ! ( fs:: create_dir_all( & out) ) ;
447460
448461 builder. ensure ( SharedAssets { target : self . target } ) ;
449462
450463 let index_page = builder. src . join ( "src/doc/index.md" ) . into_os_string ( ) ;
451- let mut extra_args = vec ! [
452- OsStr :: new( "--markdown-css" ) ,
453- OsStr :: new( "rust.css" ) ,
454- OsStr :: new( "--markdown-no-toc" ) ,
455- OsStr :: new( "--index-page" ) ,
456- & index_page,
457- ] ;
464+ let mut extra_args = match self . format {
465+ DocumentationFormat :: HTML => vec ! [
466+ OsStr :: new( "--markdown-css" ) ,
467+ OsStr :: new( "rust.css" ) ,
468+ OsStr :: new( "--markdown-no-toc" ) ,
469+ OsStr :: new( "--index-page" ) ,
470+ & index_page,
471+ ] ,
472+ DocumentationFormat :: JSON => vec ! [ OsStr :: new( "--output-format" ) , OsStr :: new( "json" ) ] ,
473+ } ;
458474
459475 if !builder. config . docs_minification {
460476 extra_args. push ( OsStr :: new ( "--disable-minification" ) ) ;
@@ -478,15 +494,12 @@ impl Step for Std {
478494 } )
479495 . collect :: < Vec < _ > > ( ) ;
480496
481- doc_std (
482- builder,
483- DocumentationFormat :: HTML ,
484- stage,
485- target,
486- & out,
487- & extra_args,
488- & requested_crates,
489- ) ;
497+ doc_std ( builder, self . format , stage, target, & out, & extra_args, & requested_crates) ;
498+
499+ // Don't open if the format is json
500+ if let DocumentationFormat :: JSON = self . format {
501+ return ;
502+ }
490503
491504 // Look for library/std, library/core etc in the `x.py doc` arguments and
492505 // open the corresponding rendered docs.
@@ -499,38 +512,6 @@ impl Step for Std {
499512 }
500513}
501514
502- #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
503- pub struct JsonStd {
504- pub stage : u32 ,
505- pub target : TargetSelection ,
506- }
507-
508- impl Step for JsonStd {
509- type Output = ( ) ;
510- const DEFAULT : bool = false ;
511-
512- fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
513- let default = run. builder . config . docs && run. builder . config . cmd . json ( ) ;
514- run. all_krates ( "test" ) . path ( "library" ) . default_condition ( default)
515- }
516-
517- fn make_run ( run : RunConfig < ' _ > ) {
518- run. builder . ensure ( Std { stage : run. builder . top_stage , target : run. target } ) ;
519- }
520-
521- /// Build JSON documentation for the standard library crates.
522- ///
523- /// This is largely just a wrapper around `cargo doc`.
524- fn run ( self , builder : & Builder < ' _ > ) {
525- let stage = self . stage ;
526- let target = self . target ;
527- let out = builder. json_doc_out ( target) ;
528- t ! ( fs:: create_dir_all( & out) ) ;
529- let extra_args = [ OsStr :: new ( "--output-format" ) , OsStr :: new ( "json" ) ] ;
530- doc_std ( builder, DocumentationFormat :: JSON , stage, target, & out, & extra_args, & [ ] )
531- }
532- }
533-
534515/// Name of the crates that are visible to consumers of the standard library.
535516/// Documentation for internal crates is handled by the rustc step, so internal crates will show
536517/// up there.
@@ -543,7 +524,7 @@ impl Step for JsonStd {
543524const STD_PUBLIC_CRATES : [ & str ; 5 ] = [ "core" , "alloc" , "std" , "proc_macro" , "test" ] ;
544525
545526#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
546- enum DocumentationFormat {
527+ pub enum DocumentationFormat {
547528 HTML ,
548529 JSON ,
549530}
0 commit comments