pub struct PrefixMap { /* private fields */ }Expand description
A list of old=new rewrites to apply to a path before it is written into the output, which is
what the -f*-prefix-map= family asks for.
The point of them is a build whose output does not depend on where it was built. A path is the
last thing in an object that a second machine cannot reproduce: two people who check out the
same commit and run the same compiler get the same instructions and different __FILE__
strings, and a distribution that wants to prove its binaries came from its sources has to make
that difference go away. So the build says what its root is called, and every path that would
name the real one names that instead.
The rule is a plain string prefix and nothing more, which is worth saying because it looks like
it ought to be about directories. gcc compares the characters, so s=B turns sub/h.h into
Bub/h.h, and an empty old matches everything and puts new in front of it. The path
compared against is the one the search found, so a header reached through a relative -I is
mapped as a relative path and the same header reached through an absolute one is mapped as an
absolute path.
Implementations§
Source§impl PrefixMap
impl PrefixMap
Sourcepub fn new() -> Self
pub fn new() -> Self
No rewrites, which is what a command line that says nothing about this gets.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether nothing was asked for, which is the case worth not spending anything on.
Sourcepub fn push(&mut self, old: impl Into<String>, new: impl Into<String>)
pub fn push(&mut self, old: impl Into<String>, new: impl Into<String>)
Adds a rewrite, which is what one flag on the command line is.
Sourcepub fn split(arg: &str) -> Option<(&str, &str)>
pub fn split(arg: &str) -> Option<(&str, &str)>
The two halves of one flag’s argument, split at the last = rather than the first.
That is where gcc splits it, and it is the answer that makes a path containing an =
mappable: -ffile-prefix-map=/home/a=b=/src maps the directory /home/a=b. The cost is
that a replacement cannot contain one, which is the rarer thing to want. None when there
is no = at all, which gcc refuses rather than reading as a mapping to nothing.
Sourcepub fn apply<'a>(&self, path: &'a str) -> Cow<'a, str>
pub fn apply<'a>(&self, path: &'a str) -> Cow<'a, str>
path with the last rewrite that matches it applied, or path where none does.
The last rather than the first, because that is gcc’s answer and because it is the one a build relies on: a mapping set for the whole project and a narrower one set for one directory is a command line where the second is meant to win.