Skip to content

Commit

Permalink
Add --out-dir flag for rustdoc
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
hi-rustin committed Nov 30, 2021
1 parent 4919988 commit 03be3e2
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/doc/rustdoc/src/command-line-arguments.md
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/librustdoc/config.rs
Expand Up @@ -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));
Expand Down
11 changes: 10 additions & 1 deletion src/librustdoc/lib.rs
Expand Up @@ -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")
}),
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-make/rustdoc-with-out-dir-option/Makefile
@@ -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
2 changes: 2 additions & 0 deletions src/test/run-make/rustdoc-with-out-dir-option/src/lib.rs
@@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}
8 changes: 8 additions & 0 deletions src/test/run-make/rustdoc-with-output-option/Makefile
@@ -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
2 changes: 2 additions & 0 deletions src/test/run-make/rustdoc-with-output-option/src/lib.rs
@@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}
8 changes: 8 additions & 0 deletions src/test/run-make/rustdoc-with-short-out-dir-option/Makefile
@@ -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
@@ -0,0 +1,2 @@
// @has foobar/fn.ok.html
pub fn ok() {}
1 change: 1 addition & 0 deletions src/test/rustdoc-ui/use_both_out_dir_and_output_options.rs
@@ -0,0 +1 @@
// compile-flags: --output ./foo
@@ -0,0 +1,2 @@
error: cannot use both 'out-dir' and 'output' at once

0 comments on commit 03be3e2

Please sign in to comment.