@@ -74,6 +74,7 @@ use rustc::dep_graph::DepGraph;
7474use rustc:: session:: { self , config, Session , build_session, CompileResult } ;
7575use rustc:: session:: config:: { Input , PrintRequest , OutputType , ErrorOutputType } ;
7676use rustc:: session:: config:: nightly_options;
77+ use rustc:: session:: early_error;
7778use rustc:: lint:: Lint ;
7879use rustc:: lint;
7980use rustc_metadata:: loader;
@@ -93,8 +94,6 @@ use std::str;
9394use std:: sync:: { Arc , Mutex } ;
9495use std:: thread;
9596
96- use rustc:: session:: early_error;
97-
9897use syntax:: { ast, json} ;
9998use syntax:: codemap:: { CodeMap , FileLoader , RealFileLoader } ;
10099use syntax:: feature_gate:: { GatedCfg , UnstableFeatures } ;
@@ -131,17 +130,18 @@ pub fn abort_on_err<T>(result: Result<T, usize>, sess: &Session) -> T {
131130 }
132131}
133132
134- pub fn run ( args : Vec < String > ) -> isize {
133+ pub fn run < F > ( run_compiler : F ) -> isize
134+ where F : FnOnce ( ) -> ( CompileResult , Option < Session > ) + Send + ' static
135+ {
135136 monitor ( move || {
136- let ( result, session) = run_compiler ( & args , & mut RustcDefaultCalls ) ;
137+ let ( result, session) = run_compiler ( ) ;
137138 if let Err ( err_count) = result {
138139 if err_count > 0 {
139140 match session {
140141 Some ( sess) => sess. fatal ( & abort_msg ( err_count) ) ,
141142 None => {
142143 let emitter =
143- errors:: emitter:: EmitterWriter :: stderr ( errors:: ColorConfig :: Auto ,
144- None ) ;
144+ errors:: emitter:: EmitterWriter :: stderr ( errors:: ColorConfig :: Auto , None ) ;
145145 let handler = errors:: Handler :: with_emitter ( true , false , Box :: new ( emitter) ) ;
146146 handler. emit ( & MultiSpan :: new ( ) ,
147147 & abort_msg ( err_count) ,
@@ -155,20 +155,15 @@ pub fn run(args: Vec<String>) -> isize {
155155 0
156156}
157157
158- pub fn run_compiler < ' a > ( args : & [ String ] ,
159- callbacks : & mut CompilerCalls < ' a > )
160- -> ( CompileResult , Option < Session > ) {
161- run_compiler_with_file_loader ( args, callbacks, box RealFileLoader )
162- }
163-
164158// Parse args and run the compiler. This is the primary entry point for rustc.
165159// See comments on CompilerCalls below for details about the callbacks argument.
166160// The FileLoader provides a way to load files from sources other than the file system.
167- pub fn run_compiler_with_file_loader < ' a , L > ( args : & [ String ] ,
168- callbacks : & mut CompilerCalls < ' a > ,
169- loader : Box < L > )
170- -> ( CompileResult , Option < Session > )
171- where L : FileLoader + ' static {
161+ pub fn run_compiler < ' a > ( args : & [ String ] ,
162+ callbacks : & mut CompilerCalls < ' a > ,
163+ file_loader : Option < Box < FileLoader + ' static > > ,
164+ emitter_dest : Option < Box < Write + Send > > )
165+ -> ( CompileResult , Option < Session > )
166+ {
172167 macro_rules! do_or_return { ( $expr: expr, $sess: expr) => {
173168 match $expr {
174169 Compilation :: Stop => return ( Ok ( ( ) ) , $sess) ,
@@ -207,13 +202,16 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
207202
208203 let dep_graph = DepGraph :: new ( sopts. build_dep_graph ( ) ) ;
209204 let cstore = Rc :: new ( CStore :: new ( & dep_graph) ) ;
205+
206+ let loader = file_loader. unwrap_or ( box RealFileLoader ) ;
210207 let codemap = Rc :: new ( CodeMap :: with_file_loader ( loader) ) ;
211208 let sess = session:: build_session_with_codemap ( sopts,
212209 & dep_graph,
213210 input_file_path,
214211 descriptions,
215212 cstore. clone ( ) ,
216- codemap) ;
213+ codemap,
214+ emitter_dest) ;
217215 rustc_lint:: register_builtins ( & mut sess. lint_store . borrow_mut ( ) , Some ( & sess) ) ;
218216 let mut cfg = config:: build_configuration ( & sess, cfg) ;
219217 target_features:: add_configuration ( & mut cfg, & sess) ;
@@ -1144,6 +1142,9 @@ pub fn diagnostics_registry() -> errors::registry::Registry {
11441142}
11451143
11461144pub fn main ( ) {
1147- let result = run ( env:: args ( ) . collect ( ) ) ;
1145+ let result = run ( || run_compiler ( & env:: args ( ) . collect :: < Vec < _ > > ( ) ,
1146+ & mut RustcDefaultCalls ,
1147+ None ,
1148+ None ) ) ;
11481149 process:: exit ( result as i32 ) ;
11491150}
0 commit comments