@@ -288,7 +288,7 @@ macro_rules! options {
288
288
$struct_name { $( $opt: $init) ,* }
289
289
}
290
290
291
- pub fn $buildfn( matches: & getopts:: Matches ) -> $struct_name
291
+ pub fn $buildfn( matches: & getopts:: Matches , color : ColorConfig ) -> $struct_name
292
292
{
293
293
let mut op = $defaultfn( ) ;
294
294
for option in matches. opt_strs( $prefix) {
@@ -302,20 +302,20 @@ macro_rules! options {
302
302
if !setter( & mut op, value) {
303
303
match ( value, opt_type_desc) {
304
304
( Some ( ..) , None ) => {
305
- early_error( & format!( "{} option `{}` takes no \
306
- value", $outputname, key) )
305
+ early_error( color , & format!( "{} option `{}` takes no \
306
+ value", $outputname, key) )
307
307
}
308
308
( None , Some ( type_desc) ) => {
309
- early_error( & format!( "{0} option `{1}` requires \
310
- {2} ({3} {1}=<value>)",
311
- $outputname, key,
312
- type_desc, $prefix) )
309
+ early_error( color , & format!( "{0} option `{1}` requires \
310
+ {2} ({3} {1}=<value>)",
311
+ $outputname, key,
312
+ type_desc, $prefix) )
313
313
}
314
314
( Some ( value) , Some ( type_desc) ) => {
315
- early_error( & format!( "incorrect value `{}` for {} \
316
- option `{}` - {} was expected",
317
- value, $outputname,
318
- key, type_desc) )
315
+ early_error( color , & format!( "incorrect value `{}` for {} \
316
+ option `{}` - {} was expected",
317
+ value, $outputname,
318
+ key, type_desc) )
319
319
}
320
320
( None , None ) => unreachable!( )
321
321
}
@@ -324,8 +324,8 @@ macro_rules! options {
324
324
break ;
325
325
}
326
326
if !found {
327
- early_error( & format!( "unknown {} option: `{}`" ,
328
- $outputname, key) ) ;
327
+ early_error( color , & format!( "unknown {} option: `{}`" ,
328
+ $outputname, key) ) ;
329
329
}
330
330
}
331
331
return op;
@@ -850,9 +850,23 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
850
850
}
851
851
852
852
pub fn build_session_options ( matches : & getopts:: Matches ) -> Options {
853
+ let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
854
+ Some ( "auto" ) => Auto ,
855
+ Some ( "always" ) => Always ,
856
+ Some ( "never" ) => Never ,
857
+
858
+ None => Auto ,
859
+
860
+ Some ( arg) => {
861
+ early_error ( Auto , & format ! ( "argument for --color must be auto, always \
862
+ or never (instead was `{}`)",
863
+ arg) )
864
+ }
865
+ } ;
866
+
853
867
let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
854
868
let crate_types = parse_crate_types_from_list ( unparsed_crate_types)
855
- . unwrap_or_else ( |e| early_error ( & e[ ..] ) ) ;
869
+ . unwrap_or_else ( |e| early_error ( color , & e[ ..] ) ) ;
856
870
857
871
let mut lint_opts = vec ! ( ) ;
858
872
let mut describe_lints = false ;
@@ -869,11 +883,11 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
869
883
870
884
let lint_cap = matches. opt_str ( "cap-lints" ) . map ( |cap| {
871
885
lint:: Level :: from_str ( & cap) . unwrap_or_else ( || {
872
- early_error ( & format ! ( "unknown lint level: `{}`" , cap) )
886
+ early_error ( color , & format ! ( "unknown lint level: `{}`" , cap) )
873
887
} )
874
888
} ) ;
875
889
876
- let debugging_opts = build_debugging_options ( matches) ;
890
+ let debugging_opts = build_debugging_options ( matches, color ) ;
877
891
878
892
let parse_only = debugging_opts. parse_only ;
879
893
let no_trans = debugging_opts. no_trans ;
@@ -897,8 +911,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
897
911
"link" => OutputTypeExe ,
898
912
"dep-info" => OutputTypeDepInfo ,
899
913
_ => {
900
- early_error ( & format ! ( "unknown emission type: `{}`" ,
901
- part) )
914
+ early_error ( color , & format ! ( "unknown emission type: `{}`" ,
915
+ part) )
902
916
}
903
917
} ;
904
918
output_types. push ( output_type)
@@ -911,15 +925,15 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
911
925
output_types. push ( OutputTypeExe ) ;
912
926
}
913
927
914
- let cg = build_codegen_options ( matches) ;
928
+ let cg = build_codegen_options ( matches, color ) ;
915
929
916
930
let sysroot_opt = matches. opt_str ( "sysroot" ) . map ( |m| PathBuf :: from ( & m) ) ;
917
931
let target = matches. opt_str ( "target" ) . unwrap_or (
918
932
host_triple ( ) . to_string ( ) ) ;
919
933
let opt_level = {
920
934
if matches. opt_present ( "O" ) {
921
935
if cg. opt_level . is_some ( ) {
922
- early_error ( "-O and -C opt-level both provided" ) ;
936
+ early_error ( color , "-O and -C opt-level both provided" ) ;
923
937
}
924
938
Default
925
939
} else {
@@ -930,9 +944,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
930
944
Some ( 2 ) => Default ,
931
945
Some ( 3 ) => Aggressive ,
932
946
Some ( arg) => {
933
- early_error ( & format ! ( "optimization level needs to be \
934
- between 0-3 (instead was `{}`)",
935
- arg) ) ;
947
+ early_error ( color , & format ! ( "optimization level needs to be \
948
+ between 0-3 (instead was `{}`)",
949
+ arg) ) ;
936
950
}
937
951
}
938
952
}
@@ -941,7 +955,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
941
955
let gc = debugging_opts. gc ;
942
956
let debuginfo = if matches. opt_present ( "g" ) {
943
957
if cg. debuginfo . is_some ( ) {
944
- early_error ( "-g and -C debuginfo both provided" ) ;
958
+ early_error ( color , "-g and -C debuginfo both provided" ) ;
945
959
}
946
960
FullDebugInfo
947
961
} else {
@@ -950,16 +964,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
950
964
Some ( 1 ) => LimitedDebugInfo ,
951
965
Some ( 2 ) => FullDebugInfo ,
952
966
Some ( arg) => {
953
- early_error ( & format ! ( "debug info level needs to be between \
954
- 0-2 (instead was `{}`)",
955
- arg) ) ;
967
+ early_error ( color , & format ! ( "debug info level needs to be between \
968
+ 0-2 (instead was `{}`)",
969
+ arg) ) ;
956
970
}
957
971
}
958
972
} ;
959
973
960
974
let mut search_paths = SearchPaths :: new ( ) ;
961
975
for s in & matches. opt_strs ( "L" ) {
962
- search_paths. add_path ( & s[ ..] ) ;
976
+ search_paths. add_path ( & s[ ..] , color ) ;
963
977
}
964
978
965
979
let libs = matches. opt_strs ( "l" ) . into_iter ( ) . map ( |s| {
@@ -971,9 +985,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
971
985
( Some ( name) , "framework" ) => ( name, cstore:: NativeFramework ) ,
972
986
( Some ( name) , "static" ) => ( name, cstore:: NativeStatic ) ,
973
987
( _, s) => {
974
- early_error ( & format ! ( "unknown library kind `{}`, expected \
975
- one of dylib, framework, or static",
976
- s) ) ;
988
+ early_error ( color , & format ! ( "unknown library kind `{}`, expected \
989
+ one of dylib, framework, or static",
990
+ s) ) ;
977
991
}
978
992
} ;
979
993
( name. to_string ( ) , kind)
@@ -989,40 +1003,26 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
989
1003
"file-names" => PrintRequest :: FileNames ,
990
1004
"sysroot" => PrintRequest :: Sysroot ,
991
1005
req => {
992
- early_error ( & format ! ( "unknown print request `{}`" , req) )
1006
+ early_error ( color , & format ! ( "unknown print request `{}`" , req) )
993
1007
}
994
1008
}
995
1009
} ) . collect :: < Vec < _ > > ( ) ;
996
1010
997
1011
if !cg. remark . is_empty ( ) && debuginfo == NoDebugInfo {
998
- early_warn ( "-C remark will not show source locations without \
999
- --debuginfo") ;
1012
+ early_warn ( color , "-C remark will not show source locations without \
1013
+ --debuginfo") ;
1000
1014
}
1001
1015
1002
- let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
1003
- Some ( "auto" ) => Auto ,
1004
- Some ( "always" ) => Always ,
1005
- Some ( "never" ) => Never ,
1006
-
1007
- None => Auto ,
1008
-
1009
- Some ( arg) => {
1010
- early_error ( & format ! ( "argument for --color must be auto, always \
1011
- or never (instead was `{}`)",
1012
- arg) )
1013
- }
1014
- } ;
1015
-
1016
1016
let mut externs = HashMap :: new ( ) ;
1017
1017
for arg in & matches. opt_strs ( "extern" ) {
1018
1018
let mut parts = arg. splitn ( 2 , '=' ) ;
1019
1019
let name = match parts. next ( ) {
1020
1020
Some ( s) => s,
1021
- None => early_error ( "--extern value must not be empty" ) ,
1021
+ None => early_error ( color , "--extern value must not be empty" ) ,
1022
1022
} ;
1023
1023
let location = match parts. next ( ) {
1024
1024
Some ( s) => s,
1025
- None => early_error ( "--extern value must be of the format `foo=bar`" ) ,
1025
+ None => early_error ( color , "--extern value must be of the format `foo=bar`" ) ,
1026
1026
} ;
1027
1027
1028
1028
externs. entry ( name. to_string ( ) ) . or_insert ( vec ! [ ] ) . push ( location. to_string ( ) ) ;
0 commit comments