@@ -11,10 +11,9 @@ use std::fs;
11
11
use std:: path:: { Path , PathBuf } ;
12
12
13
13
use crate :: builder:: crate_description;
14
- use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
14
+ use crate :: builder:: { Alias , Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
15
15
use crate :: cache:: { Interned , INTERNER } ;
16
16
use crate :: compile;
17
- use crate :: compile:: make_run_crates;
18
17
use crate :: config:: { Config , TargetSelection } ;
19
18
use crate :: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
20
19
use crate :: util:: { symlink_dir, t, up_to_date} ;
@@ -424,8 +423,18 @@ pub struct Std {
424
423
}
425
424
426
425
impl Std {
427
- pub ( crate ) fn new ( stage : u32 , target : TargetSelection , format : DocumentationFormat ) -> Self {
428
- Std { stage, target, format, crates : INTERNER . intern_list ( vec ! [ ] ) }
426
+ pub ( crate ) fn new (
427
+ stage : u32 ,
428
+ target : TargetSelection ,
429
+ builder : & Builder < ' _ > ,
430
+ format : DocumentationFormat ,
431
+ ) -> Self {
432
+ let crates = builder
433
+ . in_tree_crates ( "sysroot" , Some ( target) )
434
+ . into_iter ( )
435
+ . map ( |krate| krate. name . to_string ( ) )
436
+ . collect ( ) ;
437
+ Std { stage, target, format, crates : INTERNER . intern_list ( crates) }
429
438
}
430
439
}
431
440
@@ -447,15 +456,15 @@ impl Step for Std {
447
456
} else {
448
457
DocumentationFormat :: HTML
449
458
} ,
450
- crates : make_run_crates ( & run , "library" ) ,
459
+ crates : run . make_run_crates ( Alias :: Library ) ,
451
460
} ) ;
452
461
}
453
462
454
463
/// Compile all standard library documentation.
455
464
///
456
465
/// This will generate all documentation for the standard library and its
457
466
/// dependencies. This is largely just a wrapper around `cargo doc`.
458
- fn run ( mut self , builder : & Builder < ' _ > ) {
467
+ fn run ( self , builder : & Builder < ' _ > ) {
459
468
let stage = self . stage ;
460
469
let target = self . target ;
461
470
let out = match self . format {
@@ -493,20 +502,17 @@ impl Step for Std {
493
502
return ;
494
503
}
495
504
496
- // Look for library/std, library/core etc in the `x.py doc` arguments and
497
- // open the corresponding rendered docs.
498
- if self . crates . is_empty ( ) {
499
- self . crates = INTERNER . intern_list ( vec ! [ "library" . to_owned( ) ] ) ;
500
- } ;
501
-
502
- for requested_crate in & * self . crates {
503
- if requested_crate == "library" {
504
- // For `x.py doc library --open`, open `std` by default.
505
- let index = out. join ( "std" ) . join ( "index.html" ) ;
506
- builder. open_in_browser ( index) ;
507
- } else if STD_PUBLIC_CRATES . iter ( ) . any ( |& k| k == requested_crate) {
508
- let index = out. join ( requested_crate) . join ( "index.html" ) ;
509
- builder. open_in_browser ( index) ;
505
+ if builder. paths . iter ( ) . any ( |path| path. ends_with ( "library" ) ) {
506
+ // For `x.py doc library --open`, open `std` by default.
507
+ let index = out. join ( "std" ) . join ( "index.html" ) ;
508
+ builder. open_in_browser ( index) ;
509
+ } else {
510
+ for requested_crate in & * self . crates {
511
+ if STD_PUBLIC_CRATES . iter ( ) . any ( |& k| k == requested_crate) {
512
+ let index = out. join ( requested_crate) . join ( "index.html" ) ;
513
+ builder. open_in_browser ( index) ;
514
+ break ;
515
+ }
510
516
}
511
517
}
512
518
}
@@ -539,9 +545,6 @@ impl DocumentationFormat {
539
545
}
540
546
541
547
/// Build the documentation for public standard library crates.
542
- ///
543
- /// `requested_crates` can be used to build only a subset of the crates. If empty, all crates will
544
- /// be built.
545
548
fn doc_std (
546
549
builder : & Builder < ' _ > ,
547
550
format : DocumentationFormat ,
@@ -592,19 +595,11 @@ fn doc_std(
592
595
cargo. rustdocflag ( "--document-private-items" ) . rustdocflag ( "--document-hidden-items" ) ;
593
596
}
594
597
595
- // HACK: because we use `--manifest-path library/sysroot/Cargo.toml`, cargo thinks we only want to document that specific crate, not its dependencies.
596
- // Override its default.
597
- let built_crates = if requested_crates. is_empty ( ) {
598
- builder
599
- . in_tree_crates ( "sysroot" , None )
600
- . into_iter ( )
601
- . map ( |krate| krate. name . to_string ( ) )
602
- . collect ( )
603
- } else {
604
- requested_crates. to_vec ( )
605
- } ;
606
-
607
- for krate in built_crates {
598
+ for krate in requested_crates {
599
+ if krate == "sysroot" {
600
+ // The sysroot crate is an implementation detail, don't include it in public docs.
601
+ continue ;
602
+ }
608
603
cargo. arg ( "-p" ) . arg ( krate) ;
609
604
}
610
605
@@ -621,20 +616,10 @@ pub struct Rustc {
621
616
622
617
impl Rustc {
623
618
pub ( crate ) fn new ( stage : u32 , target : TargetSelection , builder : & Builder < ' _ > ) -> Self {
624
- // Find dependencies for top level crates.
625
- let root_crates = vec ! [
626
- INTERNER . intern_str( "rustc_driver" ) ,
627
- INTERNER . intern_str( "rustc_codegen_llvm" ) ,
628
- INTERNER . intern_str( "rustc_codegen_ssa" ) ,
629
- ] ;
630
- let crates: Vec < _ > = root_crates
631
- . iter ( )
632
- . flat_map ( |krate| {
633
- builder
634
- . in_tree_crates ( krate, Some ( target) )
635
- . into_iter ( )
636
- . map ( |krate| krate. name . to_string ( ) )
637
- } )
619
+ let crates = builder
620
+ . in_tree_crates ( "rustc-main" , Some ( target) )
621
+ . into_iter ( )
622
+ . map ( |krate| krate. name . to_string ( ) )
638
623
. collect ( ) ;
639
624
Self { stage, target, crates : INTERNER . intern_list ( crates) }
640
625
}
@@ -656,7 +641,7 @@ impl Step for Rustc {
656
641
run. builder . ensure ( Rustc {
657
642
stage : run. builder . top_stage ,
658
643
target : run. target ,
659
- crates : make_run_crates ( & run , "compiler" ) ,
644
+ crates : run . make_run_crates ( Alias :: Compiler ) ,
660
645
} ) ;
661
646
}
662
647
@@ -666,7 +651,7 @@ impl Step for Rustc {
666
651
/// Compiler documentation is distributed separately, so we make sure
667
652
/// we do not merge it with the other documentation from std, test and
668
653
/// proc_macros. This is largely just a wrapper around `cargo doc`.
669
- fn run ( mut self , builder : & Builder < ' _ > ) {
654
+ fn run ( self , builder : & Builder < ' _ > ) {
670
655
let stage = self . stage ;
671
656
let target = self . target ;
672
657
@@ -726,24 +711,26 @@ impl Step for Rustc {
726
711
727
712
let mut to_open = None ;
728
713
729
- if self . crates . is_empty ( ) {
730
- self . crates = INTERNER . intern_list ( vec ! [ "rustc_driver" . to_owned( ) ] ) ;
731
- } ;
732
-
733
714
for krate in & * self . crates {
734
715
// Create all crate output directories first to make sure rustdoc uses
735
716
// relative links.
736
717
// FIXME: Cargo should probably do this itself.
737
- t ! ( fs:: create_dir_all( out_dir. join( krate) ) ) ;
718
+ let dir_name = krate. replace ( "-" , "_" ) ;
719
+ t ! ( fs:: create_dir_all( out_dir. join( & * dir_name) ) ) ;
738
720
cargo. arg ( "-p" ) . arg ( krate) ;
739
721
if to_open. is_none ( ) {
740
- to_open = Some ( krate ) ;
722
+ to_open = Some ( dir_name ) ;
741
723
}
742
724
}
743
725
744
726
builder. run ( & mut cargo. into ( ) ) ;
745
- // Let's open the first crate documentation page:
746
- if let Some ( krate) = to_open {
727
+
728
+ if builder. paths . iter ( ) . any ( |path| path. ends_with ( "compiler" ) ) {
729
+ // For `x.py doc compiler --open`, open `rustc_middle` by default.
730
+ let index = out. join ( "rustc_middle" ) . join ( "index.html" ) ;
731
+ builder. open_in_browser ( index) ;
732
+ } else if let Some ( krate) = to_open {
733
+ // Let's open the first crate documentation page:
747
734
let index = out. join ( krate) . join ( "index.html" ) ;
748
735
builder. open_in_browser ( index) ;
749
736
}
0 commit comments