Skip to content

Commit b03fa1a

Browse files
authored
Rollup merge of rust-lang#102706 - ferrocene:pa-ignore-doc-index, r=jyn514
Support excluding the generation of the standalone docs For Ferrocene we need to exclude the generation of the standalone docs (which include the index page, which we want to replace with our own), but with the way bootstrap is currently implemented that proved not possible. This PR aims to support that. The first problem is that the `doc::Standalone` step did two things: it generated the "standalone" documentation (which includes the index page and all the pages at the root of the documentation tree), but it also generated some files like `rust.css` and `version_info.html` that other step like `doc::TheBook` required. This meant generating the book required generating the index page, which made disabling the index page generation problematic. The approach I took to fix the first problem is to split the step into `doc::Standalone` and `doc::SharedAssets`, with `doc::TheBook` now depending on `doc::SharedAssets`. The second problem is that disabling the `doc::Standalone` proved to be tricky due to its path, `src/doc`. The path is accurate, as the source files for that step are `src/doc/*.md`. The problem is, bootstrap treats `--exclude` as a *suffix*, and so it also excluded the Cargo book whose source lives at `src/tools/cargo/src/doc`. The approach I took to fix the second problem is to add the `standalone` path in addition to `src/doc`, so that you can pass `--exclude standalone`. I'm not fully happy with the solution, and the other idea I had was to just move the standalone docs source code to `src/doc/standalone`. I feel that second approach is cleaner, but also requires more changes and might require more consensus. This PR is best reviewed commit-by-commit. r? `@jyn514`
2 parents 5b64553 + 91c09d4 commit b03fa1a

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

src/bootstrap/doc.rs

+48-18
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Step for TheBook {
228228
}
229229

230230
// build the version info page and CSS
231-
builder.ensure(Standalone { compiler, target });
231+
let shared_assets = builder.ensure(SharedAssets { target });
232232

233233
// build the redirect pages
234234
builder.info(&format!("Documenting book redirect pages ({})", target));
@@ -237,7 +237,7 @@ impl Step for TheBook {
237237
let path = file.path();
238238
let path = path.to_str().unwrap();
239239

240-
invoke_rustdoc(builder, compiler, target, path);
240+
invoke_rustdoc(builder, compiler, &shared_assets, target, path);
241241
}
242242

243243
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
@@ -251,6 +251,7 @@ impl Step for TheBook {
251251
fn invoke_rustdoc(
252252
builder: &Builder<'_>,
253253
compiler: Compiler,
254+
shared_assets: &SharedAssetsPaths,
254255
target: TargetSelection,
255256
markdown: &str,
256257
) {
@@ -260,7 +261,6 @@ fn invoke_rustdoc(
260261

261262
let header = builder.src.join("src/doc/redirect.inc");
262263
let footer = builder.src.join("src/doc/footer.inc");
263-
let version_info = out.join("version_info.html");
264264

265265
let mut cmd = builder.rustdoc_cmd(compiler);
266266

@@ -269,7 +269,7 @@ fn invoke_rustdoc(
269269
cmd.arg("--html-after-content")
270270
.arg(&footer)
271271
.arg("--html-before-content")
272-
.arg(&version_info)
272+
.arg(&shared_assets.version_info)
273273
.arg("--html-in-header")
274274
.arg(&header)
275275
.arg("--markdown-no-toc")
@@ -300,7 +300,7 @@ impl Step for Standalone {
300300

301301
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
302302
let builder = run.builder;
303-
run.path("src/doc").default_condition(builder.config.docs)
303+
run.path("src/doc").alias("standalone").default_condition(builder.config.docs)
304304
}
305305

306306
fn make_run(run: RunConfig<'_>) {
@@ -325,21 +325,11 @@ impl Step for Standalone {
325325
let out = builder.doc_out(target);
326326
t!(fs::create_dir_all(&out));
327327

328+
let version_info = builder.ensure(SharedAssets { target: self.target }).version_info;
329+
328330
let favicon = builder.src.join("src/doc/favicon.inc");
329331
let footer = builder.src.join("src/doc/footer.inc");
330332
let full_toc = builder.src.join("src/doc/full-toc.inc");
331-
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
332-
333-
let version_input = builder.src.join("src/doc/version_info.html.template");
334-
let version_info = out.join("version_info.html");
335-
336-
if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
337-
let info = t!(fs::read_to_string(&version_input))
338-
.replace("VERSION", &builder.rust_release())
339-
.replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
340-
.replace("STAMP", builder.rust_info.sha().unwrap_or(""));
341-
t!(fs::write(&version_info, &info));
342-
}
343333

344334
for file in t!(fs::read_dir(builder.src.join("src/doc"))) {
345335
let file = t!(file);
@@ -401,6 +391,45 @@ impl Step for Standalone {
401391
}
402392
}
403393

394+
#[derive(Debug, Clone)]
395+
pub struct SharedAssetsPaths {
396+
pub version_info: PathBuf,
397+
}
398+
399+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
400+
pub struct SharedAssets {
401+
target: TargetSelection,
402+
}
403+
404+
impl Step for SharedAssets {
405+
type Output = SharedAssetsPaths;
406+
const DEFAULT: bool = false;
407+
408+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
409+
// Other tasks depend on this, no need to execute it on its own
410+
run.never()
411+
}
412+
413+
// Generate shared resources used by other pieces of documentation.
414+
fn run(self, builder: &Builder<'_>) -> Self::Output {
415+
let out = builder.doc_out(self.target);
416+
417+
let version_input = builder.src.join("src").join("doc").join("version_info.html.template");
418+
let version_info = out.join("version_info.html");
419+
if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
420+
let info = t!(fs::read_to_string(&version_input))
421+
.replace("VERSION", &builder.rust_release())
422+
.replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
423+
.replace("STAMP", builder.rust_info.sha().unwrap_or(""));
424+
t!(fs::write(&version_info, &info));
425+
}
426+
427+
builder.copy(&builder.src.join("src").join("doc").join("rust.css"), &out.join("rust.css"));
428+
429+
SharedAssetsPaths { version_info }
430+
}
431+
}
432+
404433
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
405434
pub struct Std {
406435
pub stage: u32,
@@ -429,7 +458,8 @@ impl Step for Std {
429458
let target = self.target;
430459
let out = builder.doc_out(target);
431460
t!(fs::create_dir_all(&out));
432-
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
461+
462+
builder.ensure(SharedAssets { target: self.target });
433463

434464
let index_page = builder.src.join("src/doc/index.md").into_os_string();
435465
let mut extra_args = vec![

0 commit comments

Comments
 (0)