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;
@@ -279,6 +282,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
279
282
"edition to use when compiling rust code (default: 2015)" ,
280
283
"EDITION" )
281
284
} ) ,
285
+ unstable( "color" , |o| {
286
+ o. optopt( "" ,
287
+ "color" ,
288
+ "Configure coloring of output:
289
+ auto = colorize, if output goes to a tty (default);
290
+ always = always colorize output;
291
+ never = never colorize output" ,
292
+ "auto|always|never" )
293
+ } ) ,
294
+ unstable( "error-format" , |o| {
295
+ o. optopt( "" ,
296
+ "error-format" ,
297
+ "How errors and other messages are produced" ,
298
+ "human|json|short" )
299
+ } ) ,
282
300
]
283
301
}
284
302
@@ -363,9 +381,33 @@ pub fn main_args(args: &[String]) -> isize {
363
381
}
364
382
let input = & matches. free [ 0 ] ;
365
383
384
+ let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
385
+ Some ( "auto" ) => ColorConfig :: Auto ,
386
+ Some ( "always" ) => ColorConfig :: Always ,
387
+ Some ( "never" ) => ColorConfig :: Never ,
388
+ None => ColorConfig :: Auto ,
389
+ Some ( arg) => {
390
+ print_error ( & format ! ( "argument for --color must be `auto`, `always` or `never` \
391
+ (instead was `{}`)", arg) ) ;
392
+ return 1 ;
393
+ }
394
+ } ;
395
+ let error_format = match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
396
+ Some ( "human" ) => ErrorOutputType :: HumanReadable ( color) ,
397
+ Some ( "json" ) => ErrorOutputType :: Json ( false ) ,
398
+ Some ( "pretty-json" ) => ErrorOutputType :: Json ( true ) ,
399
+ Some ( "short" ) => ErrorOutputType :: Short ( color) ,
400
+ None => ErrorOutputType :: HumanReadable ( color) ,
401
+ Some ( arg) => {
402
+ print_error ( & format ! ( "argument for --error-format must be `human`, `json` or \
403
+ `short` (instead was `{}`)", arg) ) ;
404
+ return 1 ;
405
+ }
406
+ } ;
407
+
366
408
let mut libs = SearchPaths :: new ( ) ;
367
409
for s in & matches. opt_strs ( "L" ) {
368
- libs. add_path ( s, ErrorOutputType :: default ( ) ) ;
410
+ libs. add_path ( s, error_format ) ;
369
411
}
370
412
let externs = match parse_externs ( & matches) {
371
413
Ok ( ex) => ex,
@@ -465,7 +507,9 @@ pub fn main_args(args: &[String]) -> isize {
465
507
}
466
508
467
509
let output_format = matches. opt_str ( "w" ) ;
468
- let res = acquire_input ( PathBuf :: from ( input) , externs, edition, cg, & matches, move |out| {
510
+
511
+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition, cg, & matches, error_format,
512
+ move |out| {
469
513
let Output { krate, passes, renderinfo } = out;
470
514
info ! ( "going to format" ) ;
471
515
match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -509,13 +553,14 @@ fn acquire_input<R, F>(input: PathBuf,
509
553
edition : Edition ,
510
554
cg : CodegenOptions ,
511
555
matches : & getopts:: Matches ,
556
+ error_format : ErrorOutputType ,
512
557
f : F )
513
558
-> Result < R , String >
514
559
where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
515
560
match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
516
- Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, cg, matches, f) ) ,
561
+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, cg, matches, error_format , f) ) ,
517
562
Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
518
- None => Ok ( rust_input ( input, externs, edition, cg, matches, f) )
563
+ None => Ok ( rust_input ( input, externs, edition, cg, matches, error_format , f) )
519
564
}
520
565
}
521
566
@@ -546,6 +591,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
546
591
edition : Edition ,
547
592
cg : CodegenOptions ,
548
593
matches : & getopts:: Matches ,
594
+ error_format : ErrorOutputType ,
549
595
f : F ) -> R
550
596
where R : ' static + Send ,
551
597
F : ' static + Send + FnOnce ( Output ) -> R
@@ -598,7 +644,7 @@ where R: 'static + Send,
598
644
let ( mut krate, renderinfo) =
599
645
core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
600
646
display_warnings, crate_name. clone ( ) ,
601
- force_unstable_if_unmarked, edition, cg) ;
647
+ force_unstable_if_unmarked, edition, cg, error_format ) ;
602
648
603
649
info ! ( "finished with rustc" ) ;
604
650
0 commit comments