@@ -46,7 +46,7 @@ pub use syntax::diagnostic;
46
46
47
47
use rustc_trans:: back:: link;
48
48
use rustc:: session:: { config, Session , build_session} ;
49
- use rustc:: session:: config:: Input ;
49
+ use rustc:: session:: config:: { Input , PrintRequest } ;
50
50
use rustc:: lint:: Lint ;
51
51
use rustc:: lint;
52
52
use rustc:: metadata;
@@ -101,6 +101,8 @@ fn run_compiler(args: &[String]) {
101
101
}
102
102
103
103
let sopts = config:: build_session_options ( & matches) ;
104
+ let odir = matches. opt_str ( "out-dir" ) . map ( |o| Path :: new ( o) ) ;
105
+ let ofile = matches. opt_str ( "o" ) . map ( |o| Path :: new ( o) ) ;
104
106
let ( input, input_file_path) = match matches. free . len ( ) {
105
107
0 u => {
106
108
if sopts. describe_lints {
@@ -109,13 +111,10 @@ fn run_compiler(args: &[String]) {
109
111
describe_lints ( & ls, false ) ;
110
112
return ;
111
113
}
112
-
113
114
let sess = build_session ( sopts, None , descriptions) ;
114
- if sess. debugging_opt ( config:: PRINT_SYSROOT ) {
115
- println ! ( "{}" , sess. sysroot( ) . display( ) ) ;
115
+ if print_crate_info ( & sess, None , & odir, & ofile) {
116
116
return ;
117
117
}
118
-
119
118
early_error ( "no input filename given" ) ;
120
119
}
121
120
1 u => {
@@ -133,13 +132,14 @@ fn run_compiler(args: &[String]) {
133
132
134
133
let sess = build_session ( sopts, input_file_path, descriptions) ;
135
134
let cfg = config:: build_configuration ( & sess) ;
136
- let odir = matches. opt_str ( "out-dir" ) . map ( |o| Path :: new ( o) ) ;
137
- let ofile = matches. opt_str ( "o" ) . map ( |o| Path :: new ( o) ) ;
135
+ if print_crate_info ( & sess, Some ( & input) , & odir, & ofile) {
136
+ return
137
+ }
138
138
139
139
let pretty = matches. opt_default ( "pretty" , "normal" ) . map ( |a| {
140
140
pretty:: parse_pretty ( & sess, a. as_slice ( ) )
141
141
} ) ;
142
- match pretty {
142
+ match pretty. into_iter ( ) . next ( ) {
143
143
Some ( ( ppm, opt_uii) ) => {
144
144
pretty:: pretty_print_input ( sess, cfg, & input, ppm, opt_uii, ofile) ;
145
145
return ;
@@ -161,10 +161,6 @@ fn run_compiler(args: &[String]) {
161
161
return ;
162
162
}
163
163
164
- if print_crate_info ( & sess, & input, & odir, & ofile) {
165
- return ;
166
- }
167
-
168
164
driver:: compile_input ( sess, cfg, & input, & odir, & ofile, None ) ;
169
165
}
170
166
@@ -185,12 +181,8 @@ pub fn commit_date_str() -> Option<&'static str> {
185
181
186
182
/// Prints version information and returns None on success or an error
187
183
/// message on panic.
188
- pub fn version ( binary : & str , matches : & getopts:: Matches ) -> Option < String > {
189
- let verbose = match matches. opt_str ( "version" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
190
- None => false ,
191
- Some ( "verbose" ) => true ,
192
- Some ( s) => return Some ( format ! ( "Unrecognized argument: {}" , s) )
193
- } ;
184
+ pub fn version ( binary : & str , matches : & getopts:: Matches ) {
185
+ let verbose = matches. opt_present ( "verbose" ) ;
194
186
195
187
println ! ( "{} {}" , binary, option_env!( "CFG_VERSION" ) . unwrap_or( "unknown version" ) ) ;
196
188
if verbose {
@@ -201,18 +193,27 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
201
193
println ! ( "host: {}" , config:: host_triple( ) ) ;
202
194
println ! ( "release: {}" , unw( release_str( ) ) ) ;
203
195
}
204
- None
205
196
}
206
197
207
- fn usage ( ) {
198
+ fn usage ( verbose : bool ) {
199
+ let groups = if verbose {
200
+ config:: optgroups ( )
201
+ } else {
202
+ config:: short_optgroups ( )
203
+ } ;
208
204
let message = format ! ( "Usage: rustc [OPTIONS] INPUT" ) ;
205
+ let extra_help = if verbose {
206
+ ""
207
+ } else {
208
+ "\n --help -v Print the full set of options rustc accepts"
209
+ } ;
209
210
println ! ( "{}\n \
210
211
Additional help:
211
212
-C help Print codegen options
212
213
-W help Print 'lint' options and default settings
213
- -Z help Print internal options for debugging rustc\n " ,
214
- getopts:: usage( message. as_slice( ) ,
215
- config :: optgroups ( ) . as_slice ( ) ) ) ;
214
+ -Z help Print internal options for debugging rustc{} \n " ,
215
+ getopts:: usage( message. as_slice( ) , groups . as_slice ( ) ) ,
216
+ extra_help ) ;
216
217
}
217
218
218
219
fn describe_lints ( lint_store : & lint:: LintStore , loaded_plugins : bool ) {
@@ -360,7 +361,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
360
361
let _binary = args. remove ( 0 ) . unwrap ( ) ;
361
362
362
363
if args. is_empty ( ) {
363
- usage ( ) ;
364
+ usage ( false ) ;
364
365
return None ;
365
366
}
366
367
@@ -373,7 +374,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
373
374
} ;
374
375
375
376
if matches. opt_present ( "h" ) || matches. opt_present ( "help" ) {
376
- usage ( ) ;
377
+ usage ( matches . opt_present ( "verbose" ) ) ;
377
378
return None ;
378
379
}
379
380
@@ -397,49 +398,55 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
397
398
}
398
399
399
400
if matches. opt_present ( "version" ) {
400
- match version ( "rustc" , & matches) {
401
- Some ( err) => early_error ( err. as_slice ( ) ) ,
402
- None => return None
403
- }
401
+ version ( "rustc" , & matches) ;
402
+ return None ;
404
403
}
405
404
406
405
Some ( matches)
407
406
}
408
407
409
408
fn print_crate_info ( sess : & Session ,
410
- input : & Input ,
409
+ input : Option < & Input > ,
411
410
odir : & Option < Path > ,
412
411
ofile : & Option < Path > )
413
412
-> bool {
414
- let ( crate_name, crate_file_name) = sess. opts . print_metas ;
415
- // these nasty nested conditions are to avoid doing extra work
416
- if crate_name || crate_file_name {
417
- let attrs = parse_crate_attrs ( sess, input) ;
418
- let t_outputs = driver:: build_output_filenames ( input,
419
- odir,
420
- ofile,
421
- attrs. as_slice ( ) ,
422
- sess) ;
423
- let id = link:: find_crate_name ( Some ( sess) , attrs. as_slice ( ) , input) ;
424
-
425
- if crate_name {
426
- println ! ( "{}" , id) ;
427
- }
428
- if crate_file_name {
429
- let crate_types = driver:: collect_crate_types ( sess, attrs. as_slice ( ) ) ;
430
- let metadata = driver:: collect_crate_metadata ( sess, attrs. as_slice ( ) ) ;
431
- * sess. crate_metadata . borrow_mut ( ) = metadata;
432
- for & style in crate_types. iter ( ) {
433
- let fname = link:: filename_for_input ( sess, style, id. as_slice ( ) ,
434
- & t_outputs. with_extension ( "" ) ) ;
435
- println ! ( "{}" , fname. filename_display( ) ) ;
413
+ if sess. opts . prints . len ( ) == 0 { return false }
414
+
415
+ let attrs = input. map ( |input| parse_crate_attrs ( sess, input) ) ;
416
+ for req in sess. opts . prints . iter ( ) {
417
+ match * req {
418
+ PrintRequest :: Sysroot => println ! ( "{}" , sess. sysroot( ) . display( ) ) ,
419
+ PrintRequest :: FileNames |
420
+ PrintRequest :: CrateName => {
421
+ let input = match input {
422
+ Some ( input) => input,
423
+ None => early_error ( "no input file provided" ) ,
424
+ } ;
425
+ let attrs = attrs. as_ref ( ) . unwrap ( ) . as_slice ( ) ;
426
+ let t_outputs = driver:: build_output_filenames ( input,
427
+ odir,
428
+ ofile,
429
+ attrs,
430
+ sess) ;
431
+ let id = link:: find_crate_name ( Some ( sess) , attrs. as_slice ( ) ,
432
+ input) ;
433
+ if * req == PrintRequest :: CrateName {
434
+ println ! ( "{}" , id) ;
435
+ continue
436
+ }
437
+ let crate_types = driver:: collect_crate_types ( sess, attrs) ;
438
+ let metadata = driver:: collect_crate_metadata ( sess, attrs) ;
439
+ * sess. crate_metadata . borrow_mut ( ) = metadata;
440
+ for & style in crate_types. iter ( ) {
441
+ let fname = link:: filename_for_input ( sess, style,
442
+ id. as_slice ( ) ,
443
+ & t_outputs. with_extension ( "" ) ) ;
444
+ println ! ( "{}" , fname. filename_display( ) ) ;
445
+ }
436
446
}
437
447
}
438
-
439
- true
440
- } else {
441
- false
442
448
}
449
+ return true ;
443
450
}
444
451
445
452
fn parse_crate_attrs ( sess : & Session , input : & Input ) ->
0 commit comments