Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update path remapping #39130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +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: Vec<(String, String)> [TRACKED],
debuginfo: DebugInfoLevel [TRACKED],
lint_opts: Vec<(String, lint::Level)> [TRACKED],
lint_cap: Option<lint::Level> [TRACKED],
Expand Down Expand Up @@ -445,6 +446,7 @@ pub fn basic_options() -> Options {
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
debug_prefix_map: Vec::new(),
actually_rustdoc: false,
}
}
Expand Down Expand Up @@ -801,6 +803,8 @@ 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: 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"),
panic: Option<PanicStrategy> = (None, parse_panic_strategy,
Expand Down Expand Up @@ -1423,6 +1427,18 @@ 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 = 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() {
early_error(error_format, "-g and -C debuginfo both provided");
Expand Down Expand Up @@ -1539,6 +1555,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
libs: libs,
unstable_features: UnstableFeatures::from_environment(),
debug_assertions: debug_assertions,
debug_prefix_map: debug_prefix_map,
actually_rustdoc: false,
},
cfg)
Expand Down Expand Up @@ -1714,6 +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!(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>);
Expand Down
49 changes: 41 additions & 8 deletions src/librustc_trans/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,19 +657,50 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
metadata
}

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) {
// 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()
}

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),
};

file_metadata_(cx, path, file_name, &work_dir)
file_metadata_(cx, path, &remap_file_name, &remap_dir)
}

pub fn unknown_file_metadata(cx: &CrateContext) -> DIFile {
Expand Down Expand Up @@ -759,7 +790,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
debug_context: &CrateDebugContext,
sess: &Session)
-> DIDescriptor {
let work_dir = &sess.working_dir;
let work_dir = sess.working_dir.to_str().unwrap();
let compile_unit_name = match sess.local_crate_source_file {
None => fallback_path(scc),
Some(ref abs_path) => {
Expand All @@ -781,12 +812,14 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
}
};

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

debug!("compile_unit_metadata: {:?}", compile_unit_name);
let producer = format!("rustc version {}",
(option_env!("CFG_VERSION")).expect("CFG_VERSION"));

let compile_unit_name = compile_unit_name.as_ptr();
let work_dir = path2cstr(&work_dir);
let work_dir = CString::new(work_dir).unwrap();
let producer = CString::new(producer).unwrap();
let flags = "\0";
let split_name = "\0";
Expand Down
2 changes: 1 addition & 1 deletion src/llvm