Skip to content

Commit 448e139

Browse files
committed
Fix up source name remapping
- allow arbitrary numbers of remappings - if we're remapping an absolute path, make the remappings absolute
1 parent d65e2f1 commit 448e139

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

src/librustc/session/config.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ top_level_options!(
253253
// Include the debug_assertions flag into dependency tracking, since it
254254
// can influence whether overflow checks are done or not.
255255
debug_assertions: bool [TRACKED],
256-
debug_prefix_map: Option<(String, String)> [TRACKED],
256+
debug_prefix_map: Vec<(String, String)> [TRACKED],
257257
debuginfo: DebugInfoLevel [TRACKED],
258258
lint_opts: Vec<(String, lint::Level)> [TRACKED],
259259
lint_cap: Option<lint::Level> [TRACKED],
@@ -446,7 +446,7 @@ pub fn basic_options() -> Options {
446446
libs: Vec::new(),
447447
unstable_features: UnstableFeatures::Disallow,
448448
debug_assertions: true,
449-
debug_prefix_map: None,
449+
debug_prefix_map: Vec::new(),
450450
actually_rustdoc: false,
451451
}
452452
}
@@ -803,7 +803,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
803803
"optimize with possible levels 0-3, s, or z"),
804804
debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
805805
"explicitly enable the cfg(debug_assertions) directive"),
806-
debug_prefix_map: String = ("".to_string(), parse_string, [TRACKED],
806+
debug_prefix_map: Vec<String> = (vec![], parse_string_push, [TRACKED],
807807
"remap OLD to NEW in debug info (OLD=NEW)"),
808808
inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED],
809809
"set the inlining threshold for"),
@@ -1428,18 +1428,16 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14281428
};
14291429
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
14301430

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

14441442
let debuginfo = if matches.opt_present("g") {
14451443
if cg.debuginfo.is_some() {
@@ -1733,7 +1731,7 @@ mod dep_tracking {
17331731
impl_dep_tracking_hash_via_hash!(Option<bool>);
17341732
impl_dep_tracking_hash_via_hash!(Option<usize>);
17351733
impl_dep_tracking_hash_via_hash!(Option<String>);
1736-
impl_dep_tracking_hash_via_hash!(Option<(String, String)>);
1734+
impl_dep_tracking_hash_via_hash!(Vec<(String, String)>);
17371735
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
17381736
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
17391737
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);

src/librustc_trans/debuginfo/metadata.rs

+31-12
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,24 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
657657
metadata
658658
}
659659

660-
fn remap_path(sess: &Session, path: &str) -> String {
661-
for (old, new) in sess.opts.debug_prefix_map.clone() {
660+
fn remap_path(sess: &Session, dir: Option<&str>, remap_dir: Option<&str>, path: &str) -> String {
661+
for &(ref old, ref new) in &sess.opts.debug_prefix_map {
662+
// If `old` is not absolute and we've been given a dir, add the dir to make
663+
// it absolute. Otherwise use `old` as-is.
664+
let old = if dir.is_none() || Path::new(old).is_absolute() {
665+
old.to_string()
666+
} else {
667+
format!("{}/{}", dir.unwrap(), old)
668+
};
662669
if path.starts_with(&old) {
663-
return new + &path[old.len()..];
670+
// Likewise, add `remap_dir` to new if we have one and `new` isn't absolute.
671+
let mut ret = if remap_dir.is_none() || Path::new(new).is_absolute() {
672+
new.to_string()
673+
} else {
674+
format!("{}/{}", remap_dir.unwrap(), new)
675+
};
676+
ret.push_str(&path[old.len()..]);
677+
return ret;
664678
}
665679
}
666680
path.to_string()
@@ -669,18 +683,23 @@ fn remap_path(sess: &Session, path: &str) -> String {
669683
pub fn file_metadata(cx: &CrateContext, path: &str, full_path: &Option<String>) -> DIFile {
670684
// FIXME (#9639): This needs to handle non-utf8 paths
671685
let work_dir = cx.sess().working_dir.to_str().unwrap();
672-
let file_name =
673-
full_path.as_ref().map(|p| p.as_str()).unwrap_or_else(|| {
674-
if path.starts_with(work_dir) {
686+
let sess = cx.sess();
687+
let remap_dir = remap_path(sess, None, None, work_dir);
688+
689+
let remap_file_name = match full_path {
690+
&None => {
691+
// Huh: return a relative path?
692+
let p = if path.starts_with(work_dir) {
675693
&path[work_dir.len() + 1..path.len()]
676694
} else {
677695
path
678-
}
679-
});
696+
};
697+
remap_path(sess, None, None, p)
698+
},
699+
// Huh: return an absolute path?
700+
&Some(ref full) => remap_path(sess, Some(work_dir), Some(&remap_dir), full),
701+
};
680702

681-
let sess = cx.sess();
682-
let remap_file_name = remap_path(sess, file_name);
683-
let remap_dir = remap_path(sess, work_dir);
684703
file_metadata_(cx, path, &remap_file_name, &remap_dir)
685704
}
686705

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

796-
let work_dir = remap_path(sess, work_dir);
815+
let work_dir = remap_path(sess, None, None, work_dir);
797816

798817
debug!("compile_unit_metadata: {:?}", compile_unit_name);
799818
let producer = format!("rustc version {}",

0 commit comments

Comments
 (0)