@@ -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 , 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 ;
@@ -111,6 +113,24 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
111
113
}
112
114
}
113
115
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
+
114
134
// List external crates used by the current crate.
115
135
pub fn get_external_crates ( & self ) -> Vec < ExternalCrateData > {
116
136
let mut result = Vec :: with_capacity ( self . tcx . crates ( ) . len ( ) ) ;
@@ -139,15 +159,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
139
159
disambiguator : self . tcx . crate_disambiguator ( n) . to_fingerprint ( ) . as_value ( ) ,
140
160
} ,
141
161
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) ) ,
151
165
}
152
166
} ) ;
153
167
}
@@ -1103,7 +1117,7 @@ impl<'a> SaveHandler for DumpHandler<'a> {
1103
1117
let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
1104
1118
1105
1119
visitor. dump_crate_info ( cratename, krate) ;
1106
- visitor. dump_compilation_options ( ) ;
1120
+ visitor. dump_compilation_options ( cratename ) ;
1107
1121
visit:: walk_crate ( & mut visitor, krate) ;
1108
1122
}
1109
1123
}
@@ -1129,7 +1143,7 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
1129
1143
let mut visitor = DumpVisitor :: new ( save_ctxt, & mut dumper) ;
1130
1144
1131
1145
visitor. dump_crate_info ( cratename, krate) ;
1132
- visitor. dump_compilation_options ( ) ;
1146
+ visitor. dump_compilation_options ( cratename ) ;
1133
1147
visit:: walk_crate ( & mut visitor, krate) ;
1134
1148
}
1135
1149
}
0 commit comments