Skip to content

Commit 958d788

Browse files
committed
Auto merge of rust-lang#85344 - cbeuw:remap-across-cwd, r=michaelwoerister
Correctly handle remapping from path containing the current directory with trailing paths If we have a `auxiliary/lib.rs`, and we generate the metadata with `--remap-path-prefix $PWD/auxiliary=xyz`, the path to `$PWD/auxiliary/lib.rs` won't be correctly remapped in the metadata. This is because internally, path to the working directory itself and relative paths to files under the working directory are remapped separately (hence neither are affected since neither has `$PWD/auxiliary` as prefix), but the concatenation between the working directory and the relative path is not remapped. This PR fixes that.
2 parents 9863bf5 + 7ed9f2e commit 958d788

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,20 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
509509
let working_dir = &self.tcx.sess.opts.working_dir;
510510
match working_dir {
511511
RealFileName::LocalPath(absolute) => {
512-
// If working_dir has not been remapped, then we emit a
513-
// LocalPath variant as it's likely to be a valid path
514-
RealFileName::LocalPath(
515-
Path::new(absolute).join(path_to_file),
516-
)
512+
// Although neither working_dir or the file name were subject
513+
// to path remapping, the concatenation between the two may
514+
// be. Hence we need to do a remapping here.
515+
let joined = Path::new(absolute).join(path_to_file);
516+
let (joined, remapped) =
517+
source_map.path_mapping().map_prefix(joined);
518+
if remapped {
519+
RealFileName::Remapped {
520+
local_path: None,
521+
virtual_name: joined,
522+
}
523+
} else {
524+
RealFileName::LocalPath(joined)
525+
}
517526
}
518527
RealFileName::Remapped { local_path: _, virtual_name } => {
519528
// If working_dir has been remapped, then we emit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
# ignore-windows
4+
5+
# Checks if remapping works if the remap-from string contains path to the working directory plus more
6+
all:
7+
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs
8+
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
9+
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn lib() {
2+
panic!("calm");
3+
}

0 commit comments

Comments
 (0)