about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2018-02-18 15:05:24 -0800
committerJeremy Fitzhardinge <jsgf@fb.com>2018-02-22 15:13:21 -0800
commit56a68285332000c858e9aeba7d66a4ec66ebff91 (patch)
tree2eefbd5dddbb4458f91f1ca2eddb9eccb6850928
parentb1f8e6fb06d7362eeb2065347a7db94e76b1cb2f (diff)
downloadrust-56a68285332000c858e9aeba7d66a4ec66ebff91.tar.gz
rust-56a68285332000c858e9aeba7d66a4ec66ebff91.zip
Implement --remap-path-prefix
Remove experimental -Zremap-path-prefix-from/to, and replace it with
the stabilized --remap-path-prefix=from=to variant.

This is an implementation for issue of #41555.
-rw-r--r--src/doc/man/rustc.110
-rw-r--r--src/doc/unstable-book/src/compiler-flags/remap-path-prefix.md37
-rw-r--r--src/libproc_macro/lib.rs2
-rw-r--r--src/librustc/session/config.rs47
-rw-r--r--src/librustc_metadata/encoder.rs2
-rw-r--r--src/libsyntax/codemap.rs2
-rw-r--r--src/libsyntax_pos/lib.rs2
-rw-r--r--src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs2
-rw-r--r--src/test/codegen/remap_path_prefix/main.rs2
-rw-r--r--src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs2
10 files changed, 38 insertions, 70 deletions
diff --git a/src/doc/man/rustc.1 b/src/doc/man/rustc.1
index 19f6cc9ac61..39d10539959 100644
--- a/src/doc/man/rustc.1
+++ b/src/doc/man/rustc.1
@@ -125,6 +125,16 @@ Print version info and exit.
 \fB\-v\fR, \fB\-\-verbose\fR
 Use verbose output.
 .TP
+\fB\-\-remap\-path\-prefix\fR \fIfrom\fR=\fIto\fR
+Remap source path prefixes in all output, including compiler diagnostics, debug information,
+macro expansions, etc. The \fIfrom\fR=\fIto\fR parameter is scanned from right to left, so \fIfrom\fR
+may contain '=', but \fIto\fR may not.
+
+This is useful for normalizing build products, for example by removing the current directory out of
+pathnames emitted into the object files. The replacement is purely textual, with no consideration of
+the current system's pathname syntax. For example \fI\-\-remap\-path\-prefix foo=bar\fR will
+match \fBfoo/lib.rs\fR but not \fB./foo/lib.rs\fR.
+.TP
 \fB\-\-extern\fR \fINAME\fR=\fIPATH\fR
 Specify where an external rust library is located. These should match
 \fIextern\fR declarations in the crate's source code.
