Use local name if available in write_out_deps

This commit is contained in:
Andy Wang 2021-04-19 20:07:27 +01:00
parent e5445f3722
commit ec34cd94dd
No known key found for this signature in database
GPG key ID: 181B49F9F38F3374

View file

@ -36,7 +36,7 @@ use rustc_session::output::{filename_for_input, filename_for_metadata};
use rustc_session::search_paths::PathKind;
use rustc_session::Session;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{FileName, RealFileName};
use rustc_span::FileName;
use rustc_trait_selection::traits;
use rustc_typeck as typeck;
use tracing::{info, warn};
@ -532,10 +532,10 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
check_output(output_paths, check)
}
fn escape_dep_filename(filename: &FileName) -> String {
fn escape_dep_filename(filename: &String) -> String {
// Apparently clang and gcc *only* escape spaces:
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
filename.to_string().replace(" ", "\\ ")
filename.replace(" ", "\\ ")
}
// Makefile comments only need escaping newlines and `\`.
@ -575,7 +575,14 @@ fn write_out_deps(
.iter()
.filter(|fmap| fmap.is_real_file())
.filter(|fmap| !fmap.is_imported())
.map(|fmap| escape_dep_filename(&fmap.name))
.map(|fmap| {
escape_dep_filename(&match &fmap.name {
FileName::Real(real) => {
real.local_path().unwrap_or(real.stable_name()).display().to_string()
}
_ => fmap.name.to_string(),
})
})
.collect();
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
@ -587,16 +594,13 @@ fn write_out_deps(
for cnum in resolver.cstore().crates_untracked() {
let source = resolver.cstore().crate_source_untracked(cnum);
if let Some((path, _)) = source.dylib {
let file_name = FileName::Real(RealFileName::LocalPath(path));
files.push(escape_dep_filename(&file_name));
files.push(escape_dep_filename(&path.display().to_string()));
}
if let Some((path, _)) = source.rlib {
let file_name = FileName::Real(RealFileName::LocalPath(path));
files.push(escape_dep_filename(&file_name));
files.push(escape_dep_filename(&path.display().to_string()));
}
if let Some((path, _)) = source.rmeta {
let file_name = FileName::Real(RealFileName::LocalPath(path));
files.push(escape_dep_filename(&file_name));
files.push(escape_dep_filename(&path.display().to_string()));
}
}
});