Skip to content

Commit 832c97b

Browse files
committed
Allow remap-path-prefix in rustdoc
This adds the `--remap-path-prefix` (as an unstable option) to `rustdoc` as well, and passes it down to the rust compiler when compiling doctests. Combined with `--persist-doctests`, the generated executables should have the same resulting paths as the crate artifact itself.
1 parent a5c039c commit 832c97b

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

src/librustdoc/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ pub(crate) struct Options {
9292
pub(crate) debugging_opts: DebuggingOptions,
9393
/// Debugging (`-Z`) options strings to pass to the compiler.
9494
pub(crate) debugging_opts_strs: Vec<String>,
95+
/// Path remapping (`--remap-path-prefix`) directives to hand to the compiler.
96+
pub(crate) remap_path_prefix_strs: Vec<String>,
9597
/// The target used to compile the crate against.
9698
pub(crate) target: TargetTriple,
9799
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
@@ -179,6 +181,7 @@ impl fmt::Debug for Options {
179181
.field("check-cfgs", &self.check_cfgs)
180182
.field("codegen_options", &"...")
181183
.field("debugging_options", &"...")
184+
.field("remap_path_prefixes", &"...")
182185
.field("target", &self.target)
183186
.field("edition", &self.edition)
184187
.field("maybe_sysroot", &self.maybe_sysroot)
@@ -644,6 +647,7 @@ impl Options {
644647
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
645648
let codegen_options_strs = matches.opt_strs("C");
646649
let debugging_opts_strs = matches.opt_strs("Z");
650+
let remap_path_prefix_strs = matches.opt_strs("remap-path-prefix");
647651
let lib_strs = matches.opt_strs("L");
648652
let extern_strs = matches.opt_strs("extern");
649653
let runtool = matches.opt_str("runtool");
@@ -687,6 +691,7 @@ impl Options {
687691
codegen_options_strs,
688692
debugging_opts,
689693
debugging_opts_strs,
694+
remap_path_prefix_strs,
690695
target,
691696
edition,
692697
maybe_sysroot,

src/librustdoc/doctest.rs

+3
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ fn run_test(
360360
for debugging_option_str in &rustdoc_options.debugging_opts_strs {
361361
compiler.arg("-Z").arg(&debugging_option_str);
362362
}
363+
for remap_path_prefix_str in &rustdoc_options.remap_path_prefix_strs {
364+
compiler.arg("--remap-path-prefix").arg(&remap_path_prefix_str);
365+
}
363366
if no_run && !lang_string.compile_fail && rustdoc_options.persist_doctests.is_none() {
364367
compiler.arg("--emit=metadata");
365368
}

src/librustdoc/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ fn opts() -> Vec<RustcOptGroup> {
278278
stable("C", |o| {
279279
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
280280
}),
281+
unstable("remap-path-prefix", |o| {
282+
o.optmulti(
283+
"",
284+
"remap-path-prefix",
285+
"Remap source names in all output (compiler messages and output files)",
286+
"FROM=TO",
287+
)
288+
}),
281289
stable("document-private-items", |o| {
282290
o.optflagmulti("", "document-private-items", "document private items")
283291
}),

src/test/run-make-fulldeps/coverage-reports/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ endif
3535
# workaround for two problems causing tests to fail on Windows:
3636
#
3737
# 1. When multiple files appear in the `llvm-cov show` results, each file's coverage results can
38-
# appear in different a different order. Whether this is random or, somehow, platform-specific,
38+
# appear in a different order. Whether this is random or, somehow, platform-specific,
3939
# the Windows output flips the order of the files, compared to Linux. In the `uses_crate.rs`
4040
# test, the only test-unique (interesting) results we care about are the results for only one
4141
# of the two files, `mod/uses_crate.rs`, so the workaround is to ignore all but this one file.

src/test/run-make-fulldeps/remap-path-prefix/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ all:
77
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs
88
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
99
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
10+
$(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
11+
grep "/the/pwd" $(TMPDIR)/rustdoc-remap/auxiliary_lib_rs_1_0/rust_out || exit 1
12+
! grep "$$PWD" $(TMPDIR)/rustdoc-remap/auxiliary_lib_rs_1_0/rust_out || exit 1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// ```
2+
/// assert_eq!(1, 1);
3+
/// ```
14
pub fn lib() {
25
panic!("calm");
36
}

0 commit comments

Comments
 (0)