diff --git a/src/doc/unstable-book/src/compiler-flags/remap-path-prefix.md b/src/doc/unstable-book/src/compiler-flags/remap-path-prefix.md
deleted file mode 100644
index 8ca04d25325..00000000000
--- a/src/doc/unstable-book/src/compiler-flags/remap-path-prefix.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# `remap-path-prefix`
-
-The tracking issue for this feature is: [#41555](https://github.com/rust-lang/rust/issues/41555)
-
-------------------------
-
-The `-Z remap-path-prefix-from`, `-Z remap-path-prefix-to` commandline option
-pair allows to replace prefixes of any file paths the compiler emits in various
-places. This is useful for bringing debuginfo paths into a well-known form and
-for achieving reproducible builds independent of the directory the compiler was
-executed in. All paths emitted by the compiler are affected, including those in
-error messages.
-
-In order to map all paths starting with `/home/foo/my-project/src` to
-`/sources/my-project`, one would invoke the compiler as follows:
-
-```text
-rustc -Zremap-path-prefix-from="/home/foo/my-project/src" -Zremap-path-prefix-to="/sources/my-project"
-```
-
-Debuginfo for code from the file `/home/foo/my-project/src/foo/mod.rs`,
-for example, would then point debuggers to `/sources/my-project/foo/mod.rs`
-instead of the original file.
-
-The options can be specified multiple times when multiple prefixes should be
-mapped:
-
-```text
-rustc -Zremap-path-prefix-from="/home/foo/my-project/src" \
-      -Zremap-path-prefix-to="/sources/my-project" \
-      -Zremap-path-prefix-from="/home/foo/my-project/build-dir" \
-      -Zremap-path-prefix-to="/stable-build-dir"
-```
-
-When the options are given multiple times, the nth `-from` will be matched up
-with the nth `-to` and they can appear anywhere on the commandline. Mappings
-specified later on the line will take precedence over earlier ones.
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs
index 6768e0ade43..0f31ac15a45 100644
--- a/src/libproc_macro/lib.rs
+++ b/src/libproc_macro/lib.rs
@@ -316,7 +316,7 @@ impl SourceFile {
     /// If the code span associated with this `SourceFile` was generated by an external macro, this
     /// may not be an actual path on the filesystem. Use [`is_real`] to check.
     ///
-    /// Also note that even if `is_real` returns `true`, if `-Z remap-path-prefix-*` was passed on
+    /// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on
     /// the command line, the path as given may not actually be valid.
     ///
     /// [`is_real`]: #method.is_real
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index cfbf233297c..1d554cb0d82 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -435,6 +435,9 @@ top_level_options!(
         // if we otherwise use the defaults of rustc.
         cli_forced_codegen_units: Option<usize> [UNTRACKED],
         cli_forced_thinlto_off: bool [UNTRACKED],
+
+        // Remap source path prefixes in all output (messages, object files, debug, etc)
+        remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
     }
 );
 
@@ -617,6 +620,7 @@ pub fn basic_options() -> Options {
         actually_rustdoc: false,
         cli_forced_codegen_units: None,
         cli_forced_thinlto_off: false,
+        remap_path_prefix: Vec::new(),
     }
 }
 
@@ -635,11 +639,7 @@ impl Options {
     }
 
     pub fn file_path_mapping(&self) -> FilePathMapping {
-        FilePathMapping::new(
-            self.debugging_opts.remap_path_prefix_from.iter().zip(
-                self.debugging_opts.remap_path_prefix_to.iter()
-            ).map(|(src, dst)| (src.clone(), dst.clone())).collect()
-        )
+        FilePathMapping::new(self.remap_path_prefix.clone())
     }
 
     /// True if there will be an output file generated
@@ -1269,10 +1269,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
         "set the optimization fuel quota for a crate"),
     print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
         "make Rustc print the total optimization fuel used by a crate"),
-    remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
-        "add a source pattern to the file path remapping config"),
-    remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
-        "add a mapping target to the file path remapping config"),
     force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
         "force all crates to be `rustc_private` unstable"),
     pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
@@ -1595,6 +1591,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
                   `expanded` (crates expanded), or
                   `expanded,identified` (fully parenthesized, AST nodes with IDs).",
                  "TYPE"),
+        opt::multi_s("", "remap-path-prefix", "remap source names in output", "FROM=TO"),
     ]);
     opts
 }
@@ -1718,23 +1715,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
         output_types.insert(OutputType::Exe, None);
     }
 
-    let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
-    let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len();
-
-    if remap_path_prefix_targets < remap_path_prefix_sources {
-        for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {
-            early_error(error_format,
-                &format!("option `-Zremap-path-prefix-from='{}'` does not have \
-                         a corresponding `-Zremap-path-prefix-to`", source.display()))
-        }
-    } else if remap_path_prefix_targets > remap_path_prefix_sources {
-        for target in &debugging_opts.remap_path_prefix_to[remap_path_prefix_sources..] {
-            early_error(error_format,
-                &format!("option `-Zremap-path-prefix-to='{}'` does not have \
-                          a corresponding `-Zremap-path-prefix-from`", target.display()))
-        }
-    }
-
     let mut cg = build_codegen_options(matches, error_format);
     let mut codegen_units = cg.codegen_units;
     let mut disable_thinlto = false;
@@ -1968,6 +1948,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
 
     let crate_name = matches.opt_str("crate-name");
 
