Skip to content

Commit afe29e4

Browse files
committed
split steps for generating the standalone docs and the shared assets
Before this commit, the step to generate the standalone docs (which included the index page and other HTML files at the root of the documentation) was bundled with the code copying files needed by multiple pieces of documentation. This means it wasn't possible to avoid generating the standalone docs. This commit splits the step into two, allowing the standalone docs generation to be excluded while still building the rest of the docs.
1 parent dd8c3a8 commit afe29e4

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

src/bootstrap/doc.rs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl Step for TheBook {
227227
}
228228

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

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

239-
invoke_rustdoc(builder, compiler, target, path);
239+
invoke_rustdoc(builder, compiler, &shared_assets, target, path);
240240
}
241241

242242
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
@@ -250,6 +250,7 @@ impl Step for TheBook {
250250
fn invoke_rustdoc(
251251
builder: &Builder<'_>,
252252
compiler: Compiler,
253+
shared_assets: &SharedAssetsPaths,
253254
target: TargetSelection,
254255
markdown: &str,
255256
) {
@@ -259,7 +260,6 @@ fn invoke_rustdoc(
259260

260261
let header = builder.src.join("src/doc/redirect.inc");
261262
let footer = builder.src.join("src/doc/footer.inc");
262-
let version_info = out.join("version_info.html");
263263

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

@@ -268,7 +268,7 @@ fn invoke_rustdoc(
268268
cmd.arg("--html-after-content")
269269
.arg(&footer)
270270
.arg("--html-before-content")
271-
.arg(&version_info)
271+
.arg(&shared_assets.version_info)
272272
.arg("--html-in-header")
273273
.arg(&header)
274274
.arg("--markdown-no-toc")
@@ -324,21 +324,11 @@ impl Step for Standalone {
324324
let out = builder.doc_out(target);
325325
t!(fs::create_dir_all(&out));
326326

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

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

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

0 commit comments

Comments
 (0)