Add --out-dir flag for rustdoc

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
This commit is contained in:
hi-rustin 2021-11-28 15:12:56 +08:00
parent 4919988fe1
commit 03be3e21b1
11 changed files with 57 additions and 5 deletions

View file

@ -57,13 +57,13 @@ release: 1.17.0
LLVM version: 3.9
```
## `-o`/`--output`: output path
## `-o`/`--out-dir`: output directory path
Using this flag looks like this:
```bash
$ rustdoc src/lib.rs -o target/doc
$ rustdoc src/lib.rs --output target/doc
$ rustdoc src/lib.rs --out-dir target/doc
```
By default, `rustdoc`'s output appears in a directory named `doc` in

View file

@ -504,8 +504,18 @@ impl Options {
return Err(1);
}
let output =
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
let output = match (out_dir, output) {
(Some(_), Some(_)) => {
diag.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
return Err(1);
}
(Some(out_dir), None) => out_dir,
(None, Some(output)) => output,
(None, None) => PathBuf::from("doc"),
};
let cfgs = matches.opt_strs("cfg");
let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));

View file

@ -278,7 +278,16 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
}),
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
stable("output", |o| {
o.optopt(
"",
"output",
"Which directory to place the output. \
This option is deprecated, use --out-dir instead.",
"PATH",
)
}),
stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")),
stable("crate-name", |o| {
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
}),

View file

@ -0,0 +1,8 @@
-include ../../run-make-fulldeps/tools.mk
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
all:
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --out-dir $(OUTPUT_DIR)
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs

View file

@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}

View file

@ -0,0 +1,8 @@
-include ../../run-make-fulldeps/tools.mk
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
all:
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR)
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs

View file

@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}

View file

@ -0,0 +1,8 @@
-include ../../run-make-fulldeps/tools.mk
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
all:
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib -o $(OUTPUT_DIR)
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs

View file

@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}

View file

@ -0,0 +1 @@
// compile-flags: --output ./foo

View file

@ -0,0 +1,2 @@
error: cannot use both 'out-dir' and 'output' at once