@@ -16,6 +16,7 @@ use crate::builder::crate_description;
16
16
use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
17
17
use crate :: cache:: { Interned , INTERNER } ;
18
18
use crate :: compile;
19
+ use crate :: compile:: make_run_crates;
19
20
use crate :: config:: { Config , TargetSelection } ;
20
21
use crate :: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
21
22
use crate :: util:: { symlink_dir, t, up_to_date} ;
@@ -87,15 +88,6 @@ book!(
87
88
StyleGuide , "src/doc/style-guide" , "style-guide" ;
88
89
) ;
89
90
90
- // "library/std" -> ["library", "std"]
91
- //
92
- // Used for deciding whether a particular step is one requested by the user on
93
- // the `x.py doc` command line, which determines whether `--open` will open that
94
- // page.
95
- pub ( crate ) fn components_simplified ( path : & PathBuf ) -> Vec < & str > {
96
- path. iter ( ) . map ( |component| component. to_str ( ) . unwrap_or ( "???" ) ) . collect ( )
97
- }
98
-
99
91
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
100
92
pub struct UnstableBook {
101
93
target : TargetSelection ,
@@ -425,11 +417,18 @@ impl Step for SharedAssets {
425
417
}
426
418
}
427
419
428
- #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
420
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
429
421
pub struct Std {
430
422
pub stage : u32 ,
431
423
pub target : TargetSelection ,
432
424
pub format : DocumentationFormat ,
425
+ crates : Interned < Vec < String > > ,
426
+ }
427
+
428
+ impl Std {
429
+ pub ( crate ) fn new ( stage : u32 , target : TargetSelection , format : DocumentationFormat ) -> Self {
430
+ Std { stage, target, format, crates : INTERNER . intern_list ( vec ! [ ] ) }
431
+ }
433
432
}
434
433
435
434
impl Step for Std {
@@ -438,7 +437,7 @@ impl Step for Std {
438
437
439
438
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
440
439
let builder = run. builder ;
441
- run. all_krates ( "sysroot" ) . path ( "library" ) . default_condition ( builder. config . docs )
440
+ run. crate_or_deps ( "sysroot" ) . path ( "library" ) . default_condition ( builder. config . docs )
442
441
}
443
442
444
443
fn make_run ( run : RunConfig < ' _ > ) {
@@ -450,14 +449,15 @@ impl Step for Std {
450
449
} else {
451
450
DocumentationFormat :: HTML
452
451
} ,
452
+ crates : make_run_crates ( & run, "library" ) ,
453
453
} ) ;
454
454
}
455
455
456
456
/// Compile all standard library documentation.
457
457
///
458
458
/// This will generate all documentation for the standard library and its
459
459
/// dependencies. This is largely just a wrapper around `cargo doc`.
460
- fn run ( self , builder : & Builder < ' _ > ) {
460
+ fn run ( mut self , builder : & Builder < ' _ > ) {
461
461
let stage = self . stage ;
462
462
let target = self . target ;
463
463
let out = match self . format {
@@ -487,25 +487,7 @@ impl Step for Std {
487
487
extra_args. push ( OsStr :: new ( "--disable-minification" ) ) ;
488
488
}
489
489
490
- let requested_crates = builder
491
- . paths
492
- . iter ( )
493
- . map ( components_simplified)
494
- . filter_map ( |path| {
495
- if path. len ( ) >= 2 && path. get ( 0 ) == Some ( & "library" ) {
496
- // single crate
497
- Some ( path[ 1 ] . to_owned ( ) )
498
- } else if !path. is_empty ( ) {
499
- // ??
500
- Some ( path[ 0 ] . to_owned ( ) )
501
- } else {
502
- // all library crates
503
- None
504
- }
505
- } )
506
- . collect :: < Vec < _ > > ( ) ;
507
-
508
- doc_std ( builder, self . format , stage, target, & out, & extra_args, & requested_crates) ;
490
+ doc_std ( builder, self . format , stage, target, & out, & extra_args, & self . crates ) ;
509
491
510
492
// Don't open if the format is json
511
493
if let DocumentationFormat :: JSON = self . format {
@@ -514,7 +496,11 @@ impl Step for Std {
514
496
515
497
// Look for library/std, library/core etc in the `x.py doc` arguments and
516
498
// open the corresponding rendered docs.
517
- for requested_crate in requested_crates {
499
+ if self . crates . is_empty ( ) {
500
+ self . crates = INTERNER . intern_list ( vec ! [ "library" . to_owned( ) ] ) ;
501
+ } ;
502
+
503
+ for requested_crate in & * self . crates {
518
504
if requested_crate == "library" {
519
505
// For `x.py doc library --open`, open `std` by default.
520
506
let index = out. join ( "std" ) . join ( "index.html" ) ;
@@ -538,7 +524,7 @@ impl Step for Std {
538
524
/// or remote link.
539
525
const STD_PUBLIC_CRATES : [ & str ; 5 ] = [ "core" , "alloc" , "std" , "proc_macro" , "test" ] ;
540
526
541
- #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
527
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
542
528
pub enum DocumentationFormat {
543
529
HTML ,
544
530
JSON ,
@@ -566,21 +552,19 @@ fn doc_std(
566
552
extra_args : & [ & OsStr ] ,
567
553
requested_crates : & [ String ] ,
568
554
) {
569
- builder. info ( & format ! (
570
- "Documenting{} stage{} library ({}) in {} format" ,
571
- crate_description( requested_crates) ,
572
- stage,
573
- target,
574
- format. as_str( )
575
- ) ) ;
576
555
if builder. no_std ( target) == Some ( true ) {
577
556
panic ! (
578
557
"building std documentation for no_std target {target} is not supported\n \
579
- Set `docs = false` in the config to disable documentation."
558
+ Set `docs = false` in the config to disable documentation, or pass `--exclude doc::library` ."
580
559
) ;
581
560
}
561
+
582
562
let compiler = builder. compiler ( stage, builder. config . build ) ;
583
563
564
+ let description =
565
+ format ! ( "library{} in {} format" , crate_description( & requested_crates) , format. as_str( ) ) ;
566
+ let _guard = builder. msg ( Kind :: Doc , stage, & description, compiler. host , target) ;
567
+
584
568
let target_doc_dir_name = if format == DocumentationFormat :: JSON { "json-doc" } else { "doc" } ;
585
569
let target_dir =
586
570
builder. stage_out ( compiler, Mode :: Std ) . join ( target. triple ) . join ( target_doc_dir_name) ;
@@ -590,42 +574,56 @@ fn doc_std(
590
574
// as a function parameter.
591
575
let out_dir = target_dir. join ( target. triple ) . join ( "doc" ) ;
592
576
593
- let run_cargo_rustdoc_for = |package : & str | {
594
- let mut cargo = builder. cargo ( compiler, Mode :: Std , SourceType :: InTree , target, "rustdoc" ) ;
595
- compile:: std_cargo ( builder, target, compiler. stage , & mut cargo) ;
596
- cargo
597
- . arg ( "--target-dir" )
598
- . arg ( & * target_dir. to_string_lossy ( ) )
599
- . arg ( "-p" )
600
- . arg ( package)
601
- . arg ( "-Zskip-rustdoc-fingerprint" )
602
- . arg ( "--" )
603
- . arg ( "-Z" )
604
- . arg ( "unstable-options" )
605
- . arg ( "--resource-suffix" )
606
- . arg ( & builder. version )
607
- . args ( extra_args) ;
608
- if builder. config . library_docs_private_items {
609
- cargo. arg ( "--document-private-items" ) . arg ( "--document-hidden-items" ) ;
610
- }
611
- builder. run ( & mut cargo. into ( ) ) ;
612
- } ;
577
+ let mut cargo = builder. cargo ( compiler, Mode :: Std , SourceType :: InTree , target, "rustdoc" ) ;
578
+ compile:: std_cargo ( builder, target, compiler. stage , & mut cargo) ;
579
+ cargo. arg ( "--target-dir" ) . arg ( & * target_dir. to_string_lossy ( ) ) . arg ( "-Zskip-rustdoc-fingerprint" ) ;
613
580
614
- for krate in STD_PUBLIC_CRATES {
615
- run_cargo_rustdoc_for ( krate) ;
616
- if requested_crates. iter ( ) . any ( |p| p == krate) {
617
- // No need to document more of the libraries if we have the one we want.
618
- break ;
619
- }
581
+ for krate in requested_crates {
582
+ cargo. arg ( "-p" ) . arg ( krate) ;
620
583
}
621
584
585
+ cargo
586
+ . arg ( "--" )
587
+ . arg ( "-Z" )
588
+ . arg ( "unstable-options" )
589
+ . arg ( "--resource-suffix" )
590
+ . arg ( & builder. version )
591
+ . args ( extra_args) ;
592
+
593
+ if builder. config . library_docs_private_items {
594
+ cargo. arg ( "--document-private-items" ) . arg ( "--document-hidden-items" ) ;
595
+ }
596
+
597
+ builder. run ( & mut cargo. into ( ) ) ;
622
598
builder. cp_r ( & out_dir, & out) ;
623
599
}
624
600
625
601
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
626
602
pub struct Rustc {
627
603
pub stage : u32 ,
628
604
pub target : TargetSelection ,
605
+ crates : Interned < Vec < String > > ,
606
+ }
607
+
608
+ impl Rustc {
609
+ pub ( crate ) fn new ( stage : u32 , target : TargetSelection , builder : & Builder < ' _ > ) -> Self {
610
+ // Find dependencies for top level crates.
611
+ let root_crates = vec ! [
612
+ INTERNER . intern_str( "rustc_driver" ) ,
613
+ INTERNER . intern_str( "rustc_codegen_llvm" ) ,
614
+ INTERNER . intern_str( "rustc_codegen_ssa" ) ,
615
+ ] ;
616
+ let crates: Vec < _ > = root_crates
617
+ . iter ( )
618
+ . flat_map ( |krate| {
619
+ builder
620
+ . in_tree_crates ( krate, Some ( target) )
621
+ . into_iter ( )
622
+ . map ( |krate| krate. name . to_string ( ) )
623
+ } )
624
+ . collect ( ) ;
625
+ Self { stage, target, crates : INTERNER . intern_list ( crates) }
626
+ }
629
627
}
630
628
631
629
impl Step for Rustc {
@@ -641,7 +639,11 @@ impl Step for Rustc {
641
639
}
642
640
643
641
fn make_run ( run : RunConfig < ' _ > ) {
644
- run. builder . ensure ( Rustc { stage : run. builder . top_stage , target : run. target } ) ;
642
+ run. builder . ensure ( Rustc {
643
+ stage : run. builder . top_stage ,
644
+ target : run. target ,
645
+ crates : make_run_crates ( & run, "compiler" ) ,
646
+ } ) ;
645
647
}
646
648
647
649
/// Generates compiler documentation.
@@ -654,15 +656,6 @@ impl Step for Rustc {
654
656
let stage = self . stage ;
655
657
let target = self . target ;
656
658
657
- let paths = builder
658
- . paths
659
- . iter ( )
660
- . filter ( |path| {
661
- let components = components_simplified ( path) ;
662
- components. len ( ) >= 2 && components[ 0 ] == "compiler"
663
- } )
664
- . collect :: < Vec < _ > > ( ) ;
665
-
666
659
// This is the intended out directory for compiler documentation.
667
660
let out = builder. compiler_doc_out ( target) ;
668
661
t ! ( fs:: create_dir_all( & out) ) ;
@@ -672,7 +665,13 @@ impl Step for Rustc {
672
665
let compiler = builder. compiler ( stage, builder. config . build ) ;
673
666
builder. ensure ( compile:: Std :: new ( compiler, builder. config . build ) ) ;
674
667
675
- builder. info ( & format ! ( "Documenting stage{} compiler ({})" , stage, target) ) ;
668
+ let _guard = builder. msg (
669
+ Kind :: Doc ,
670
+ stage,
671
+ & format ! ( "compiler{}" , crate_description( & self . crates) ) ,
672
+ compiler. host ,
673
+ target,
674
+ ) ;
676
675
677
676
// This uses a shared directory so that librustdoc documentation gets
678
677
// correctly built and merged with the rustc documentation. This is
@@ -710,22 +709,8 @@ impl Step for Rustc {
710
709
cargo. rustdocflag ( "--extern-html-root-url" ) ;
711
710
cargo. rustdocflag ( "ena=https://docs.rs/ena/latest/" ) ;
712
711
713
- let root_crates = if paths. is_empty ( ) {
714
- vec ! [
715
- INTERNER . intern_str( "rustc_driver" ) ,
716
- INTERNER . intern_str( "rustc_codegen_llvm" ) ,
717
- INTERNER . intern_str( "rustc_codegen_ssa" ) ,
718
- ]
719
- } else {
720
- paths. into_iter ( ) . map ( |p| builder. crate_paths [ p] ) . collect ( )
721
- } ;
722
- // Find dependencies for top level crates.
723
- let compiler_crates = root_crates. iter ( ) . flat_map ( |krate| {
724
- builder. in_tree_crates ( krate, Some ( target) ) . into_iter ( ) . map ( |krate| krate. name )
725
- } ) ;
726
-
727
712
let mut to_open = None ;
728
- for krate in compiler_crates {
713
+ for krate in & * self . crates {
729
714
// Create all crate output directories first to make sure rustdoc uses
730
715
// relative links.
731
716
// FIXME: Cargo should probably do this itself.
@@ -785,7 +770,7 @@ macro_rules! tool_doc {
785
770
786
771
if true $( && $rustc_tool) ? {
787
772
// Build rustc docs so that we generate relative links.
788
- builder. ensure( Rustc { stage, target } ) ;
773
+ builder. ensure( Rustc :: new ( stage, target, builder ) ) ;
789
774
790
775
// Rustdoc needs the rustc sysroot available to build.
791
776
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
0 commit comments