@@ -94,7 +94,9 @@ use std::cmp::max;
94
94
use std:: default:: Default ;
95
95
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
96
96
use std:: env;
97
+ use std:: error:: Error ;
97
98
use std:: ffi:: OsString ;
99
+ use std:: fmt:: { self , Display } ;
98
100
use std:: io:: { self , Read , Write } ;
99
101
use std:: iter:: repeat;
100
102
use std:: mem;
@@ -146,6 +148,12 @@ pub mod target_features {
146
148
}
147
149
}
148
150
151
+ /// Exit status code used for successful compilation and help output.
152
+ pub const EXIT_SUCCESS : isize = 0 ;
153
+
154
+ /// Exit status code used for compilation failures and invalid flags.
155
+ pub const EXIT_FAILURE : isize = 1 ;
156
+
149
157
const BUG_REPORT_URL : & ' static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
150
158
md#bug-reports";
151
159
@@ -178,7 +186,7 @@ pub fn abort_on_err<T>(result: Result<T, CompileIncomplete>, sess: &Session) ->
178
186
pub fn run < F > ( run_compiler : F ) -> isize
179
187
where F : FnOnce ( ) -> ( CompileResult , Option < Session > ) + Send + ' static
180
188
{
181
- monitor ( move || {
189
+ let result = monitor ( move || {
182
190
let ( result, session) = run_compiler ( ) ;
183
191
if let Err ( CompileIncomplete :: Errored ( _) ) = result {
184
192
match session {
@@ -201,7 +209,11 @@ pub fn run<F>(run_compiler: F) -> isize
201
209
}
202
210
}
203
211
} ) ;
204
- 0
212
+
213
+ match result {
214
+ Ok ( ( ) ) => EXIT_SUCCESS ,
215
+ Err ( _) => EXIT_FAILURE ,
216
+ }
205
217
}
206
218
207
219
fn load_backend_from_dylib ( path : & Path ) -> fn ( ) -> Box < dyn CodegenBackend > {
@@ -1625,20 +1637,30 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
1625
1637
}
1626
1638
}
1627
1639
1640
+ #[ derive( Debug ) ]
1641
+ pub struct CompilationFailure ;
1642
+
1643
+ impl Error for CompilationFailure { }
1644
+
1645
+ impl Display for CompilationFailure {
1646
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1647
+ write ! ( f, "compilation had errors" )
1648
+ }
1649
+ }
1650
+
1628
1651
/// Run a procedure which will detect panics in the compiler and print nicer
1629
1652
/// error messages rather than just failing the test.
1630
1653
///
1631
1654
/// The diagnostic emitter yielded to the procedure should be used for reporting
1632
1655
/// errors of the compiler.
1633
- pub fn monitor < F : FnOnce ( ) + Send + ' static > ( f : F ) {
1634
- let result = in_rustc_thread ( move || {
1656
+ pub fn monitor < F : FnOnce ( ) + Send + ' static > ( f : F ) -> Result < ( ) , CompilationFailure > {
1657
+ in_rustc_thread ( move || {
1635
1658
f ( )
1636
- } ) ;
1637
-
1638
- if let Err ( value) = result {
1639
- // Thread panicked without emitting a fatal diagnostic
1640
- if !value. is :: < errors:: FatalErrorMarker > ( ) {
1641
- // Emit a newline
1659
+ } ) . map_err ( |value| {
1660
+ if value. is :: < errors:: FatalErrorMarker > ( ) {
1661
+ CompilationFailure
1662
+ } else {
1663
+ // Thread panicked without emitting a fatal diagnostic
1642
1664
eprintln ! ( "" ) ;
1643
1665
1644
1666
let emitter =
@@ -1677,10 +1699,10 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
1677
1699
& note,
1678
1700
errors:: Level :: Note ) ;
1679
1701
}
1680
- }
1681
1702
1682
- panic:: resume_unwind ( Box :: new ( errors:: FatalErrorMarker ) ) ;
1683
- }
1703
+ panic:: resume_unwind ( Box :: new ( errors:: FatalErrorMarker ) ) ;
1704
+ }
1705
+ } )
1684
1706
}
1685
1707
1686
1708
pub fn diagnostics_registry ( ) -> errors:: registry:: Registry {
0 commit comments