Skip to content

Commit

Permalink
Fix up source name remapping
Browse files Browse the repository at this point in the history
- allow arbitrary numbers of remappings
- if we're remapping an absolute path, make the remappings absolute
  • Loading branch information
jsgf committed Jan 17, 2017
1 parent d65e2f1 commit 448e139
Showing 4 changed files with 47 additions and 30 deletions.
30 changes: 14 additions & 16 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ top_level_options!(
// Include the debug_assertions flag into dependency tracking, since it
// can influence whether overflow checks are done or not.
debug_assertions: bool [TRACKED],
debug_prefix_map: Option<(String, String)> [TRACKED],
debug_prefix_map: Vec<(String, String)> [TRACKED],
debuginfo: DebugInfoLevel [TRACKED],
lint_opts: Vec<(String, lint::Level)> [TRACKED],
lint_cap: Option<lint::Level> [TRACKED],
@@ -446,7 +446,7 @@ pub fn basic_options() -> Options {
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
debug_prefix_map: None,
debug_prefix_map: Vec::new(),
actually_rustdoc: false,
}
}
@@ -803,7 +803,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"optimize with possible levels 0-3, s, or z"),
debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
"explicitly enable the cfg(debug_assertions) directive"),
debug_prefix_map: String = ("".to_string(), parse_string, [TRACKED],
debug_prefix_map: Vec<String> = (vec![], parse_string_push, [TRACKED],
"remap OLD to NEW in debug info (OLD=NEW)"),
inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED],
"set the inlining threshold for"),
@@ -1428,18 +1428,16 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
};
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);

let debug_prefix_map = if !cg.debug_prefix_map.is_empty() {
let mut parts = cg.debug_prefix_map.splitn(2, '=');
let old = parts.next().unwrap();
let new = match parts.next() {
Some(new) => new,
None => early_error(error_format,
"-C debug-prefix-map value must be of the format `OLD=NEW`"),
};
Some((old.to_string(), new.to_string()))
} else {
None
};
let debug_prefix_map = cg.debug_prefix_map.iter()
.map(|m| {
let parts = m.splitn(2, '=').collect::<Vec<_>>();
if parts.len() != 2 {
early_error(error_format,
"-C debug-prefix-map value must be of the format `OLD=NEW`")
}
(parts[0].to_string(), parts[1].to_string())
})
.collect();

let debuginfo = if matches.opt_present("g") {
if cg.debuginfo.is_some() {
@@ -1733,7 +1731,7 @@ mod dep_tracking {
impl_dep_tracking_hash_via_hash!(Option<bool>);
impl_dep_tracking_hash_via_hash!(Option<usize>);
impl_dep_tracking_hash_via_hash!(Option<String>);
impl_dep_tracking_hash_via_hash!(Option<(String, String)>);
impl_dep_tracking_hash_via_hash!(Vec<(String, String)>);
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
43 changes: 31 additions & 12 deletions src/librustc_trans/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
@@ -657,10 +657,24 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
metadata
}

fn remap_path(sess: &Session, path: &str) -> String {
for (old, new) in sess.opts.debug_prefix_map.clone() {
fn remap_path(sess: &Session, dir: Option<&str>, remap_dir: Option<&str>, path: &str) -> String {
for &(ref old, ref new) in &sess.opts.debug_prefix_map {
// If `old` is not absolute and we've been given a dir, add the dir to make
// it absolute. Otherwise use `old` as-is.
let old = if dir.is_none() || Path::new(old).is_absolute() {
old.to_string()
} else {
format!("{}/{}", dir.unwrap(), old)
};
if path.starts_with(&old) {
return new + &path[old.len()..];
// Likewise, add `remap_dir` to new if we have one and `new` isn't absolute.
let mut ret = if remap_dir.is_none() || Path::new(new).is_absolute() {
new.to_string()
} else {
format!("{}/{}", remap_dir.unwrap(), new)
};
ret.push_str(&path[old.len()..]);
return ret;
}
}
path.to_string()
@@ -669,18 +683,23 @@ fn remap_path(sess: &Session, path: &str) -> String {
pub fn file_metadata(cx: &CrateContext, path: &str, full_path: &Option<String>) -> DIFile {
// FIXME (#9639): This needs to handle non-utf8 paths
let work_dir = cx.sess().working_dir.to_str().unwrap();
let file_name =
full_path.as_ref().map(|p| p.as_str()).unwrap_or_else(|| {
if path.starts_with(work_dir) {
let sess = cx.sess();
let remap_dir = remap_path(sess, None, None, work_dir);

let remap_file_name = match full_path {
&None => {
// Huh: return a relative path?
let p = if path.starts_with(work_dir) {
&path[work_dir.len() + 1..path.len()]
} else {
path
}
});
};
remap_path(sess, None, None, p)
},
// Huh: return an absolute path?
&Some(ref full) => remap_path(sess, Some(work_dir), Some(&remap_dir), full),
};

let sess = cx.sess();
let remap_file_name = remap_path(sess, file_name);
let remap_dir = remap_path(sess, work_dir);
file_metadata_(cx, path, &remap_file_name, &remap_dir)
}

@@ -793,7 +812,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
}
};

let work_dir = remap_path(sess, work_dir);
let work_dir = remap_path(sess, None, None, work_dir);

debug!("compile_unit_metadata: {:?}", compile_unit_name);
let producer = format!("rustc version {}",
2 changes: 1 addition & 1 deletion src/llvm

0 comments on commit 448e139

Please sign in to comment.