23
23
#![ feature( test) ]
24
24
#![ feature( vec_remove_item) ]
25
25
#![ feature( entry_and_modify) ]
26
+ #![ feature( dyn_trait) ]
26
27
27
28
extern crate arena;
28
29
extern crate getopts;
@@ -48,6 +49,8 @@ extern crate tempdir;
48
49
49
50
extern crate serialize as rustc_serialize; // used by deriving
50
51
52
+ use errors:: ColorConfig ;
53
+
51
54
use std:: collections:: { BTreeMap , BTreeSet } ;
52
55
use std:: default:: Default ;
53
56
use std:: env;
@@ -274,6 +277,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
274
277
"edition to use when compiling rust code (default: 2015)" ,
275
278
"EDITION" )
276
279
} ) ,
280
+ unstable( "color" , |o| {
281
+ o. optopt( "" ,
282
+ "color" ,
283
+ "Configure coloring of output:
284
+ auto = colorize, if output goes to a tty (default);
285
+ always = always colorize output;
286
+ never = never colorize output" ,
287
+ "auto|always|never" )
288
+ } ) ,
289
+ unstable( "error-format" , |o| {
290
+ o. optopt( "" ,
291
+ "error-format" ,
292
+ "How errors and other messages are produced" ,
293
+ "human|json|short" )
294
+ } ) ,
277
295
]
278
296
}
279
297
@@ -358,9 +376,33 @@ pub fn main_args(args: &[String]) -> isize {
358
376
}
359
377
let input = & matches. free [ 0 ] ;
360
378
379
+ let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
380
+ Some ( "auto" ) => ColorConfig :: Auto ,
381
+ Some ( "always" ) => ColorConfig :: Always ,
382
+ Some ( "never" ) => ColorConfig :: Never ,
383
+ None => ColorConfig :: Auto ,
384
+ Some ( arg) => {
385
+ print_error ( & format ! ( "argument for --color must be `auto`, `always` or `never` \
386
+ (instead was `{}`)", arg) ) ;
387
+ return 1 ;
388
+ }
389
+ } ;
390
+ let error_format = match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
391
+ Some ( "human" ) => ErrorOutputType :: HumanReadable ( color) ,
392
+ Some ( "json" ) => ErrorOutputType :: Json ( false ) ,
393
+ Some ( "pretty-json" ) => ErrorOutputType :: Json ( true ) ,
394
+ Some ( "short" ) => ErrorOutputType :: Short ( color) ,
395
+ None => ErrorOutputType :: HumanReadable ( color) ,
396
+ Some ( arg) => {
397
+ print_error ( & format ! ( "argument for --error-format must be `human`, `json` or \
398
+ `short` (instead was `{}`)", arg) ) ;
399
+ return 1 ;
400
+ }
401
+ } ;
402
+
361
403
let mut libs = SearchPaths :: new ( ) ;
362
404
for s in & matches. opt_strs ( "L" ) {
363
- libs. add_path ( s, ErrorOutputType :: default ( ) ) ;
405
+ libs. add_path ( s, error_format ) ;
364
406
}
365
407
let externs = match parse_externs ( & matches) {
366
408
Ok ( ex) => ex,
@@ -458,7 +500,8 @@ pub fn main_args(args: &[String]) -> isize {
458
500
}
459
501
460
502
let output_format = matches. opt_str ( "w" ) ;
461
- let res = acquire_input ( PathBuf :: from ( input) , externs, edition, & matches, move |out| {
503
+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition, & matches, error_format,
504
+ move |out| {
462
505
let Output { krate, passes, renderinfo } = out;
463
506
info ! ( "going to format" ) ;
464
507
match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -501,13 +544,14 @@ fn acquire_input<R, F>(input: PathBuf,
501
544
externs : Externs ,
502
545
edition : Edition ,
503
546
matches : & getopts:: Matches ,
547
+ error_format : ErrorOutputType ,
504
548
f : F )
505
549
-> Result < R , String >
506
550
where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
507
551
match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
508
- Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, matches, f) ) ,
552
+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, matches, error_format , f) ) ,
509
553
Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
510
- None => Ok ( rust_input ( input, externs, edition, matches, f) )
554
+ None => Ok ( rust_input ( input, externs, edition, matches, error_format , f) )
511
555
}
512
556
}
513
557
@@ -537,6 +581,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
537
581
externs : Externs ,
538
582
edition : Edition ,
539
583
matches : & getopts:: Matches ,
584
+ error_format : ErrorOutputType ,
540
585
f : F ) -> R
541
586
where R : ' static + Send ,
542
587
F : ' static + Send + FnOnce ( Output ) -> R
@@ -589,7 +634,7 @@ where R: 'static + Send,
589
634
let ( mut krate, renderinfo) =
590
635
core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
591
636
display_warnings, crate_name. clone ( ) ,
592
- force_unstable_if_unmarked, edition) ;
637
+ force_unstable_if_unmarked, edition, error_format ) ;
593
638
594
639
info ! ( "finished with rustc" ) ;
595
640
0 commit comments