Skip to content

Commit 03be3e2

Browse files
committed
Add --out-dir flag for rustdoc
Signed-off-by: hi-rustin <[email protected]>
1 parent 4919988 commit 03be3e2

File tree

11 files changed

+57
-5
lines changed

11 files changed

+57
-5
lines changed

src/doc/rustdoc/src/command-line-arguments.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ release: 1.17.0
5757
LLVM version: 3.9
5858
```
5959

60-
## `-o`/`--output`: output path
60+
## `-o`/`--out-dir`: output directory path
6161

6262
Using this flag looks like this:
6363

6464
```bash
6565
$ rustdoc src/lib.rs -o target/doc
66-
$ rustdoc src/lib.rs --output target/doc
66+
$ rustdoc src/lib.rs --out-dir target/doc
6767
```
6868

6969
By default, `rustdoc`'s output appears in a directory named `doc` in

src/librustdoc/config.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,18 @@ impl Options {
504504
return Err(1);
505505
}
506506

507-
let output =
508-
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
507+
let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
508+
let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
509+
let output = match (out_dir, output) {
510+
(Some(_), Some(_)) => {
511+
diag.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
512+
return Err(1);
513+
}
514+
(Some(out_dir), None) => out_dir,
515+
(None, Some(output)) => output,
516+
(None, None) => PathBuf::from("doc"),
517+
};
518+
509519
let cfgs = matches.opt_strs("cfg");
510520

511521
let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));

src/librustdoc/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,16 @@ fn opts() -> Vec<RustcOptGroup> {
278278
o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
279279
}),
280280
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
281-
stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
281+
stable("output", |o| {
282+
o.optopt(
283+
"",
284+
"output",
285+
"Which directory to place the output. \
286+
This option is deprecated, use --out-dir instead.",
287+
"PATH",
288+
)
289+
}),
290+
stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")),
282291
stable("crate-name", |o| {
283292
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
284293
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
4+
5+
all:
6+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --out-dir $(OUTPUT_DIR)
7+
8+
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @has foobar/fn.ok.html
2+
pub fn ok() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
4+
5+
all:
6+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR)
7+
8+
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @has foobar/fn.ok.html
2+
pub fn ok() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
4+
5+
all:
6+
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib -o $(OUTPUT_DIR)
7+
8+
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @has foobar/fn.ok.html
2+
pub fn ok() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// compile-flags: --output ./foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: cannot use both 'out-dir' and 'output' at once
2+

0 commit comments

Comments
 (0)