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