From b76ce696061f6c72a1df5aa6a935ade7cc30696b Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 15 May 2021 19:35:10 +0100 Subject: [PATCH 1/6] Add test for remap-from in the form of $PWD/trailing --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 6 ++++++ .../run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 src/test/run-make-fulldeps/remap-path-prefix/Makefile create mode 100644 src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile new file mode 100644 index 0000000000000..c923d7e80117d --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +# Checks if remapping works if the remap-from string contains path to the working directory plus more +all: + $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs + ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 diff --git a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs new file mode 100644 index 0000000000000..7067130a46181 --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs @@ -0,0 +1,3 @@ +fn lib() { + panic!("calm"); +} From 1ced98ac651510f1a614caf287fca88721c2b983 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 15 May 2021 19:36:42 +0100 Subject: [PATCH 2/6] Remap after prepending cwd --- compiler/rustc_metadata/src/rmeta/encoder.rs | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 29fcbffa0b952..1b7b851382e00 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -497,11 +497,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let working_dir = &self.tcx.sess.working_dir; match working_dir { RealFileName::LocalPath(absolute) => { - // If working_dir has not been remapped, then we emit a - // LocalPath variant as it's likely to be a valid path - RealFileName::LocalPath( - Path::new(absolute).join(path_to_file), - ) + // Although neither working_dir or the file name were subject + // to path remapping, the concatenation between the two may + // be. Hence we need to do a remapping here. + let joined = Path::new(absolute).join(path_to_file); + let (joined, remapped) = + source_map.path_mapping().map_prefix(joined); + if remapped { + RealFileName::Remapped { + local_path: None, + virtual_name: joined, + } + } else { + RealFileName::LocalPath( + Path::new(absolute).join(path_to_file), + ) + } } RealFileName::Remapped { local_path: _, virtual_name } => { // If working_dir has been remapped, then we emit From f3c18bb50dd9f09739cab7e69ded6ffb092ede5d Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sun, 16 May 2021 12:38:49 +0100 Subject: [PATCH 3/6] Reuse variable --- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1b7b851382e00..f7701e7fc9ddf 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -509,9 +509,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { virtual_name: joined, } } else { - RealFileName::LocalPath( - Path::new(absolute).join(path_to_file), - ) + RealFileName::LocalPath(joined) } } RealFileName::Remapped { local_path: _, virtual_name } => { From 70b9a7b988772817284dda19a5cd6e0d46cb7dbb Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 19 Aug 2021 19:01:19 +0100 Subject: [PATCH 4/6] Make test function pub --- src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs index 7067130a46181..019c786a9023e 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs +++ b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs @@ -1,3 +1,3 @@ -fn lib() { +pub fn lib() { panic!("calm"); } From 08c55bdce592154dbbe36588f4e228b4b3a0ecaf Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 19 Aug 2021 19:04:46 +0100 Subject: [PATCH 5/6] Test presence of remapped path --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile index c923d7e80117d..b01f406e55824 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/Makefile +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -3,4 +3,5 @@ # Checks if remapping works if the remap-from string contains path to the working directory plus more 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 From 7ed9f2e6aa1e38ff43c0fe56bd9afc7f8aec28ba Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 24 Aug 2021 13:21:27 +0100 Subject: [PATCH 6/6] Ignore test on Windows --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile index b01f406e55824..86785c59509df 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/Makefile +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -1,5 +1,7 @@ -include ../tools.mk +# ignore-windows + # Checks if remapping works if the remap-from string contains path to the working directory plus more all: $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs