@@ -420,6 +420,7 @@ impl Step for SharedAssets {
420
420
pub struct Std {
421
421
pub stage : u32 ,
422
422
pub target : TargetSelection ,
423
+ pub format : DocumentationFormat ,
423
424
}
424
425
425
426
impl Step for Std {
@@ -432,7 +433,15 @@ impl Step for Std {
432
433
}
433
434
434
435
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
+ } ) ;
436
445
}
437
446
438
447
/// Compile all standard library documentation.
@@ -442,19 +451,26 @@ impl Step for Std {
442
451
fn run ( self , builder : & Builder < ' _ > ) {
443
452
let stage = self . stage ;
444
453
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
+
446
459
t ! ( fs:: create_dir_all( & out) ) ;
447
460
448
461
builder. ensure ( SharedAssets { target : self . target } ) ;
449
462
450
463
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
+ } ;
458
474
459
475
if !builder. config . docs_minification {
460
476
extra_args. push ( OsStr :: new ( "--disable-minification" ) ) ;
@@ -478,15 +494,12 @@ impl Step for Std {
478
494
} )
479
495
. collect :: < Vec < _ > > ( ) ;
480
496
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
+ }
490
503
491
504
// Look for library/std, library/core etc in the `x.py doc` arguments and
492
505
// open the corresponding rendered docs.
@@ -499,38 +512,6 @@ impl Step for Std {
499
512
}
500
513
}
501
514
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
-
534
515
/// Name of the crates that are visible to consumers of the standard library.
535
516
/// Documentation for internal crates is handled by the rustc step, so internal crates will show
536
517
/// up there.
@@ -543,7 +524,7 @@ impl Step for JsonStd {
543
524
const STD_PUBLIC_CRATES : [ & str ; 5 ] = [ "core" , "alloc" , "std" , "proc_macro" , "test" ] ;
544
525
545
526
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
546
- enum DocumentationFormat {
527
+ pub enum DocumentationFormat {
547
528
HTML ,
548
529
JSON ,
549
530
}
0 commit comments