@@ -23,6 +23,7 @@ extern crate rustc;
23
23
#[ macro_use]
24
24
extern crate log;
25
25
extern crate rustc_data_structures;
26
+ extern crate rustc_codegen_utils;
26
27
extern crate rustc_serialize;
27
28
extern crate rustc_target;
28
29
extern crate rustc_typeck;
@@ -45,9 +46,10 @@ use rustc::hir::def::Def as HirDef;
45
46
use rustc:: hir:: Node ;
46
47
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
47
48
use rustc:: middle:: cstore:: ExternCrate ;
48
- use rustc:: session:: config:: CrateType ;
49
+ use rustc:: session:: config:: { CrateType , Input , OutputType } ;
49
50
use rustc:: ty:: { self , TyCtxt } ;
50
51
use rustc_typeck:: hir_ty_to_ty;
52
+ use rustc_codegen_utils:: link:: { filename_for_metadata, out_filename} ;
51
53
52
54
use std:: cell:: Cell ;
53
55
use std:: default:: Default ;
@@ -110,6 +112,24 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
110
112
}
111
113
}
112
114
115
+ // Returns path to the compilation output (e.g. libfoo-12345678.rmeta)
116
+ pub fn compilation_output ( & self , crate_name : & str ) -> PathBuf {
117
+ let sess = & self . tcx . sess ;
118
+ // Save-analysis is emitted per whole session, not per each crate type
119
+ let crate_type = sess. crate_types . borrow ( ) [ 0 ] ;
120
+ let outputs = & * self . tcx . output_filenames ( LOCAL_CRATE ) ;
121
+
122
+ if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
123
+ filename_for_metadata ( sess, crate_name, outputs)
124
+ } else if outputs. outputs . should_codegen ( ) {
125
+ out_filename ( sess, crate_type, outputs, crate_name)
126
+ } else {
127
+ // Otherwise it's only a DepInfo, in which case we return early and
128
+ // not even reach the analysis stage.
129
+ unreachable ! ( )
130
+ }
131
+ }
132
+
113
133
// List external crates used by the current crate.
114
134
pub fn get_external_crates ( & self ) -> Vec < ExternalCrateData > {
115
135
let mut result = Vec :: with_capacity ( self . tcx . crates ( ) . len ( ) ) ;
@@ -126,7 +146,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
126
146
result. push ( ExternalCrateData {
127
147
// FIXME: change file_name field to PathBuf in rls-data
128
148
// https://github.com/nrc/rls-data/issues/7
129
- file_name : self . span_utils . make_path_string ( & lo_loc. file . name ) ,
149
+ file_name : self . span_utils . make_filename_string ( & lo_loc. file ) ,
130
150
num : n. as_u32 ( ) ,
131
151
id : GlobalCrateId {
132
152
name : self . tcx . crate_name ( n) . to_string ( ) ,
@@ -1015,6 +1035,7 @@ pub trait SaveHandler {
1015
1035
save_ctxt : SaveContext < ' l , ' tcx > ,
1016
1036
krate : & ast:: Crate ,
1017
1037
cratename : & str ,
1038
+ input : & ' l Input ,
1018
1039
) ;
1019
1040
}
1020
1041
@@ -1080,12 +1101,14 @@ impl<'a> SaveHandler for DumpHandler<'a> {
1080
1101
save_ctxt : SaveContext < ' l , ' tcx > ,
1081
1102
krate : & ast:: Crate ,
1082
1103
cratename : & str ,
1104
+ input : & ' l Input ,
1083
1105
) {
1084
1106
let output = & mut self . output_file ( & save_ctxt) ;
1085
1107
let mut dumper = JsonDumper :: new ( output, save_ctxt. config . clone ( ) ) ;
1086
1108
let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
1087
1109
1088
1110
visitor. dump_crate_info ( cratename, krate) ;
1111
+ visitor. dump_compilation_options ( input, cratename) ;
1089
1112
visit:: walk_crate ( & mut visitor, krate) ;
1090
1113
}
1091
1114
}
@@ -1101,6 +1124,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
1101
1124
save_ctxt : SaveContext < ' l , ' tcx > ,
1102
1125
krate : & ast:: Crate ,
1103
1126
cratename : & str ,
1127
+ input : & ' l Input ,
1104
1128
) {
1105
1129
// We're using the JsonDumper here because it has the format of the
1106
1130
// save-analysis results that we will pass to the callback. IOW, we are
@@ -1111,6 +1135,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
1111
1135
let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
1112
1136
1113
1137
visitor. dump_crate_info ( cratename, krate) ;
1138
+ visitor. dump_compilation_options ( input, cratename) ;
1114
1139
visit:: walk_crate ( & mut visitor, krate) ;
1115
1140
}
1116
1141
}
@@ -1120,6 +1145,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
1120
1145
krate : & ast:: Crate ,
1121
1146
analysis : & ' l ty:: CrateAnalysis ,
1122
1147
cratename : & str ,
1148
+ input : & ' l Input ,
1123
1149
config : Option < Config > ,
1124
1150
mut handler : H ,
1125
1151
) {
@@ -1137,7 +1163,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
1137
1163
impl_counter : Cell :: new ( 0 ) ,
1138
1164
} ;
1139
1165
1140
- handler. save ( save_ctxt, krate, cratename)
1166
+ handler. save ( save_ctxt, krate, cratename, input )
1141
1167
} )
1142
1168
}
1143
1169
0 commit comments