]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #85344 - cbeuw:remap-across-cwd, r=michaelwoerister
authorbors <bors@rust-lang.org>
Wed, 25 Aug 2021 10:58:43 +0000 (10:58 +0000)
committerbors <bors@rust-lang.org>
Wed, 25 Aug 2021 10:58:43 +0000 (10:58 +0000)
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.

1  2 
compiler/rustc_metadata/src/rmeta/encoder.rs

index d9bbb03129975de9884dbf73d9ce61c174c8b60a,f7701e7fc9ddf0d6e2d29028df651d1aac78fcdc..1c243f8bd514835d7d60ab2d319120e270eb68dc
@@@ -503,17 -494,23 +503,26 @@@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> 
                                  // Prepend path of working directory onto potentially
                                  // relative paths, because they could become relative
                                  // to a wrong directory.
 -                                let working_dir = &self.tcx.sess.working_dir;
 +                                // We include `working_dir` as part of the crate hash,
 +                                // so it's okay for us to use it as part of the encoded
 +                                // metadata.
 +                                let working_dir = &self.tcx.sess.opts.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(joined)
+                                         }
                                      }
                                      RealFileName::Remapped { local_path: _, virtual_name } => {
                                          // If working_dir has been remapped, then we emit