@@ -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 , 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 ;
@@ -111,6 +113,24 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
111113 }
112114 }
113115
116+ // Returns path to the compilation output (e.g. libfoo-12345678.rmeta)
117+ pub fn compilation_output ( & self , crate_name : & str ) -> PathBuf {
118+ let sess = & self . tcx . sess ;
119+ // Save-analysis is emitted per whole session, not per each crate type
120+ let crate_type = sess. crate_types . borrow ( ) [ 0 ] ;
121+ let outputs = & * self . tcx . output_filenames ( LOCAL_CRATE ) ;
122+
123+ if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
124+ filename_for_metadata ( sess, crate_name, outputs)
125+ } else if outputs. outputs . should_codegen ( ) {
126+ out_filename ( sess, crate_type, outputs, crate_name)
127+ } else {
128+ // Otherwise it's only a DepInfo, in which case we return early and
129+ // not even reach the analysis stage.
130+ unreachable ! ( )
131+ }
132+ }
133+
114134 // List external crates used by the current crate.
115135 pub fn get_external_crates ( & self ) -> Vec < ExternalCrateData > {
116136 let mut result = Vec :: with_capacity ( self . tcx . crates ( ) . len ( ) ) ;
@@ -139,15 +159,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
139159 disambiguator : self . tcx . crate_disambiguator ( n) . to_fingerprint ( ) . as_value ( ) ,
140160 } ,
141161 source : CrateSource {
142- dylib : src. dylib . as_ref ( ) . map ( |( ref path, _) |
143- map_prefix ( path) . display ( ) . to_string ( )
144- ) ,
145- rlib : src. rlib . as_ref ( ) . map ( |( ref path, _) |
146- map_prefix ( path) . display ( ) . to_string ( )
147- ) ,
148- rmeta : src. rmeta . as_ref ( ) . map ( |( ref path, _) |
149- map_prefix ( path) . display ( ) . to_string ( )
150- ) ,
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) ) ,
151165 }
152166 } ) ;
153167 }
@@ -1103,7 +1117,7 @@ impl<'a> SaveHandler for DumpHandler<'a> {
11031117 let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
11041118
11051119 visitor. dump_crate_info ( cratename, krate) ;
1106- visitor. dump_compilation_options ( ) ;
1120+ visitor. dump_compilation_options ( cratename ) ;
11071121 visit:: walk_crate ( & mut visitor, krate) ;
11081122 }
11091123}
@@ -1129,7 +1143,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
11291143 let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
11301144
11311145 visitor. dump_crate_info ( cratename, krate) ;
1132- visitor. dump_compilation_options ( ) ;
1146+ visitor. dump_compilation_options ( cratename ) ;
11331147 visit:: walk_crate ( & mut visitor, krate) ;
11341148 }
11351149}
0 commit comments