Skip to content
/ rust Public
forked from rust-lang/rust

Commit beb0886

Browse files
authored
Rollup merge of rust-lang#159765 - Kobzol:bootstrap-docs-json-rebuild, r=Mark-Simulacrum
Avoid spurious rebuilds of JSON docs in bootstrap Found this while working on rust-lang#159671. Before, repeated runs of e.g. `x dist rust-docs-json` always rebuilt the docs. It was caused by Cargo not knowing that the output should be JSON, so it was trying to find the HTML files. Instead of passing the output format through `RUSTDOCFLAGS`, which Cargo doesn't inspect, we now pass it to Cargo directly, which fixes the issue.
2 parents 76c35a1 + 220fbca commit beb0886

1 file changed

Lines changed: 46 additions & 21 deletions

File tree

  • src/bootstrap/src/core/build_steps

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl Step for Std {
721721
DocumentationFormat::Html => {
722722
vec!["--markdown-css", "rust.css", "--markdown-no-toc", "--index-page", &index_page]
723723
}
724-
DocumentationFormat::Json => vec!["--output-format", "json"],
724+
DocumentationFormat::Json => vec![],
725725
};
726726

727727
if !builder.config.docs_minification {
@@ -730,7 +730,47 @@ impl Step for Std {
730730
// For `--index-page` and `--output-format=json`.
731731
extra_args.push("-Zunstable-options");
732732

733-
doc_std(builder, self.format, self.build_compiler, target, &out, &extra_args, &crates);
733+
let target_doc_dir_name =
734+
if self.format == DocumentationFormat::Json { "json-doc" } else { "doc" };
735+
let target_dir = builder
736+
.stage_out(self.build_compiler, Mode::Std)
737+
.join(target)
738+
.join(target_doc_dir_name);
739+
740+
// This is directory where the compiler will place the output of the command.
741+
// We will then copy the files from this directory into the final `out` directory, the specified
742+
// as a function parameter.
743+
let out_dir = target_dir.join(target).join("doc");
744+
745+
let mut cargo = doc_std(
746+
builder,
747+
self.format,
748+
self.build_compiler,
749+
target,
750+
&target_dir,
751+
&extra_args,
752+
&crates,
753+
);
754+
match self.format {
755+
DocumentationFormat::Html => {}
756+
DocumentationFormat::Json => {
757+
// We have to pass these directly to cargo, rather than through RUSTDOCFLAGS,
758+
// otherwise Cargo will not detect freshness of the output correctly, and keep
759+
// rebuilding the docs on every invocation.
760+
cargo.args(["-Zunstable-options", "--output-format", "json"]);
761+
}
762+
}
763+
764+
let description =
765+
format!("library{} in {} format", crate_description(&crates), self.format.as_str());
766+
767+
{
768+
let _guard =
769+
builder.msg(Kind::Doc, description, Mode::Std, self.build_compiler, target);
770+
771+
cargo.into_cmd().run(builder);
772+
builder.cp_link_r(&out_dir, &out);
773+
}
734774

735775
// Open if the format is HTML
736776
if let DocumentationFormat::Html = self.format {
@@ -787,25 +827,16 @@ impl DocumentationFormat {
787827
}
788828
}
789829

790-
/// Build the documentation for public standard library crates.
830+
/// Prepare a Cargo command for building the documentation for public standard library crates.
791831
fn doc_std(
792832
builder: &Builder<'_>,
793833
format: DocumentationFormat,
794834
build_compiler: Compiler,
795835
target: TargetSelection,
796-
out: &Path,
836+
target_dir: &Path,
797837
extra_args: &[&str],
798838
requested_crates: &[String],
799-
) {
800-
let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" };
801-
let target_dir =
802-
builder.stage_out(build_compiler, Mode::Std).join(target).join(target_doc_dir_name);
803-
804-
// This is directory where the compiler will place the output of the command.
805-
// We will then copy the files from this directory into the final `out` directory, the specified
806-
// as a function parameter.
807-
let out_dir = target_dir.join(target).join("doc");
808-
839+
) -> builder::Cargo {
809840
let mut cargo = builder::Cargo::new(
810841
builder,
811842
build_compiler,
@@ -836,13 +867,7 @@ fn doc_std(
836867
if format == DocumentationFormat::Json || builder.config.library_docs_private_items {
837868
cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
838869
}
839-
840-
let description =
841-
format!("library{} in {} format", crate_description(requested_crates), format.as_str());
842-
let _guard = builder.msg(Kind::Doc, description, Mode::Std, build_compiler, target);
843-
844-
cargo.into_cmd().run(builder);
845-
builder.cp_link_r(&out_dir, out);
870+
cargo
846871
}
847872

848873
/// Prepare a compiler that will be able to document something for `target` at `stage`.

0 commit comments

Comments
 (0)