Skip to content

Commit bcfb380

Browse files
authored
Rollup merge of #68075 - ollie27:rustbuild_books, r=Mark-Simulacrum
rustbuild: Cleanup book generation The Cargo book can be generated the same way as the other books.
2 parents 1af7524 + 870ca31 commit bcfb380

File tree

1 file changed

+14
-72
lines changed

1 file changed

+14
-72
lines changed

Diff for: src/bootstrap/doc.rs

+14-72
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ macro_rules! book {
4949
builder.ensure(RustbookSrc {
5050
target: self.target,
5151
name: INTERNER.intern_str($book_name),
52-
src: doc_src(builder),
52+
src: INTERNER.intern_path(builder.src.join($path)),
5353
})
5454
}
5555
}
@@ -60,6 +60,7 @@ macro_rules! book {
6060
// NOTE: When adding a book here, make sure to ALSO build the book by
6161
// adding a build step in `src/bootstrap/builder.rs`!
6262
book!(
63+
CargoBook, "src/tools/cargo/src/doc", "cargo";
6364
EditionGuide, "src/doc/edition-guide", "edition-guide";
6465
EmbeddedBook, "src/doc/embedded-book", "embedded-book";
6566
Nomicon, "src/doc/nomicon", "nomicon";
@@ -69,10 +70,6 @@ book!(
6970
RustdocBook, "src/doc/rustdoc", "rustdoc";
7071
);
7172

72-
fn doc_src(builder: &Builder<'_>) -> Interned<PathBuf> {
73-
INTERNER.intern_path(builder.src.join("src/doc"))
74-
}
75-
7673
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
7774
pub struct UnstableBook {
7875
target: Interned<String>,
@@ -96,48 +93,11 @@ impl Step for UnstableBook {
9693
builder.ensure(RustbookSrc {
9794
target: self.target,
9895
name: INTERNER.intern_str("unstable-book"),
99-
src: builder.md_doc_out(self.target),
96+
src: INTERNER.intern_path(builder.md_doc_out(self.target).join("unstable-book")),
10097
})
10198
}
10299
}
103100

104-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
105-
pub struct CargoBook {
106-
target: Interned<String>,
107-
name: Interned<String>,
108-
}
109-
110-
impl Step for CargoBook {
111-
type Output = ();
112-
const DEFAULT: bool = true;
113-
114-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
115-
let builder = run.builder;
116-
run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs)
117-
}
118-
119-
fn make_run(run: RunConfig<'_>) {
120-
run.builder.ensure(CargoBook { target: run.target, name: INTERNER.intern_str("cargo") });
121-
}
122-
123-
fn run(self, builder: &Builder<'_>) {
124-
let target = self.target;
125-
let name = self.name;
126-
let src = builder.src.join("src/tools/cargo/src/doc");
127-
128-
let out = builder.doc_out(target);
129-
t!(fs::create_dir_all(&out));
130-
131-
let out = out.join(name);
132-
133-
builder.info(&format!("Cargo Book ({}) - {}", target, name));
134-
135-
let _ = fs::remove_dir_all(&out);
136-
137-
builder.run(builder.tool_cmd(Tool::Rustbook).arg("build").arg(&src).arg("-d").arg(out));
138-
}
139-
}
140-
141101
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
142102
struct RustbookSrc {
143103
target: Interned<String>,
@@ -164,7 +124,6 @@ impl Step for RustbookSrc {
164124
t!(fs::create_dir_all(&out));
165125

166126
let out = out.join(name);
167-
let src = src.join(name);
168127
let index = out.join("index.html");
169128
let rustbook = builder.tool_exe(Tool::Rustbook);
170129
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
@@ -182,7 +141,6 @@ impl Step for RustbookSrc {
182141
pub struct TheBook {
183142
compiler: Compiler,
184143
target: Interned<String>,
185-
name: &'static str,
186144
}
187145

188146
impl Step for TheBook {
@@ -198,53 +156,37 @@ impl Step for TheBook {
198156
run.builder.ensure(TheBook {
199157
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
200158
target: run.target,
201-
name: "book",
202159
});
203160
}
204161

205162
/// Builds the book and associated stuff.
206163
///
207164
/// We need to build:
208165
///
209-
/// * Book (first edition)
210-
/// * Book (second edition)
166+
/// * Book
167+
/// * Older edition redirects
211168
/// * Version info and CSS
212169
/// * Index page
213170
/// * Redirect pages
214171
fn run(self, builder: &Builder<'_>) {
215172
let compiler = self.compiler;
216173
let target = self.target;
217-
let name = self.name;
218174

219175
// build book
220176
builder.ensure(RustbookSrc {
221177
target,
222-
name: INTERNER.intern_string(name.to_string()),
223-
src: doc_src(builder),
178+
name: INTERNER.intern_str("book"),
179+
src: INTERNER.intern_path(builder.src.join("src/doc/book")),
224180
});
225181

226182
// building older edition redirects
227-
228-
let source_name = format!("{}/first-edition", name);
229-
builder.ensure(RustbookSrc {
230-
target,
231-
name: INTERNER.intern_string(source_name),
232-
src: doc_src(builder),
233-
});
234-
235-
let source_name = format!("{}/second-edition", name);
236-
builder.ensure(RustbookSrc {
237-
target,
238-
name: INTERNER.intern_string(source_name),
239-
src: doc_src(builder),
240-
});
241-
242-
let source_name = format!("{}/2018-edition", name);
243-
builder.ensure(RustbookSrc {
244-
target,
245-
name: INTERNER.intern_string(source_name),
246-
src: doc_src(builder),
247-
});
183+
for edition in &["first-edition", "second-edition", "2018-edition"] {
184+
builder.ensure(RustbookSrc {
185+
target,
186+
name: INTERNER.intern_string(format!("book/{}", edition)),
187+
src: INTERNER.intern_path(builder.src.join("src/doc/book").join(edition)),
188+
});
189+
}
248190

249191
// build the version info page and CSS
250192
builder.ensure(Standalone { compiler, target });

0 commit comments

Comments
 (0)