@@ -20,10 +20,29 @@ use crate::core::builder::{
2020use crate :: core:: config:: { Config , TargetSelection } ;
2121use crate :: helpers:: { is_path_in_submodule, symlink_dir, t, up_to_date} ;
2222
23+ /// If the doc path is inside a submodule and is thus not the same as the submodule path, then we
24+ /// need to use the submodule path to checkout the submodule. The doc could be inside an submodule
25+ /// that is not checked out. Helper for [`book`].
26+ fn select_book_submodule_path < ' a > ( doc_path : & ' a str , submodule_path : Option < & ' a str > ) -> & ' a str {
27+ submodule_path. unwrap_or ( doc_path)
28+ }
29+
2330macro_rules! book {
24- ( $( $name: ident, $path: expr, $book_name: expr, $lang: expr ; ) +) => {
25- $(
26- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
31+ (
32+ $name: ident {
33+ name: $book_name: expr,
34+ // This can be *within* a submodule, e.g. `src/tools/cargo/src/doc`, compared to the
35+ // submodule *itself*.
36+ doc_path: $doc_path: expr
37+ // Optional; only needed if `doc_path` is inside the submodule path, i.e. they are not
38+ // the same.
39+ $( , submodule_path: $submodule_path: expr ) ?
40+ // Optional; only needed if the book has multi-lingual support.
41+ $( , languages: $languages: expr ) ?
42+ $( , ) ?
43+ }
44+ ) => {
45+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
2746 pub struct $name {
2847 target: TargetSelection ,
2948 }
@@ -34,49 +53,59 @@ macro_rules! book {
3453
3554 fn should_run( run: ShouldRun <' _>) -> ShouldRun <' _> {
3655 let builder = run. builder;
37- run. path( $path ) . default_condition( builder. config. docs)
56+ run. path( $doc_path ) . default_condition( builder. config. docs)
3857 }
3958
4059 fn make_run( run: RunConfig <' _>) {
41- run. builder. ensure( $name {
42- target: run. target,
43- } ) ;
60+ run. builder. ensure( $name { target: run. target } ) ;
4461 }
4562
4663 fn run( self , builder: & Builder <' _>) {
47- if is_path_in_submodule( & builder, $path) {
48- builder. require_submodule( $path, None ) ;
64+ let path = select_book_submodule_path(
65+ $doc_path,
66+ None $( . or( Some ( $submodule_path) ) ) ?,
67+ ) ;
68+
69+ if is_path_in_submodule( & builder, $doc_path) {
70+ builder. require_submodule( path, None ) ;
4971 }
5072
73+ #[ allow( unused_assignments, unused_mut) ]
74+ let mut languages: Vec <& str > = vec![ ] ;
75+ $( languages. extend( $languages) ; ) ?
76+
5177 builder. ensure( RustbookSrc {
5278 target: self . target,
5379 name: $book_name. to_owned( ) ,
54- src: builder. src. join( $path ) ,
80+ src: builder. src. join( $doc_path ) ,
5581 parent: Some ( self ) ,
56- languages: $lang . into ( ) ,
82+ languages,
5783 rustdoc_compiler: None ,
5884 } )
5985 }
6086 }
61- ) +
62- }
87+ } ;
6388}
6489
6590// NOTE: When adding a book here, make sure to ALSO build the book by
6691// adding a build step in `src/bootstrap/code/builder/mod.rs`!
6792// NOTE: Make sure to add the corresponding submodule when adding a new book.
68- // FIXME: Make checking for a submodule automatic somehow (maybe by having a list of all submodules
69- // and checking against it?).
70- book ! (
71- CargoBook , "src/tools/cargo/src/doc" , "cargo" , & [ ] ;
72- ClippyBook , "src/tools/clippy/book" , "clippy" , & [ ] ;
73- EditionGuide , "src/doc/edition-guide" , "edition-guide" , & [ ] ;
74- EmbeddedBook , "src/doc/embedded-book" , "embedded-book" , & [ ] ;
75- Nomicon , "src/doc/nomicon" , "nomicon" , & [ ] ;
76- RustByExample , "src/doc/rust-by-example" , "rust-by-example" , & [ "ja" , "zh" ] ;
77- RustdocBook , "src/doc/rustdoc" , "rustdoc" , & [ ] ;
78- StyleGuide , "src/doc/style-guide" , "style-guide" , & [ ] ;
79- ) ;
93+ book ! ( CargoBook {
94+ name: "cargo" ,
95+ doc_path: "src/tools/cargo/src/doc" ,
96+ submodule_path: "src/tools/cargo" ,
97+ } ) ;
98+ book ! ( ClippyBook { name: "clippy" , doc_path: "src/tools/clippy/book" } ) ;
99+ book ! ( EditionGuide { name: "edition-guide" , doc_path: "src/doc/edition-guide" } ) ;
100+ book ! ( EmbeddedBook { name: "embedded-book" , doc_path: "src/doc/embedded-book" } ) ;
101+ book ! ( Nomicon { name: "nomicon" , doc_path: "src/doc/nomicon" } ) ;
102+ book ! ( RustByExample {
103+ name: "rust-by-example" ,
104+ doc_path: "src/doc/rust-by-example" ,
105+ languages: & [ "ja" , "zh" ]
106+ } ) ;
107+ book ! ( RustdocBook { name: "rustdoc" , doc_path: "src/doc/rustdoc" } ) ;
108+ book ! ( StyleGuide { name: "style-guide" , doc_path: "src/doc/style-guide" } ) ;
80109
81110#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
82111pub struct UnstableBook {
0 commit comments