Skip to content

Commit a97a4d9

Browse files
Rollup merge of #159415 - notriddle:rename-parts-to-dep-meta, r=GuillaumeGomez
rustdoc: rename the doc parts metadata params Written in response to #152902 (comment)
2 parents 238ef89 + 50fd1f1 commit a97a4d9

50 files changed

Lines changed: 179 additions & 223 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/doc/rustdoc/src/unstable-features.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,26 @@ themselves marked as unstable. To use any of these options, pass `-Z unstable-op
197197
the flag in question to Rustdoc on the command-line. To do this from Cargo, you can either use the
198198
`RUSTDOCFLAGS` environment variable or the `cargo rustdoc` command.
199199

200-
### `--merge`, `--parts-out-dir`, and `--include-parts-dir`
200+
### `--write-doc-meta-dir`, and `--read-doc-meta-dir`
201201

202202
These options control how rustdoc handles files that combine data from multiple crates.
203203

204-
By default, they act like `--merge=shared` is set, and `--parts-out-dir` and `--include-parts-dir`
205-
are turned off. The `--merge=shared` mode causes rustdoc to load the existing data in the out-dir,
206-
combine the new crate data into it, and write the result. This is very easy to use in scripts that
207-
manually invoke rustdoc, but it's also slow, because it performs O(crates) work on
208-
every crate, meaning it performs O(crates<sup>2</sup>) work.
204+
By default, rustdoc will read the doc meta from the doc output dir itself and merge them together.
205+
This is very easy to use in scripts that manually invoke rustdoc, but it's also slow, because it
206+
performs O(crates) work on every crate, meaning it performs O(crates<sup>2</sup>) work. When
207+
`--write-doc-meta-dir` and/or `--read-doc-meta-dir` are supplied, this is turned off.
208+
209+
When `--write-doc-meta-dir` is supplied, rustdoc will write the crate's metadata to that directory.
210+
If this parameter is supplied but `--read-doc-meta-dir` isn't, it runs in *intermediate mode*:
211+
some pages may be written to the output dir, but there is a lot of functionality that won't work
212+
until rustdoc is run in *finalize mode*.
213+
214+
When `--read-doc-meta-dir` is supplied, rustdoc runs in *finalize mode*. It will read the data from
215+
the supplied directory, and will write it to the doc output directory in the form that the web
216+
frontend will use.
217+
218+
If both `--write-doc-meta-dir` and `--read-doc-meta-dir` are specified, the crate metadata will be
219+
written to both the HTML `--out-dir` and to the supplied `--write-doc-meta-dir`.
209220

210221
```console
211222
$ rustdoc crate1.rs --out-dir=doc
@@ -217,13 +228,13 @@ rd_("fcrate1fcrate2")
217228
```
218229

219230
To delay shared-data merging until the end of a build, so that you only have to perform O(crates)
220-
work, use `--merge=none` on every crate except the last one, which will use `--merge=finalize`.
231+
work, use `--write-doc-meta-dir` on every crate, and the last will use `--read-doc-meta-dir`.
221232

222233
```console
223-
$ rustdoc +nightly crate1.rs --merge=none --parts-out-dir=crate1.d -Zunstable-options
234+
$ rustdoc +nightly crate1.rs --write-doc-meta=crate1.d -Zunstable-options
224235
$ cat doc/search.index/crateNames/*
225236
cat: 'doc/search.index/crateNames/*': No such file or directory
226-
$ rustdoc +nightly crate2.rs --merge=finalize --include-parts-dir=crate1.d -Zunstable-options
237+
$ rustdoc +nightly crate2.rs --read-doc-meta=crate1.d -Zunstable-options
227238
$ cat doc/search.index/crateNames/*
228239
rd_("fcrate1fcrate2")
229240
```

src/librustdoc/config.rs

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -598,34 +598,66 @@ impl Options {
598598

599599
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(early_dcx, matches);
600600

601-
let input = if describe_lints {
602-
InputMode::HasFile(make_input(early_dcx, ""))
603-
} else {
604-
match matches.free.as_slice() {
605-
[] if matches.opt_str("merge").as_deref() == Some("finalize") => {
606-
InputMode::NoInputMergeFinalize
607-
}
608-
[] => dcx.fatal("missing file operand"),
609-
[input] => InputMode::HasFile(make_input(early_dcx, input)),
610-
_ => dcx.fatal("too many file operands"),
611-
}
612-
};
613-
614601
let externs = parse_externs(early_dcx, matches, &unstable_opts);
615602
let extern_html_root_urls = match parse_extern_html_roots(matches) {
616603
Ok(ex) => ex,
617604
Err(err) => dcx.fatal(err),
618605
};
619606

620-
let parts_out_dir =
621-
match matches.opt_str("parts-out-dir").map(PathToParts::from_flag).transpose() {
607+
let mut parts_out_dir =
608+
match matches.opt_str("write-doc-meta-dir").map(PathToParts::from_flag).transpose() {
622609
Ok(parts_out_dir) => parts_out_dir,
623610
Err(e) => dcx.fatal(e),
624611
};
625-
let include_parts_dir = match parse_include_parts_dir(matches) {
612+
let mut include_parts_dir = match parse_read_doc_meta(matches, "read-doc-meta-dir") {
626613
Ok(include_parts_dir) => include_parts_dir,
627614
Err(e) => dcx.fatal(e),
628615
};
616+
let mut should_merge = compute_should_merge(matches);
617+
if parts_out_dir.is_none() && include_parts_dir.is_empty() {
618+
// we'll need to get rid of this stuff once Cargo stops using them
619+
parts_out_dir =
620+
match matches.opt_str("parts-out-dir").map(PathToParts::from_flag).transpose() {
621+
Ok(parts_out_dir) => parts_out_dir,
622+
Err(e) => dcx.fatal(e),
623+
};
624+
include_parts_dir = match parse_read_doc_meta(matches, "include-parts-dir") {
625+
Ok(include_parts_dir) => include_parts_dir,
626+
Err(e) => dcx.fatal(e),
627+
};
628+
should_merge = match matches.opt_str("merge").as_deref() {
629+
None => ShouldMerge { read_rendered_cci: true, write_rendered_cci: true },
630+
Some("none") => ShouldMerge { read_rendered_cci: false, write_rendered_cci: false },
631+
Some("shared") => ShouldMerge { read_rendered_cci: true, write_rendered_cci: true },
632+
Some("finalize") => {
633+
ShouldMerge { read_rendered_cci: false, write_rendered_cci: true }
634+
}
635+
Some(_) => dcx.fatal("argument to --merge must be `none`, `shared`, or `finalize`"),
636+
};
637+
} else if matches.opt_str("parts-out-dir").is_some() {
638+
dcx.fatal(
639+
"deprecated version of write-doc-meta-dir is used with new doc-meta-dir stuff",
640+
);
641+
} else if matches.opt_str("include-parts-dir").is_some() {
642+
dcx.fatal(
643+
"deprecated version of read-doc-meta-dir is used with new doc-meta-dir stuff",
644+
);
645+
} else if matches.opt_str("merge").is_some() {
646+
dcx.fatal("deprecated parameter merge is used with new doc-meta-dir stuff");
647+
}
648+
649+
let input = if describe_lints {
650+
InputMode::HasFile(make_input(early_dcx, ""))
651+
} else {
652+
match matches.free.as_slice() {
653+
[] if !include_parts_dir.is_empty() && should_merge.write_rendered_cci => {
654+
InputMode::NoInputMergeFinalize
655+
}
656+
[] => dcx.fatal("missing file operand"),
657+
[input] => InputMode::HasFile(make_input(early_dcx, input)),
658+
_ => dcx.fatal("too many file operands"),
659+
}
660+
};
629661

630662
let default_settings: Vec<Vec<(String, String)>> = vec![
631663
matches
@@ -850,10 +882,6 @@ impl Options {
850882
let extern_html_root_takes_precedence =
851883
matches.opt_present("extern-html-root-takes-precedence");
852884
let html_no_source = matches.opt_present("html-no-source");
853-
let should_merge = match parse_merge(matches) {
854-
Ok(result) => result,
855-
Err(e) => dcx.fatal(format!("--merge option error: {e}")),
856-
};
857885
let merge_doctests = parse_merge_doctests(matches, edition, dcx);
858886
tracing::debug!("merge_doctests: {merge_doctests:?}");
859887

@@ -1048,7 +1076,7 @@ impl PathToParts {
10481076
// check here is for diagnostics
10491077
if path.exists() && !path.is_dir() {
10501078
Err(format!(
1051-
"--parts-out-dir and --include-parts-dir expect directories, found: {}",
1079+
"--write-doc-meta-dir and --read-doc-meta-dir expect directories, found: {}",
10521080
path.display(),
10531081
))
10541082
} else {
@@ -1058,15 +1086,15 @@ impl PathToParts {
10581086
}
10591087
}
10601088

1061-
/// Reports error if --include-parts-dir is not a directory
1062-
fn parse_include_parts_dir(m: &getopts::Matches) -> Result<Vec<PathToParts>, String> {
1089+
/// Reports error if --read-doc-meta-dir is not a directory
1090+
fn parse_read_doc_meta(m: &getopts::Matches, name: &str) -> Result<Vec<PathToParts>, String> {
10631091
let mut ret = Vec::new();
1064-
for p in m.opt_strs("include-parts-dir") {
1092+
for p in m.opt_strs(name) {
10651093
let p = PathToParts::from_flag(p)?;
10661094
// this is just for diagnostic
10671095
if !p.0.is_dir() {
10681096
return Err(format!(
1069-
"--include-parts-dir expected {} to be a directory",
1097+
"--read-doc-meta-dir expected {} to be a directory",
10701098
p.0.display()
10711099
));
10721100
}
@@ -1086,23 +1114,15 @@ pub(crate) struct ShouldMerge {
10861114

10871115
/// Extracts read_rendered_cci and write_rendered_cci from command line arguments, or
10881116
/// reports an error if an invalid option was provided
1089-
fn parse_merge(m: &getopts::Matches) -> Result<ShouldMerge, &'static str> {
1090-
match m.opt_str("merge").as_deref() {
1091-
// default = read-write
1092-
None => Ok(ShouldMerge { read_rendered_cci: true, write_rendered_cci: true }),
1093-
Some("none") if m.opt_present("include-parts-dir") => {
1094-
Err("--include-parts-dir not allowed if --merge=none")
1095-
}
1096-
Some("none") => Ok(ShouldMerge { read_rendered_cci: false, write_rendered_cci: false }),
1097-
Some("shared") if m.opt_present("parts-out-dir") || m.opt_present("include-parts-dir") => {
1098-
Err("--parts-out-dir and --include-parts-dir not allowed if --merge=shared")
1099-
}
1100-
Some("shared") => Ok(ShouldMerge { read_rendered_cci: true, write_rendered_cci: true }),
1101-
Some("finalize") if m.opt_present("parts-out-dir") => {
1102-
Err("--parts-out-dir not allowed if --merge=finalize")
1103-
}
1104-
Some("finalize") => Ok(ShouldMerge { read_rendered_cci: false, write_rendered_cci: true }),
1105-
Some(_) => Err("argument to --merge must be `none`, `shared`, or `finalize`"),
1117+
fn compute_should_merge(m: &getopts::Matches) -> ShouldMerge {
1118+
match (m.opt_present("read-doc-meta-dir"), m.opt_present("write-doc-meta-dir")) {
1119+
// shared mode
1120+
(false, false) => ShouldMerge { read_rendered_cci: true, write_rendered_cci: true },
1121+
// intermediate mode
1122+
(false, true) => ShouldMerge { read_rendered_cci: false, write_rendered_cci: false },
1123+
// finalize mode
1124+
(true, false) => ShouldMerge { read_rendered_cci: false, write_rendered_cci: true },
1125+
(true, true) => ShouldMerge { read_rendered_cci: false, write_rendered_cci: true },
11061126
}
11071127
}
11081128

src/librustdoc/lib.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,28 +613,41 @@ fn opts() -> Vec<RustcOptGroup> {
613613
Unstable,
614614
Opt,
615615
"",
616-
"merge",
617-
"Controls how rustdoc handles files from previously documented crates in the doc root\n\
618-
none = Do not write cross-crate information to the --out-dir\n\
619-
shared = Append current crate's info to files found in the --out-dir\n\
620-
finalize = Write current crate's info and --include-parts-dir info to the --out-dir, overwriting conflicting files",
621-
"none|shared|finalize",
616+
"write-doc-meta-dir",
617+
"Writes trait implementations and other info for the current crate to provided path",
618+
"path/to/doc.meta",
619+
),
620+
opt(
621+
Unstable,
622+
Multi,
623+
"",
624+
"read-doc-meta-dir",
625+
"Includes trait implementations and other crate info from provided path",
626+
"path/to/doc.meta",
622627
),
623628
opt(
624629
Unstable,
625630
Opt,
626631
"",
627632
"parts-out-dir",
628-
"Writes trait implementations and other info for the current crate to provided path. Only use with --merge=none",
629-
"path/to/doc.parts/<crate-name>",
633+
"Deprecated synonym of write-doc-meta-dir",
634+
"path/to/doc.meta",
630635
),
631636
opt(
632637
Unstable,
633638
Multi,
634639
"",
635640
"include-parts-dir",
636-
"Includes trait implementations and other crate info from provided path. Only use with --merge=finalize",
637-
"path/to/doc.parts/<crate-name>",
641+
"Deprecated synonym of read-doc-meta-dir",
642+
"path/to/doc.meta",
643+
),
644+
opt(
645+
Unstable,
646+
Opt,
647+
"",
648+
"merge",
649+
"Deprecated option to specify read/write-doc-meta-dir mode",
650+
"none, shared, finalize",
638651
),
639652
opt(Unstable, Flag, "", "html-no-source", "Disable HTML source code pages generation", ""),
640653
opt(
@@ -758,7 +771,7 @@ fn run_renderer<
758771

759772
/// Renders and writes cross-crate info files, like the search index. This function exists so that
760773
/// we can run rustdoc without a crate root in the `--merge=finalize` mode. Cross-crate info files
761-
/// discovered via `--include-parts-dir` are combined and written to the doc root.
774+
/// discovered via `--read-doc-meta-dir` are combined and written to the doc root.
762775
fn run_merge_finalize(opt: config::RenderOptions) -> Result<(), error::Error> {
763776
assert!(
764777
opt.should_merge.write_rendered_cci,

tests/run-make/rustdoc-default-output/output-default.stdout

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,19 @@ Options:
176176
--scrape-tests Include test code when scraping examples
177177
--with-examples path to function call information (for displaying examples in the documentation)
178178

179-
--merge none|shared|finalize
180-
Controls how rustdoc handles files from previously
181-
documented crates in the doc root
182-
none = Do not write cross-crate information to the
183-
--out-dir
184-
shared = Append current crate's info to files found in
185-
the --out-dir
186-
finalize = Write current crate's info and
187-
--include-parts-dir info to the --out-dir, overwriting
188-
conflicting files
189-
--parts-out-dir path/to/doc.parts/<crate-name>
179+
--write-doc-meta-dir path/to/doc.meta
190180
Writes trait implementations and other info for the
191-
current crate to provided path. Only use with
192-
--merge=none
193-
--include-parts-dir path/to/doc.parts/<crate-name>
181+
current crate to provided path
182+
--read-doc-meta-dir path/to/doc.meta
194183
Includes trait implementations and other crate info
195-
from provided path. Only use with --merge=finalize
184+
from provided path
185+
--parts-out-dir path/to/doc.meta
186+
Deprecated synonym of write-doc-meta-dir
187+
--include-parts-dir path/to/doc.meta
188+
Deprecated synonym of read-doc-meta-dir
189+
--merge none, shared, finalize
190+
Deprecated option to specify read/write-doc-meta-dir
191+
mode
196192
--html-no-source
197193
Disable HTML source code pages generation
198194
--doctest-build-arg ARG

tests/run-make/rustdoc-merge-directory-alias/rmake.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Running --merge=finalize without an input crate root should not trigger ICE.
1+
// Running --read-doc-meta-dir without an input crate root should not trigger ICE.
22
// Issue: https://github.com/rust-lang/rust/issues/146646
33

44
//@ needs-target-std
@@ -14,71 +14,63 @@ fn main() {
1414
.input("dep1.rs")
1515
.out_dir(&out_dir)
1616
.arg("-Zunstable-options")
17-
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
18-
.arg("--merge=none")
17+
.arg(format!("--write-doc-meta-dir={}", parts_out_dir.display()))
1918
.run();
2019
assert!(parts_out_dir.join("dep1.json").exists());
2120

2221
let output = rustdoc()
2322
.arg("-Zunstable-options")
2423
.out_dir(&out_dir)
25-
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
26-
.arg("--merge=finalize")
24+
.arg(format!("--read-doc-meta-dir={}", parts_out_dir.display()))
2725
.run();
2826
output.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
2927

3028
rustdoc()
3129
.input("dep2.rs")
3230
.out_dir(&out_dir)
3331
.arg("-Zunstable-options")
34-
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
35-
.arg("--merge=none")
32+
.arg(format!("--write-doc-meta-dir={}", parts_out_dir.display()))
3633
.run();
3734
assert!(parts_out_dir.join("dep2.json").exists());
3835

3936
let output2 = rustdoc()
4037
.arg("-Zunstable-options")
4138
.out_dir(&out_dir)
42-
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
43-
.arg("--merge=finalize")
39+
.arg(format!("--read-doc-meta-dir={}", parts_out_dir.display()))
4440
.run();
4541
output2.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
4642

4743
rustdoc()
4844
.input("dep1.rs")
4945
.out_dir(&out_dir)
5046
.arg("-Zunstable-options")
51-
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
52-
.arg("--merge=none")
47+
.arg(format!("--write-doc-meta-dir={}", parts_out_dir.display()))
5348
.run();
5449
assert!(parts_out_dir.join("dep1.json").exists());
5550

5651
let output3 = rustdoc()
5752
.arg("-Zunstable-options")
5853
.out_dir(&out_dir)
59-
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
60-
.arg("--merge=finalize")
54+
.arg(format!("--read-doc-meta-dir={}", parts_out_dir.display()))
6155
.run();
6256
output3.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
6357

64-
// dep_missing is different, because --parts-out-dir is not supplied
58+
// dep_missing is different, because --write-doc-meta-dir is not supplied
6559
rustdoc().input("dep_missing.rs").out_dir(&out_dir).run();
6660
assert!(parts_out_dir.join("dep2.json").exists());
6761

6862
rustdoc()
6963
.input("dep1.rs")
7064
.out_dir(&out_dir)
7165
.arg("-Zunstable-options")
72-
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
73-
.arg("--merge=none")
66+
.arg(format!("--write-doc-meta-dir={}", parts_out_dir.display()))
7467
.run();
7568
assert!(parts_out_dir.join("dep1.json").exists());
7669

7770
let output4 = rustdoc()
7871
.arg("-Zunstable-options")
7972
.out_dir(&out_dir)
80-
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
81-
.arg("--merge=finalize")
73+
.arg(format!("--read-doc-meta-dir={}", parts_out_dir.display()))
8274
.run();
8375
output4.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
8476

0 commit comments

Comments
 (0)