-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a file-path remapping feature in support of debuginfo and reproducible builds #41508
Implement a file-path remapping feature in support of debuginfo and reproducible builds #41508
Conversation
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a potentially confusing CLUI to me. At this point I would simply make -Z remap-path
take two arguments… obviously not something our argument parser can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know, it's not perfect. There's been quite some discussion about the CLUI in the initial issue (#38322). This seemed to be an acceptable compromise. It's an unstable feature at the moment. If our parser had some improvements before this is stabilized, we could certainly revisit this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the values are paths, and most file systems do not like colon ':'
in path names, can't a single argument be bifurcated on a colon? Example: -Z remap-path="original_path_from:preferred_path_to"
.
Looks great to me! Was it intentional to remove the same-number-arguments validation? (checking that the same number of -to as -from was supplied) |
Good catch! I'll add it back in tomorrow. |
@rust-lang/docs, is there a place where a not-yet-stable feature like this can be documented? |
Unstable book would be the place except it doesn't support unstable flags
due to overzealous tidy lint.
On Apr 25, 2017 5:23 PM, "Michael Woerister" <notifications@github.com> wrote:
@rust-lang/docs <https://github.com/orgs/rust-lang/teams/docs>, is there a
place where a not-yet-stable feature like this can be documented?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#41508 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AApc0i66l7IKfBrC2LZELtMi5Kcib0nGks5rzgHMgaJpZM4NGdXh>
.
|
Yep! Just add a new file to this directory and link to it in the 'compiler flags' section of the summary file. |
An example of an existing entry: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/linker-flavor.html |
OK, I added some documentation to the unstable book and made the codegen test check more things. |
☔ The latest upstream changes (presumably #41504) made this pull request unmergeable. Please resolve the merge conflicts. |
5b20acc
to
7be6f22
Compare
7be6f22
to
4dbd8a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few nits, otherwise r=me
src/doc/unstable-book/src/SUMMARY.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
- [Compiler flags](compiler-flags.md) | |||
- [linker_flavor](compiler-flags/linker-flavor.md) | |||
- [linker_flavor](compiler-flags/remap-path-prefix.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/linker_flavor/remap_path_prefix/
@@ -0,0 +1,37 @@ | |||
# `remap-path-prefix` | |||
|
|||
The tracking issue for this feature is: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind opening a tracking issue for this?
4dbd8a3
to
ab9691d
Compare
@bors r=alexcrichton Nits fixed, I think. |
📌 Commit ab9691d has been approved by |
Thanks for turning this around @michaelwoerister! I hope to try this out soon. BTW, assuming this gets stabilized in more or less the current form, what would the stable command-line options look like? |
```text | ||
rustc -Zremap-path-prefix-from="/home/foo/my-project/src" -Zremap-path-prefix-to="/sources/my-project" | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear from this how the remapping is actually operating. It should also answer:
- Is it delimited by path element boundaries, or is it operating on literal strings?
- Is there any normalization performed before/after doing the transformation? (Redundant
/
elimination?) - Are the input paths absolute, relative, or whatever was provided to the compiler?
- In this example, if the input path were
/home/foo/my-project/src-orig
, would this remap to/sources/my-project-orig
? Should there be a trailing/
to prevent this if its undesirable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. I'll provide some more documentation in a follow-up PR. The implementation as it is does as little as possible: (1) Take each string as it is provided to the compiler, (2) don't do any normalization, (3) do a simple string-level prefix replacement.
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
Mappings specified later on the line will take precedence over earlier ones.
actually mean? Do you mean that if the -Zremap-path-prefix-from
is identical it is replaced? Or does it more generally apply, such that a more specific path overrides a more general one?
For example, what's the mapping for:
rustc -Zremap-path-prefix-from=my-project/src -Zremap-path-prefix-to=/sources/my-project \
-Zremap-path-prefix-from=my-project/src/vendored/otherproject -Zremap-path-prefix-to=/sources/otherproject
when applied to my-project/src/vendored/otherproject/src/lib.rs
?
In other words, does the ordering of the -from
options matter when multiple mappings could apply? Or is there some other way to disambiguate multiple matching mappings?
Is it guaranteed that at most a single mapping can be applied, or is there some notion of repeated application of mappings until nothing matches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if defining the matching as:
- later
remap-path-prefix-from
replaces a previous identical one - mappings are matched from longest
from
prefix to shortest
would be better.
I think this would make it deterministically always select more specific mappings over more general ones, rather than relying purely on ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would differ from the current behaviour in the example a/b -> y, a -> x
. I'm not sure which is better, but without a concrete argument that the new one is better I'd suggest to stick with the current behaviour which is simple to describe and implement. The other behaviour would require a trie-like data structure or other more complex thing.
I'm trying to standardise this behaviour across multiple compilers and GCC is already doing something very similar based on the ordering of command-line flags (and I have a patch pending to make it exactly match the behaviour being proposed in this PR). Changing this in the suggested way would make the spec for this standard even more complex. :(
In real-world cases I don't think the issue will crop up, in rustc or anywhere else - it's unlikely that a child process inheriting a prefix-map from a parent process would want to add a less-specific mapping for a higher-level directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is very simple: Walk all from/to pairs as provided on the commandline, starting at the last, and just stop at the first match.
In my opinion, relying only on ordering is a good approach, since the rules are clear and without surprises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current behaviour allows you to specify useless mappings (by putting more general before more specific in the reverse ordering), which might be inadvertent or unexpected.
I don't think it would require very fancy structures; I think you could implement it pretty simply using BTreeMap<String, String>
instead of Vec<String, String>
. It would be nice to have an algorithm that can have more efficient implementations (ie, not linear search), to cope with the case where there are lots of mappings (but that's definitely not a requirement for the first implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, relying only on ordering is a good approach, since the rules are clear and without surprises
I think that's fine - I think the wording could do with clarification (ie, I managed to misinterpret what it meant until I looked at the source).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. I'll provide an update in a subsequent PR and make sure to ping the usual suspects for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the ordering of flags for the lookup allows easy overriding of previous flags without needing to have a way to remove items from an accumulated list of flags (ex: presuming a variable in some higher level build env is accumulating RUST_FLAGS, using ordering means there is no need to parse all the accumulated flags to figure out which ones to remove when adding a higher priority remapping).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that might be useful to have anyway, since an identity mapping is semantically different from no mapping at all.
As this remaps all paths, will this also resolve #40552 ? ie: does it affect the expansion of |
@jmesmon - I believe that's the intent. |
@TimNN Thanks for the tip! But the problem is already caused by the arguments passed to the compiler, I think. |
More specifically, the test case tells the compiler to replace something Unix-specific here:
But on Windows the compiler will see the equivalent of
😭 |
@michaelwoerister I'd also consider it ok to ignore the test on windows, it seems like we may not benefit much from the extra coverage there |
@bors r=alexcrichton OK, since we are only doing string replacement there should be nothing platform-specific in there atm, so I |
📌 Commit 8ea050d has been approved by |
⌛ Testing commit 8ea050d with merge 9339127... |
💔 Test failed - status-travis |
…xcrichton Implement a file-path remapping feature in support of debuginfo and reproducible builds This PR adds the `-Zremap-path-prefix-from`/`-Zremap-path-prefix-to` commandline option pair and is a more general implementation of #41419. As opposed to the previous attempt, this implementation should enable reproducible builds regardless of the working directory of the compiler. This implementation of the feature is more general in the sense that the re-mapping will affect *all* paths the compiler emits, including the ones in error messages. r? @alexcrichton
☀️ Test successful - status-appveyor, status-travis |
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes rust-lang#73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in rust-lang#72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by rust-lang#44940) and `name_was_remapped` (introduced by rust-lang#41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes rust-lang#73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in rust-lang#72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by rust-lang#44940) and `name_was_remapped` (introduced by rust-lang#41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes rust-lang#73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in rust-lang#72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by rust-lang#44940) and `name_was_remapped` (introduced by rust-lang#41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
This PR adds the
-Zremap-path-prefix-from
/-Zremap-path-prefix-to
commandline option pair and is a more general implementation of #41419. As opposed to the previous attempt, this implementation should enable reproducible builds regardless of the working directory of the compiler.This implementation of the feature is more general in the sense that the re-mapping will affect all paths the compiler emits, including the ones in error messages.
r? @alexcrichton