@@ -46,7 +46,7 @@ pub use syntax::diagnostic;
4646
4747use rustc_trans:: back:: link;
4848use rustc:: session:: { config, Session , build_session} ;
49- use rustc:: session:: config:: Input ;
49+ use rustc:: session:: config:: { Input , PrintRequest } ;
5050use rustc:: lint:: Lint ;
5151use rustc:: lint;
5252use rustc:: metadata;
@@ -101,6 +101,8 @@ fn run_compiler(args: &[String]) {
101101 }
102102
103103 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) ) ;
104106 let ( input, input_file_path) = match matches. free . len ( ) {
105107 0 u => {
106108 if sopts. describe_lints {
@@ -109,13 +111,10 @@ fn run_compiler(args: &[String]) {
109111 describe_lints ( & ls, false ) ;
110112 return ;
111113 }
112-
113114 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) {
116116 return ;
117117 }
118-
119118 early_error ( "no input filename given" ) ;
120119 }
121120 1 u => {
@@ -133,13 +132,14 @@ fn run_compiler(args: &[String]) {
133132
134133 let sess = build_session ( sopts, input_file_path, descriptions) ;
135134 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+ }
138138
139139 let pretty = matches. opt_default ( "pretty" , "normal" ) . map ( |a| {
140140 pretty:: parse_pretty ( & sess, a. as_slice ( ) )
141141 } ) ;
142- match pretty {
142+ match pretty. into_iter ( ) . next ( ) {
143143 Some ( ( ppm, opt_uii) ) => {
144144 pretty:: pretty_print_input ( sess, cfg, & input, ppm, opt_uii, ofile) ;
145145 return ;
@@ -161,10 +161,6 @@ fn run_compiler(args: &[String]) {
161161 return ;
162162 }
163163
164- if print_crate_info ( & sess, & input, & odir, & ofile) {
165- return ;
166- }
167-
168164 driver:: compile_input ( sess, cfg, & input, & odir, & ofile, None ) ;
169165}
170166
@@ -185,12 +181,8 @@ pub fn commit_date_str() -> Option<&'static str> {
185181
186182/// Prints version information and returns None on success or an error
187183/// 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" ) ;
194186
195187 println ! ( "{} {}" , binary, option_env!( "CFG_VERSION" ) . unwrap_or( "unknown version" ) ) ;
196188 if verbose {
@@ -201,18 +193,27 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
201193 println ! ( "host: {}" , config:: host_triple( ) ) ;
202194 println ! ( "release: {}" , unw( release_str( ) ) ) ;
203195 }
204- None
205196}
206197
207- fn usage ( ) {
198+ fn usage ( verbose : bool ) {
199+ let groups = if verbose {
200+ config:: optgroups ( )
201+ } else {
202+ config:: short_optgroups ( )
203+ } ;
208204 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+ } ;
209210 println ! ( "{}\n \
210211 Additional help:
211212 -C help Print codegen options
212213 -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 ) ;
216217}
217218
218219fn describe_lints ( lint_store : & lint:: LintStore , loaded_plugins : bool ) {
@@ -360,7 +361,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
360361 let _binary = args. remove ( 0 ) . unwrap ( ) ;
361362
362363 if args. is_empty ( ) {
363- usage ( ) ;
364+ usage ( false ) ;
364365 return None ;
365366 }
366367
@@ -373,7 +374,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
373374 } ;
374375
375376 if matches. opt_present ( "h" ) || matches. opt_present ( "help" ) {
376- usage ( ) ;
377+ usage ( matches . opt_present ( "verbose" ) ) ;
377378 return None ;
378379 }
379380
@@ -397,49 +398,55 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
397398 }
398399
399400 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 ;
404403 }
405404
406405 Some ( matches)
407406}
408407
409408fn print_crate_info ( sess : & Session ,
410- input : & Input ,
409+ input : Option < & Input > ,
411410 odir : & Option < Path > ,
412411 ofile : & Option < Path > )
413412 -> 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+ }
436446 }
437447 }
438-
439- true
440- } else {
441- false
442448 }
449+ return true ;
443450}
444451
445452fn parse_crate_attrs ( sess : & Session , input : & Input ) ->
0 commit comments