From 6637340c2860344bacd1554fc025f3d90c80a602 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 19 Dec 2011 03:42:58 -0500 Subject: [PATCH] Properly calculate base working dir for compile units. --- src/comp/driver/rustc.rs | 10 +++++----- src/comp/driver/session.rs | 6 +++++- src/comp/middle/debuginfo.rs | 13 +++++++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 35e450244ac..8e293e98f0d 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -489,7 +489,7 @@ fn build_session_options(match: getopts::match) ret sopts; } -fn build_session(sopts: @session::options) -> session::session { +fn build_session(sopts: @session::options, input: str) -> session::session { let target_cfg = build_target_config(sopts); let cstore = cstore::mk_cstore(); let filesearch = filesearch::mk_filesearch( @@ -498,7 +498,7 @@ fn build_session(sopts: @session::options) -> session::session { sopts.addl_lib_search_paths); ret session::session(target_cfg, sopts, cstore, @{cm: codemap::new_codemap(), mutable next_id: 1}, - none, 0u, filesearch, false); + none, 0u, filesearch, false, fs::dirname(input)); } fn parse_pretty(sess: session::session, &&name: str) -> pp_mode { @@ -644,7 +644,7 @@ fn main(args: [str]) { }; let sopts = build_session_options(match); - let sess = build_session(sopts); + let sess = build_session(sopts, ifile); let odir = getopts::opt_maybe_str(match, "out-dir"); let ofile = getopts::opt_maybe_str(match, "o"); let cfg = build_configuration(sess, binary, ifile); @@ -676,7 +676,7 @@ fn test_switch_implies_cfg_test() { ok(m) { m } }; let sessopts = build_session_options(match); - let sess = build_session(sessopts); + let sess = build_session(sessopts, ""); let cfg = build_configuration(sess, "whatever", "whatever"); assert (attr::contains_name(cfg, "test")); } @@ -690,7 +690,7 @@ fn test_switch_implies_cfg_test_unless_cfg_test() { ok(m) { m } }; let sessopts = build_session_options(match); - let sess = build_session(sessopts); + let sess = build_session(sessopts, ""); let cfg = build_configuration(sess, "whatever", "whatever"); let test_items = attr::find_meta_items_by_name(cfg, "test"); assert (vec::len(test_items) == 1u); diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 6645d5d6894..1bedbf87f7e 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -60,7 +60,8 @@ mutable main_fn: option::t, mutable err_count: uint, filesearch: filesearch::filesearch, - mutable building_library: bool) { + mutable building_library: bool, + working_dir: str) { fn get_targ_cfg() -> @config { ret targ_cfg; } fn get_opts() -> @options { ret opts; } fn get_cstore() -> metadata::cstore::cstore { cstore } @@ -123,6 +124,9 @@ fn building_library() -> bool { building_library } fn set_building_library(crate: @ast::crate) { building_library = session::building_library(opts.crate_type, crate); } + fn get_working_dir() -> str { + ret working_dir; + } } fn building_library(req_crate_type: crate_type, crate: @ast::crate) -> bool { diff --git a/src/comp/middle/debuginfo.rs b/src/comp/middle/debuginfo.rs index 7460244d479..c11f65dc34f 100644 --- a/src/comp/middle/debuginfo.rs +++ b/src/comp/middle/debuginfo.rs @@ -162,13 +162,18 @@ fn create_compile_unit(cx: @crate_ctxt, full_path: str) option::none. {} } - let fname = fs::basename(full_path); - let path = fs::dirname(full_path); + let work_dir = cx.sess.get_working_dir(); + let file_path = if str::starts_with(full_path, work_dir) { + str::slice(full_path, str::byte_len(work_dir), + str::byte_len(full_path)) + } else { + full_path + }; let unit_metadata = [lltag(tg), llunused(), lli32(DW_LANG_RUST), - llstr(fname), - llstr(path), + llstr(file_path), + llstr(work_dir), llstr(#env["CFG_VERSION"]), lli1(false), // main compile unit lli1(cx.sess.get_opts().optimize != 0u), -- GitLab