@@ -11,10 +11,9 @@ use std::fs;
1111use std:: path:: { Path , PathBuf } ;
1212
1313use 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 } ;
1515use crate :: cache:: { Interned , INTERNER } ;
1616use crate :: compile;
17- use crate :: compile:: make_run_crates;
1817use crate :: config:: { Config , TargetSelection } ;
1918use crate :: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
2019use crate :: util:: { symlink_dir, t, up_to_date} ;
@@ -424,8 +423,18 @@ pub struct Std {
424423}
425424
426425impl 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) }
429438 }
430439}
431440
@@ -447,15 +456,15 @@ impl Step for Std {
447456 } else {
448457 DocumentationFormat :: HTML
449458 } ,
450- crates : make_run_crates ( & run , "library" ) ,
459+ crates : run . make_run_crates ( Alias :: Library ) ,
451460 } ) ;
452461 }
453462
454463 /// Compile all standard library documentation.
455464 ///
456465 /// This will generate all documentation for the standard library and its
457466 /// dependencies. This is largely just a wrapper around `cargo doc`.
458- fn run ( mut self , builder : & Builder < ' _ > ) {
467+ fn run ( self , builder : & Builder < ' _ > ) {
459468 let stage = self . stage ;
460469 let target = self . target ;
461470 let out = match self . format {
@@ -493,20 +502,17 @@ impl Step for Std {
493502 return ;
494503 }
495504
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+ }
510516 }
511517 }
512518 }
@@ -539,9 +545,6 @@ impl DocumentationFormat {
539545}
540546
541547/// 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.
545548fn doc_std (
546549 builder : & Builder < ' _ > ,
547550 format : DocumentationFormat ,
@@ -592,19 +595,11 @@ fn doc_std(
592595 cargo. rustdocflag ( "--document-private-items" ) . rustdocflag ( "--document-hidden-items" ) ;
593596 }
594597
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+ }
608603 cargo. arg ( "-p" ) . arg ( krate) ;
609604 }
610605
@@ -621,20 +616,10 @@ pub struct Rustc {
621616
622617impl Rustc {
623618 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 ( ) )
638623 . collect ( ) ;
639624 Self { stage, target, crates : INTERNER . intern_list ( crates) }
640625 }
@@ -656,7 +641,7 @@ impl Step for Rustc {
656641 run. builder . ensure ( Rustc {
657642 stage : run. builder . top_stage ,
658643 target : run. target ,
659- crates : make_run_crates ( & run , "compiler" ) ,
644+ crates : run . make_run_crates ( Alias :: Compiler ) ,
660645 } ) ;
661646 }
662647
@@ -666,7 +651,7 @@ impl Step for Rustc {
666651 /// Compiler documentation is distributed separately, so we make sure
667652 /// we do not merge it with the other documentation from std, test and
668653 /// proc_macros. This is largely just a wrapper around `cargo doc`.
669- fn run ( mut self , builder : & Builder < ' _ > ) {
654+ fn run ( self , builder : & Builder < ' _ > ) {
670655 let stage = self . stage ;
671656 let target = self . target ;
672657
@@ -726,24 +711,26 @@ impl Step for Rustc {
726711
727712 let mut to_open = None ;
728713
729- if self . crates . is_empty ( ) {
730- self . crates = INTERNER . intern_list ( vec ! [ "rustc_driver" . to_owned( ) ] ) ;
731- } ;
732-
733714 for krate in & * self . crates {
734715 // Create all crate output directories first to make sure rustdoc uses
735716 // relative links.
736717 // 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) ) ) ;
738720 cargo. arg ( "-p" ) . arg ( krate) ;
739721 if to_open. is_none ( ) {
740- to_open = Some ( krate ) ;
722+ to_open = Some ( dir_name ) ;
741723 }
742724 }
743725
744726 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:
747734 let index = out. join ( krate) . join ( "index.html" ) ;
748735 builder. open_in_browser ( index) ;
749736 }
0 commit comments