Skip to main content

PrefixMap

Struct PrefixMap 

Source
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

Source

pub fn new() -> Self

No rewrites, which is what a command line that says nothing about this gets.

Source

pub fn is_empty(&self) -> bool

Whether nothing was asked for, which is the case worth not spending anything on.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for PrefixMap

Source§

fn clone(&self) -> PrefixMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PrefixMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PrefixMap

Source§

fn default() -> PrefixMap

Returns the “default value” for a type. Read more
Source§

impl Eq for PrefixMap

Source§

impl PartialEq for PrefixMap

Source§

fn eq(&self, other: &PrefixMap) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PrefixMap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.