Skip to content

Commit d3e9191

Browse files
authored
Rollup merge of rust-lang#104286 - ozkanonur:fix-doc-bootstrap-recompilation, r=jyn514
copy doc output files by format This pr provides copying doc outputs by checking output format without removing output directory on each trigger. Resolves rust-lang#103785
2 parents bd91c94 + 7e28df9 commit d3e9191

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

src/bootstrap/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,13 @@ impl<'a> Builder<'a> {
10941094
let my_out = match mode {
10951095
// This is the intended out directory for compiler documentation.
10961096
Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target),
1097-
Mode::Std => out_dir.join(target.triple).join("doc"),
1097+
Mode::Std => {
1098+
if self.config.cmd.json() {
1099+
out_dir.join(target.triple).join("json-doc")
1100+
} else {
1101+
out_dir.join(target.triple).join("doc")
1102+
}
1103+
}
10981104
_ => panic!("doc mode {:?} not expected", mode),
10991105
};
11001106
let rustdoc = self.rustdoc(compiler);

src/bootstrap/doc.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -564,27 +564,22 @@ fn doc_std(
564564
);
565565
}
566566
let compiler = builder.compiler(stage, builder.config.build);
567+
568+
let target_doc_dir_name = if format == DocumentationFormat::JSON { "json-doc" } else { "doc" };
569+
let target_dir =
570+
builder.stage_out(compiler, Mode::Std).join(target.triple).join(target_doc_dir_name);
571+
567572
// This is directory where the compiler will place the output of the command.
568573
// We will then copy the files from this directory into the final `out` directory, the specified
569574
// as a function parameter.
570-
let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc");
571-
// `cargo` uses the same directory for both JSON docs and HTML docs.
572-
// This could lead to cross-contamination when copying files into the specified `out` directory.
573-
// For example:
574-
// ```bash
575-
// x doc std
576-
// x doc std --json
577-
// ```
578-
// could lead to HTML docs being copied into the JSON docs output directory.
579-
// To avoid this issue, we clean the doc folder before invoking `cargo`.
580-
if out_dir.exists() {
581-
builder.remove_dir(&out_dir);
582-
}
575+
let out_dir = target_dir.join(target.triple).join("doc");
583576

584577
let run_cargo_rustdoc_for = |package: &str| {
585578
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc");
586579
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
587580
cargo
581+
.arg("--target-dir")
582+
.arg(&*target_dir.to_string_lossy())
588583
.arg("-p")
589584
.arg(package)
590585
.arg("-Zskip-rustdoc-fingerprint")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
4+
TMP_OUTPUT_DIR := "$(TMPDIR)/tmp-rustdoc"
5+
6+
all:
7+
# Generate html docs
8+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --out-dir $(OUTPUT_DIR)
9+
10+
# Copy first output for to check if it's exactly same after second compilation
11+
cp -R $(OUTPUT_DIR) $(TMP_OUTPUT_DIR)
12+
13+
# Generate html docs once again on same output
14+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --out-dir $(OUTPUT_DIR)
15+
16+
# Check if everything exactly same
17+
$(DIFF) -r -q $(OUTPUT_DIR) $(TMP_OUTPUT_DIR)
18+
19+
# Generate json doc on the same output
20+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --out-dir $(OUTPUT_DIR) -Z unstable-options --output-format json
21+
22+
# Check if expected json file is generated
23+
[ -e $(OUTPUT_DIR)/foobar.json ]
24+
25+
# TODO
26+
# We should re-generate json doc once again and compare the diff with previously
27+
# generated one. Because layout of json docs changes in each compilation, we can't
28+
# do that currently.
29+
#
30+
# See https://github.com/rust-lang/rust/issues/103785#issuecomment-1307425590 for details.
31+
32+
# remove generated json doc
33+
rm $(OUTPUT_DIR)/foobar.json
34+
35+
# Check if json doc compilation broke any of the html files generated previously
36+
$(DIFF) -r -q $(OUTPUT_DIR) $(TMP_OUTPUT_DIR)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing to see here

0 commit comments

Comments
 (0)