@@ -23,6 +23,7 @@ extern crate rustc;
2323#[ macro_use]
2424extern crate log;
2525extern crate rustc_data_structures;
26+ extern crate rustc_codegen_utils;
2627extern crate rustc_serialize;
2728extern crate rustc_target;
2829extern crate rustc_typeck;
@@ -45,9 +46,10 @@ use rustc::hir::def::Def as HirDef;
4546use rustc:: hir:: Node ;
4647use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
4748use rustc:: middle:: cstore:: ExternCrate ;
48- use rustc:: session:: config:: CrateType ;
49+ use rustc:: session:: config:: { CrateType , Input , OutputType } ;
4950use rustc:: ty:: { self , TyCtxt } ;
5051use rustc_typeck:: hir_ty_to_ty;
52+ use rustc_codegen_utils:: link:: { filename_for_metadata, out_filename} ;
5153
5254use std:: cell:: Cell ;
5355use std:: default:: Default ;
@@ -110,6 +112,24 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
110112 }
111113 }
112114
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+
113133 // List external crates used by the current crate.
114134 pub fn get_external_crates ( & self ) -> Vec < ExternalCrateData > {
115135 let mut result = Vec :: with_capacity ( self . tcx . crates ( ) . len ( ) ) ;
@@ -126,7 +146,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
126146 result. push ( ExternalCrateData {
127147 // FIXME: change file_name field to PathBuf in rls-data
128148 // 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 ) ,
130150 num : n. as_u32 ( ) ,
131151 id : GlobalCrateId {
132152 name : self . tcx . crate_name ( n) . to_string ( ) ,
@@ -1015,6 +1035,7 @@ pub trait SaveHandler {
10151035 save_ctxt : SaveContext < ' l , ' tcx > ,
10161036 krate : & ast:: Crate ,
10171037 cratename : & str ,
1038+ input : & ' l Input ,
10181039 ) ;
10191040}
10201041
@@ -1080,12 +1101,14 @@ impl<'a> SaveHandler for DumpHandler<'a> {
10801101 save_ctxt : SaveContext < ' l , ' tcx > ,
10811102 krate : & ast:: Crate ,
10821103 cratename : & str ,
1104+ input : & ' l Input ,
10831105 ) {
10841106 let output = & mut self . output_file ( & save_ctxt) ;
10851107 let mut dumper = JsonDumper :: new ( output, save_ctxt. config . clone ( ) ) ;
10861108 let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
10871109
10881110 visitor. dump_crate_info ( cratename, krate) ;
1111+ visitor. dump_compilation_options ( input, cratename) ;
10891112 visit:: walk_crate ( & mut visitor, krate) ;
10901113 }
10911114}
@@ -1101,6 +1124,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
11011124 save_ctxt : SaveContext < ' l , ' tcx > ,
11021125 krate : & ast:: Crate ,
11031126 cratename : & str ,
1127+ input : & ' l Input ,
11041128 ) {
11051129 // We're using the JsonDumper here because it has the format of the
11061130 // save-analysis results that we will pass to the callback. IOW, we are
@@ -1111,6 +1135,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
11111135 let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
11121136
11131137 visitor. dump_crate_info ( cratename, krate) ;
1138+ visitor. dump_compilation_options ( input, cratename) ;
11141139 visit:: walk_crate ( & mut visitor, krate) ;
11151140 }
11161141}
@@ -1120,6 +1145,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11201145 krate : & ast:: Crate ,
11211146 analysis : & ' l ty:: CrateAnalysis ,
11221147 cratename : & str ,
1148+ input : & ' l Input ,
11231149 config : Option < Config > ,
11241150 mut handler : H ,
11251151) {
@@ -1137,7 +1163,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11371163 impl_counter : Cell :: new ( 0 ) ,
11381164 } ;
11391165
1140- handler. save ( save_ctxt, krate, cratename)
1166+ handler. save ( save_ctxt, krate, cratename, input )
11411167 } )
11421168}
11431169
0 commit comments