about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-11 08:22:30 +0100
committerGitHub <noreply@github.com>2021-12-11 08:22:30 +0100
commitd8bb4d69db35368cf3ceff92ee59b100339bce3b (patch)
tree3a5b9e442c50f010b343ae166178d644eca0e343 /src
parent2f8e2ff6ba7194424718e39f0482b6d350b5e170 (diff)
parent03be3e21b1e259b24859b8f00f5280e56bd0b254 (diff)
downloadrust-d8bb4d69db35368cf3ceff92ee59b100339bce3b.tar.gz
rust-d8bb4d69db35368cf3ceff92ee59b100339bce3b.zip
Rollup merge of #91310 - hi-rustin:rustin-patch-rustdoc, r=jyn514
Add --out-dir flag for rustdoc

part of https://github.com/rust-lang/rust/issues/91260

Add --out-dir flag for rustdoc and change the `-o` option to point to out-dir.

I'm not quite sure if it should be stable, also I'm not sure if this parameter priority is appropriate? Or should I just refuse to pass both parameters at the same time?

r? `@jyn514`
Diffstat (limited to 'src')
-rw-r--r--src/doc/rustdoc/src/command-line-arguments.md4
-rw-r--r--src/librustdoc/config.rs14
-rw-r--r--src/librustdoc/lib.rs11
-rw-r--r--src/test/run-make/rustdoc-with-out-dir-option/Makefile8
-rw-r--r--src/test/run-make/rustdoc-with-out-dir-option/src/lib.rs2
-rw-r--r--src/test/run-make/rustdoc-with-output-option/Makefile8
-rw-r--r--src/test/run-make/rustdoc-with-output-option/src/lib.rs2
-rw-r--r--src/test/run-make/rustdoc-with-short-out-dir-option/Makefile8
-rw-r--r--src/test/run-make/rustdoc-with-short-out-dir-option/src/lib.rs2
-rw-r--r--src/test/rustdoc-ui/use_both_out_dir_and_output_options.rs1
-rw-r--r--src/test/rustdoc-ui/use_both_out_dir_and_output_options.stderr2
11 files changed, 57 insertions, 5 deletions
diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md
index d6948622662..9de2e733de7 100644
--- a/src/doc/rustdoc/src/command-line-arguments.md
+++ b/src/doc/rustdoc/src/command-line-arguments.md
@@ -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
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 04bcade156a..ee19567be10 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -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));
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index b6311abb5c3..8699ab20b19 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -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")
         }),
diff --git a/src/test/run-make/rustdoc-with-out-dir-option/Makefile b/src/test/run-make/rustdoc-with-out-dir-option/Makefile
new file mode 100644
index 00000000000..f79fce8eeea
--- /dev/null
+++ b/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
diff --git a/src/test/run-make/rustdoc-with-out-dir-option/src/lib.rs b/src/test/run-make/rustdoc-with-out-dir-option/src/lib.rs
new file mode 100644
index 00000000000..044bb6acb19
--- /dev/null
+++ b/src/test/run-make/rustdoc-with-out-dir-option/src/lib.rs
@@ -0,0 +1,2 @@
+// @has foobar/fn.ok.html
+pub fn ok() {}
diff --git a/src/test/run-make/rustdoc-with-output-option/Makefile b/src/test/run-make/rustdoc-with-output-option/Makefile
new file mode 100644
index 00000000000..654f9672588
--- /dev/null
+++ b/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
diff --git a/src/test/run-make/rustdoc-with-output-option/src/lib.rs b/src/test/run-make/rustdoc-with-output-option/src/lib.rs
new file mode 100644
index 00000000000..044bb6acb19
--- /dev/null
+++ b/src/test/run-make/rustdoc-with-output-option/src/lib.rs
@@ -0,0 +1,2 @@
+// @has foobar/fn.ok.html
+pub fn ok() {}
diff --git a/src/test/run-make/rustdoc-with-short-out-dir-option/Makefile b/src/test/run-make/rustdoc-with-short-out-dir-option/Makefile
new file mode 100644
index 00000000000..1e9ba71de26
--- /dev/null
+++ b/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
diff --git a/src/test/run-make/rustdoc-with-short-out-dir-option/src/lib.rs b/src/test/run-make/rustdoc-with-short-out-dir-option/src/lib.rs
new file mode 100644
index 00000000000..044bb6acb19
--- /dev/null
+++ b/src/test/run-make/rustdoc-with-short-out-dir-option/src/lib.rs
@@ -0,0 +1,2 @@
+// @has foobar/fn.ok.html
+pub fn ok() {}
diff --git a/src/test/rustdoc-ui/use_both_out_dir_and_output_options.rs b/src/test/rustdoc-ui/use_both_out_dir_and_output_options.rs
new file mode 100644
index 00000000000..5037043f19a
--- /dev/null
+++ b/src/test/rustdoc-ui/use_both_out_dir_and_output_options.rs
@@ -0,0 +1 @@
+// compile-flags: --output ./foo
diff --git a/src/test/rustdoc-ui/use_both_out_dir_and_output_options.stderr b/src/test/rustdoc-ui/use_both_out_dir_and_output_options.stderr
new file mode 100644
index 00000000000..96d2295ac3e
--- /dev/null
+++ b/src/test/rustdoc-ui/use_both_out_dir_and_output_options.stderr
@@ -0,0 +1,2 @@
+error: cannot use both 'out-dir' and 'output' at once
+