Use the virtual name for libstd files in StableSourceFileId and also in the
encoded build artifacts. Fix #70924.
This commit is contained in:
parent
da09fd3db0
commit
5e5a3d5867
3 changed files with 24 additions and 2 deletions
|
@ -396,7 +396,7 @@ impl<'tcx> EncodeContext<'tcx> {
|
|||
// any relative paths are potentially relative to a
|
||||
// wrong directory.
|
||||
FileName::Real(ref name) => {
|
||||
let name = name.local_path();
|
||||
let name = name.stable_name();
|
||||
let mut adapted = (**source_file).clone();
|
||||
adapted.name = Path::new(&working_dir).join(name).into();
|
||||
adapted.name_hash = {
|
||||
|
|
|
@ -99,6 +99,7 @@ pub enum RealFileName {
|
|||
|
||||
impl RealFileName {
|
||||
/// Returns the path suitable for reading from the file system on the local host.
|
||||
/// Avoid embedding this in build artifacts; see `stable_name` for that.
|
||||
pub fn local_path(&self) -> &Path {
|
||||
match self {
|
||||
RealFileName::Named(p)
|
||||
|
@ -107,12 +108,24 @@ impl RealFileName {
|
|||
}
|
||||
|
||||
/// Returns the path suitable for reading from the file system on the local host.
|
||||
/// Avoid embedding this in build artifacts; see `stable_name` for that.
|
||||
pub fn into_local_path(self) -> PathBuf {
|
||||
match self {
|
||||
RealFileName::Named(p)
|
||||
| RealFileName::Devirtualized { local_path: p, virtual_name: _ } => p,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path suitable for embedding into build artifacts. Note that
|
||||
/// a virtualized path will not correspond to a valid file system path; see
|
||||
/// `local_path` for something that is more likely to return paths into the
|
||||
/// local host file system.
|
||||
pub fn stable_name(&self) -> &Path {
|
||||
match self {
|
||||
RealFileName::Named(p)
|
||||
| RealFileName::Devirtualized { local_path: _, virtual_name: p } => &p,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Differentiates between real files and common virtual files.
|
||||
|
|
|
@ -86,6 +86,8 @@ impl FileLoader for RealFileLoader {
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
|
||||
pub struct StableSourceFileId(u128);
|
||||
|
||||
// FIXME: we need a more globally consistent approach to the problem solved by
|
||||
// StableSourceFileId, perhaps built atop source_file.name_hash.
|
||||
impl StableSourceFileId {
|
||||
pub fn new(source_file: &SourceFile) -> StableSourceFileId {
|
||||
StableSourceFileId::new_from_pieces(
|
||||
|
@ -102,7 +104,14 @@ impl StableSourceFileId {
|
|||
) -> StableSourceFileId {
|
||||
let mut hasher = StableHasher::new();
|
||||
|
||||
name.hash(&mut hasher);
|
||||
if let FileName::Real(real_name) = name {
|
||||
// rust-lang/rust#70924: Use the stable (virtualized) name when
|
||||
// available. (We do not want artifacts from transient file system
|
||||
// paths for libstd to leak into our build artifacts.)
|
||||
real_name.stable_name().hash(&mut hasher)
|
||||
} else {
|
||||
name.hash(&mut hasher);
|
||||
}
|
||||
name_was_remapped.hash(&mut hasher);
|
||||
unmapped_path.hash(&mut hasher);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue