diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-08-07 14:44:21 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-12-20 15:17:45 +0100 |
| commit | 05731afff2e7fb21eab3bc3c0c62c3d61a6d1d0a (patch) | |
| tree | 04a8503efbdc58f20016ec9571437304fe3915f6 | |
| parent | 8a1f8039a7ded79d3d4fe97b110016d89f2b11e2 (diff) | |
| download | rust-05731afff2e7fb21eab3bc3c0c62c3d61a6d1d0a.tar.gz rust-05731afff2e7fb21eab3bc3c0c62c3d61a6d1d0a.zip | |
Add `--doctest-compilation-args` option to allow passing arguments to doctest compilation
| -rw-r--r-- | src/librustdoc/config.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 11 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 10 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 34c91e33db7..af3c7cc7be3 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -172,6 +172,9 @@ pub(crate) struct Options { /// This is mainly useful for other tools that reads that debuginfo to figure out /// how to call the compiler with the same arguments. pub(crate) expanded_args: Vec<String>, + + /// Arguments to be used when compiling doctests. + pub(crate) doctest_compilation_args: Vec<String>, } impl fmt::Debug for Options { @@ -774,6 +777,7 @@ impl Options { let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx); let with_examples = matches.opt_strs("with-examples"); let call_locations = crate::scrape_examples::load_call_locations(with_examples, dcx); + let doctest_compilation_args = matches.opt_strs("doctest-compilation-args"); let unstable_features = rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref()); @@ -819,6 +823,7 @@ impl Options { scrape_examples_options, unstable_features, expanded_args: args, + doctest_compilation_args, }; let render_options = RenderOptions { output, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index ce44cb1c319..a53316dc6c1 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -78,6 +78,17 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) -> content.push(format!("-Z{unstable_option_str}")); } + for compilation_args in &options.doctest_compilation_args { + for flag in compilation_args + .split_whitespace() + .map(|flag| flag.trim()) + .filter(|flag| !flag.is_empty()) + { + // Very simple parsing implementation. Might be a good idea to correctly handle strings. + content.push(flag.to_string()); + } + } + let content = content.join("\n"); file.write_all(content.as_bytes()) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 7655c2e0e15..ff1c9c61720 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -642,6 +642,15 @@ fn opts() -> Vec<RustcOptGroup> { "Includes trait implementations and other crate info from provided path. Only use with --merge=finalize", "path/to/doc.parts/<crate-name>", ), + opt(Unstable, Flag, "", "html-no-source", "Disable HTML source code pages generation", ""), + opt( + Unstable, + Multi, + "", + "doctest-compilation-args", + "", + "add arguments to be used when compiling doctests", + ), // deprecated / removed options opt(Unstable, FlagMulti, "", "disable-minification", "removed", ""), opt( @@ -684,7 +693,6 @@ fn opts() -> Vec<RustcOptGroup> { "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information", "[rust]", ), - opt(Unstable, Flag, "", "html-no-source", "Disable HTML source code pages generation", ""), ] } |