+    let remap_path_prefix = matches.opt_strs("remap-path-prefix")
+        .into_iter()
+        .map(|remap| {
+            let mut parts = remap.rsplitn(2, '='); // reverse iterator
+            let to = parts.next();
+            let from = parts.next();
+            match (from, to) {
+                (Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
+                _ => early_error(error_format,
+                        "--remap-path-prefix must contain '=' between FROM and TO"),
+            }
+        })
+        .collect();
+
     (Options {
         crate_types,
         optimize: opt_level,
@@ -1995,6 +1989,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
         actually_rustdoc: false,
         cli_forced_codegen_units: codegen_units,
         cli_forced_thinlto_off: disable_thinlto,
+        remap_path_prefix,
     },
     cfg)
 }
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 78578ca179c..d140b135416 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -323,7 +323,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
                 // paths because any relative paths are potentially relative to
                 // a wrong directory.
                 // However, if a path has been modified via
-                // `-Zremap-path-prefix` we assume the user has already set
+                // `--remap-path-prefix` we assume the user has already set
                 // things up the way they want and don't touch the path values
                 // anymore.
                 match filemap.name {
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index df5845f6c21..926548b6031 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -129,7 +129,7 @@ pub struct CodeMap {
     pub(super) files: RefCell<Vec<Rc<FileMap>>>,
     file_loader: Box<FileLoader>,
     // This is used to apply the file path remapping as specified via
-    // -Zremap-path-prefix to all FileMaps allocated within this CodeMap.
+    // --remap-path-prefix to all FileMaps allocated within this CodeMap.
     path_mapping: FilePathMapping,
     stable_id_to_filemap: RefCell<FxHashMap<StableFilemapId, Rc<FileMap>>>,
     /// In case we are in a doctest, replace all file names with the PathBuf,
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 294506625bc..e3f1417456c 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -664,7 +664,7 @@ pub struct FileMap {
     /// originate from files has names between angle brackets by convention,
     /// e.g. `<anon>`
     pub name: FileName,
-    /// True if the `name` field above has been modified by -Zremap-path-prefix
+    /// True if the `name` field above has been modified by --remap-path-prefix
     pub name_was_remapped: bool,
     /// The unmapped path of the file that the source came from.
     /// Set to `None` if the FileMap was imported from an external crate.
diff --git a/src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs b/src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs
index 5543a091680..3ef0ff9ef06 100644
--- a/src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs
+++ b/src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 
-// compile-flags: -g  -Zremap-path-prefix-from={{cwd}} -Zremap-path-prefix-to=/the/aux-cwd -Zremap-path-prefix-from={{src-base}}/remap_path_prefix/auxiliary -Zremap-path-prefix-to=/the/aux-src
+// compile-flags: -g  --remap-path-prefix={{cwd}}=/the/aux-cwd --remap-path-prefix={{src-base}}/remap_path_prefix/auxiliary=/the/aux-src
 
 #[inline]
 pub fn some_aux_function() -> i32 {
diff --git a/src/test/codegen/remap_path_prefix/main.rs b/src/test/codegen/remap_path_prefix/main.rs
index ea0c9ad2b83..2f46b6c5d48 100644
--- a/src/test/codegen/remap_path_prefix/main.rs
+++ b/src/test/codegen/remap_path_prefix/main.rs
@@ -11,7 +11,7 @@
 // ignore-windows
 // ignore-tidy-linelength
 
-// compile-flags: -g  -C no-prepopulate-passes -Zremap-path-prefix-from={{cwd}} -Zremap-path-prefix-to=/the/cwd -Zremap-path-prefix-from={{src-base}} -Zremap-path-prefix-to=/the/src
+// compile-flags: -g  -C no-prepopulate-passes --remap-path-prefix={{cwd}}=/the/cwd --remap-path-prefix={{src-base}}=/the/src
 // aux-build:remap_path_prefix_aux.rs
 
 extern crate remap_path_prefix_aux;
diff --git a/src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs b/src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs
index 1483bf92c97..c80b334623b 100644
--- a/src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs
+++ b/src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs
@@ -12,7 +12,7 @@
 
 //[rpass1] compile-flags: -g
 //[rpass2] compile-flags: -g
-//[rpass3] compile-flags: -g -Zremap-path-prefix-from={{src-base}} -Zremap-path-prefix-to=/the/src
+//[rpass3] compile-flags: -g --remap-path-prefix={{src-base}}=/the/src
 
 #![feature(rustc_attrs)]
 #![crate_type="rlib"]