Skip to content

Allow remap-path-prefix in rustdoc #92648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub(crate) struct Options {
pub(crate) debugging_opts: DebuggingOptions,
/// Debugging (`-Z`) options strings to pass to the compiler.
pub(crate) debugging_opts_strs: Vec<String>,
/// Path remapping (`--remap-path-prefix`) directives to hand to the compiler.
pub(crate) remap_path_prefix_strs: Vec<String>,
/// The target used to compile the crate against.
pub(crate) target: TargetTriple,
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
Expand Down Expand Up @@ -179,6 +181,7 @@ impl fmt::Debug for Options {
.field("check-cfgs", &self.check_cfgs)
.field("codegen_options", &"...")
.field("debugging_options", &"...")
.field("remap_path_prefixes", &"...")
.field("target", &self.target)
.field("edition", &self.edition)
.field("maybe_sysroot", &self.maybe_sysroot)
Expand Down Expand Up @@ -644,6 +647,7 @@ impl Options {
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
let codegen_options_strs = matches.opt_strs("C");
let debugging_opts_strs = matches.opt_strs("Z");
let remap_path_prefix_strs = matches.opt_strs("remap-path-prefix");
let lib_strs = matches.opt_strs("L");
let extern_strs = matches.opt_strs("extern");
let runtool = matches.opt_str("runtool");
Expand Down Expand Up @@ -687,6 +691,7 @@ impl Options {
codegen_options_strs,
debugging_opts,
debugging_opts_strs,
remap_path_prefix_strs,
target,
edition,
maybe_sysroot,
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ fn run_test(
for debugging_option_str in &rustdoc_options.debugging_opts_strs {
compiler.arg("-Z").arg(&debugging_option_str);
}
for remap_path_prefix_str in &rustdoc_options.remap_path_prefix_strs {
compiler.arg("--remap-path-prefix").arg(&remap_path_prefix_str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is the only place you use remap-path-prefix. I think you should also pass it to the compiler options in core.rs, as well as the options used for parsing doctests.

}
if no_run && !lang_string.compile_fail && rustdoc_options.persist_doctests.is_none() {
compiler.arg("--emit=metadata");
}
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ fn opts() -> Vec<RustcOptGroup> {
stable("C", |o| {
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
}),
unstable("remap-path-prefix", |o| {
o.optmulti(
"",
"remap-path-prefix",
"Remap source names in all output (compiler messages and output files)",
"FROM=TO",
)
}),
stable("document-private-items", |o| {
o.optflagmulti("", "document-private-items", "document private items")
}),
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/coverage-reports/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif
# workaround for two problems causing tests to fail on Windows:
#
# 1. When multiple files appear in the `llvm-cov show` results, each file's coverage results can
# appear in different a different order. Whether this is random or, somehow, platform-specific,
# appear in a different order. Whether this is random or, somehow, platform-specific,
# the Windows output flips the order of the files, compared to Linux. In the `uses_crate.rs`
# test, the only test-unique (interesting) results we care about are the results for only one
# of the two files, `mod/uses_crate.rs`, so the workaround is to ignore all but this one file.
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make-fulldeps/remap-path-prefix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ all:
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
$(RUSTDOC) --test --no-run -C debuginfo=1 -C split-debuginfo=off -Zunstable-options --remap-path-prefix $$PWD/auxiliary=/the/aux --remap-path-prefix $$PWD=/the/pwd --persist-doctests=$(TMPDIR)/rustdoc-remap auxiliary/lib.rs
grep "/the/pwd" $(TMPDIR)/rustdoc-remap/auxiliary_lib_rs_1_0/rust_out || exit 1
! grep "$$PWD" $(TMPDIR)/rustdoc-remap/auxiliary_lib_rs_1_0/rust_out || exit 1
3 changes: 3 additions & 0 deletions src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// ```
/// assert_eq!(1, 1);
/// ```
pub fn lib() {
panic!("calm");
}