@@ -20,10 +20,29 @@ use crate::core::builder::{
20
20
use crate :: core:: config:: { Config , TargetSelection } ;
21
21
use crate :: helpers:: { is_path_in_submodule, symlink_dir, t, up_to_date} ;
22
22
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
+
23
30
macro_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 ) ]
27
46
pub struct $name {
28
47
target: TargetSelection ,
29
48
}
@@ -34,49 +53,59 @@ macro_rules! book {
34
53
35
54
fn should_run( run: ShouldRun <' _>) -> ShouldRun <' _> {
36
55
let builder = run. builder;
37
- run. path( $path ) . default_condition( builder. config. docs)
56
+ run. path( $doc_path ) . default_condition( builder. config. docs)
38
57
}
39
58
40
59
fn make_run( run: RunConfig <' _>) {
41
- run. builder. ensure( $name {
42
- target: run. target,
43
- } ) ;
60
+ run. builder. ensure( $name { target: run. target } ) ;
44
61
}
45
62
46
63
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 ) ;
49
71
}
50
72
73
+ #[ allow( unused_assignments, unused_mut) ]
74
+ let mut languages: Vec <& str > = vec![ ] ;
75
+ $( languages. extend( $languages) ; ) ?
76
+
51
77
builder. ensure( RustbookSrc {
52
78
target: self . target,
53
79
name: $book_name. to_owned( ) ,
54
- src: builder. src. join( $path ) ,
80
+ src: builder. src. join( $doc_path ) ,
55
81
parent: Some ( self ) ,
56
- languages: $lang . into ( ) ,
82
+ languages,
57
83
rustdoc_compiler: None ,
58
84
} )
59
85
}
60
86
}
61
- ) +
62
- }
87
+ } ;
63
88
}
64
89
65
90
// NOTE: When adding a book here, make sure to ALSO build the book by
66
91
// adding a build step in `src/bootstrap/code/builder/mod.rs`!
67
92
// 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" } ) ;
80
109
81
110
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
82
111
pub struct UnstableBook {
0 commit comments