Skip to content

Commit 1e593be

Browse files
committed
Remap only source files in the command line
1 parent d45f877 commit 1e593be

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

src/librustc_driver/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {
980980
state.expanded_crate.unwrap(),
981981
state.analysis.unwrap(),
982982
state.crate_name.unwrap(),
983+
state.input,
983984
None,
984985
DumpHandler::new(state.out_dir,
985986
state.crate_name.unwrap()))

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
2626
use rustc::hir::def::Def as HirDef;
2727
use rustc::hir::def_id::DefId;
28+
use rustc::session::config::Input;
2829
use rustc::ty::{self, TyCtxt};
2930
use rustc_data_structures::fx::FxHashSet;
3031

3132
use std::path::Path;
3233
use std::env;
33-
use std::fs;
3434

3535
use syntax::ast::{self, Attribute, NodeId, PatKind, CRATE_NODE_ID};
3636
use syntax::parse::token;
@@ -173,20 +173,13 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
173173
self.dumper.crate_prelude(data);
174174
}
175175

176-
pub fn dump_compilation_options(&mut self, crate_name: &str) {
177-
// Apply possible `remap-path-prefix` remapping to the raw command
178-
let command = {
179-
let mapping = self.tcx.sess.source_map().path_mapping();
180-
let remap_arg = |x: &str| -> String {
181-
match fs::canonicalize(x) {
182-
Ok(path) => mapping.map_prefix(path).0.to_str().unwrap().to_owned(),
183-
Err(_) => x.to_owned(), // Probably not a path, ignore
184-
}
185-
};
186-
176+
pub fn dump_compilation_options(&mut self, input: &Input, crate_name: &str) {
177+
// Apply possible `remap-path-prefix` remapping to the input source file
178+
// (and don't include remapping args anymore)
179+
let (program, arguments) = {
187180
let remap_arg_indices = {
188181
let mut indices = FxHashSet();
189-
// rustc args are guaranteed to be valid UTF-8 (checked early)
182+
// Args are guaranteed to be valid UTF-8 (checked early)
190183
for (i, e) in env::args().enumerate() {
191184
if e.starts_with("--remap-path-prefix=") {
192185
indices.insert(i);
@@ -198,26 +191,30 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
198191
indices
199192
};
200193

201-
let args = env::args()
194+
let mut args = env::args()
202195
.enumerate()
203196
.filter(|(i, _)| !remap_arg_indices.contains(i))
204-
.map(|(_, elem)| {
205-
let mut arg = elem.splitn(2, '=');
206-
match (arg.next(), arg.next()) {
207-
// Apart from `--remap...`, in `a=b` args usually only
208-
// `b` is a path (e.g. `--extern some_crate=/path/to..`)
209-
(Some(a), Some(b)) => format!("{}={}", a, remap_arg(b)),
210-
(Some(a), _) => remap_arg(a),
211-
_ => unreachable!(),
197+
.map(|(_, arg)| {
198+
match input {
199+
Input::File(ref path) if path == Path::new(&arg) => {
200+
let mapped = &self.tcx.sess.local_crate_source_file;
201+
mapped
202+
.as_ref()
203+
.unwrap()
204+
.to_string_lossy()
205+
.into()
206+
},
207+
_ => arg,
212208
}
213-
}).collect::<Vec<_>>();
209+
});
214210

215-
args.as_slice().join(" ")
211+
(args.next().unwrap(), args.collect())
216212
};
217213

218214
let data = CompilationOptions {
219215
directory: self.tcx.sess.working_dir.0.clone(),
220-
command,
216+
program,
217+
arguments,
221218
output: self.save_ctxt.compilation_output(crate_name),
222219
};
223220

src/librustc_save_analysis/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc::hir::def::Def as HirDef;
4646
use rustc::hir::Node;
4747
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
4848
use rustc::middle::cstore::ExternCrate;
49-
use rustc::session::config::{CrateType, OutputType};
49+
use rustc::session::config::{CrateType, Input, OutputType};
5050
use rustc::ty::{self, TyCtxt};
5151
use rustc_typeck::hir_ty_to_ty;
5252
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
@@ -74,7 +74,7 @@ use span_utils::SpanUtils;
7474

7575
use rls_data::config::Config;
7676
use rls_data::{
77-
CrateSource, Def, DefKind, ExternalCrateData, GlobalCrateId, Impl, ImplKind, MacroRef, Ref,
77+
Def, DefKind, ExternalCrateData, GlobalCrateId, Impl, ImplKind, MacroRef, Ref,
7878
RefKind, Relation, RelationKind, SpanData,
7979
};
8080

@@ -143,11 +143,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
143143
continue;
144144
}
145145
};
146-
let src = self.tcx.used_crate_source(n);
147146
let lo_loc = self.span_utils.sess.source_map().lookup_char_pos(span.lo());
148-
let map_prefix = |path: &PathBuf| -> PathBuf {
149-
self.tcx.sess.source_map().path_mapping().map_prefix(path.to_owned()).0
150-
};
151147

152148
result.push(ExternalCrateData {
153149
// FIXME: change file_name field to PathBuf in rls-data
@@ -158,11 +154,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
158154
name: self.tcx.crate_name(n).to_string(),
159155
disambiguator: self.tcx.crate_disambiguator(n).to_fingerprint().as_value(),
160156
},
161-
source: CrateSource {
162-
dylib: src.dylib.as_ref().map(|(path, _)| map_prefix(path)),
163-
rlib: src.rlib.as_ref().map(|(path, _)| map_prefix(path)),
164-
rmeta: src.rmeta.as_ref().map(|(path, _)| map_prefix(path)),
165-
}
166157
});
167158
}
168159

@@ -1046,6 +1037,7 @@ pub trait SaveHandler {
10461037
save_ctxt: SaveContext<'l, 'tcx>,
10471038
krate: &ast::Crate,
10481039
cratename: &str,
1040+
input: &'l Input,
10491041
);
10501042
}
10511043

@@ -1111,13 +1103,14 @@ impl<'a> SaveHandler for DumpHandler<'a> {
11111103
save_ctxt: SaveContext<'l, 'tcx>,
11121104
krate: &ast::Crate,
11131105
cratename: &str,
1106+
input: &'l Input,
11141107
) {
11151108
let output = &mut self.output_file(&save_ctxt);
11161109
let mut dumper = JsonDumper::new(output, save_ctxt.config.clone());
11171110
let mut visitor = DumpVisitor::new(save_ctxt, &mut dumper);
11181111

11191112
visitor.dump_crate_info(cratename, krate);
1120-
visitor.dump_compilation_options(cratename);
1113+
visitor.dump_compilation_options(input, cratename);
11211114
visit::walk_crate(&mut visitor, krate);
11221115
}
11231116
}
@@ -1133,6 +1126,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
11331126
save_ctxt: SaveContext<'l, 'tcx>,
11341127
krate: &ast::Crate,
11351128
cratename: &str,
1129+
input: &'l Input,
11361130
) {
11371131
// We're using the JsonDumper here because it has the format of the
11381132
// save-analysis results that we will pass to the callback. IOW, we are
@@ -1143,7 +1137,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
11431137
let mut visitor = DumpVisitor::new(save_ctxt, &mut dumper);
11441138

11451139
visitor.dump_crate_info(cratename, krate);
1146-
visitor.dump_compilation_options(cratename);
1140+
visitor.dump_compilation_options(input, cratename);
11471141
visit::walk_crate(&mut visitor, krate);
11481142
}
11491143
}
@@ -1153,6 +1147,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11531147
krate: &ast::Crate,
11541148
analysis: &'l ty::CrateAnalysis,
11551149
cratename: &str,
1150+
input: &'l Input,
11561151
config: Option<Config>,
11571152
mut handler: H,
11581153
) {
@@ -1170,7 +1165,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11701165
impl_counter: Cell::new(0),
11711166
};
11721167

1173-
handler.save(save_ctxt, krate, cratename)
1168+
handler.save(save_ctxt, krate, cratename, input)
11741169
})
11751170
}
11761171

0 commit comments

Comments
 (0)