@@ -446,13 +446,49 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
446
446
let ( outputs, trans) = {
447
447
let expanded_crate = {
448
448
let crate = phase_1_parse_input ( sess, cfg. clone ( ) , input) ;
449
+ let ( crate_id, crate_name, crate_file_name) = sess. opts . print_metas ;
450
+ // these nasty nested conditions are to avoid doing extra work
451
+ if crate_id || crate_name || crate_file_name {
452
+ let t_outputs = build_output_filenames ( input, outdir, output, crate . attrs, sess) ;
453
+ if crate_id || crate_name {
454
+ let pkgid = match attr:: find_pkgid ( crate . attrs) {
455
+ Some ( pkgid) => pkgid,
456
+ None => fail ! ( "No crate_id and --crate-id or --crate-name requested" )
457
+ } ;
458
+ if crate_id {
459
+ println ( pkgid. to_str ( ) ) ;
460
+ }
461
+ if crate_name {
462
+ println ( pkgid. name ) ;
463
+ }
464
+ }
465
+
466
+ if crate_file_name {
467
+ let lm = link:: build_link_meta ( sess, & crate , & t_outputs. obj_filename ,
468
+ & mut :: util:: sha2:: Sha256 :: new ( ) ) ;
469
+ // if the vector is empty we default to OutputExecutable.
470
+ let style = sess. opts . outputs . get_opt ( 0 ) . unwrap_or ( & OutputExecutable ) ;
471
+ let fname = link:: filename_for_input ( & sess, * style, & lm,
472
+ & t_outputs. out_filename ) ;
473
+ println ! ( "{}" , fname. display( ) ) ;
474
+
475
+ // we already maybe printed the first one, so skip it
476
+ for style in sess. opts . outputs . iter ( ) . skip ( 1 ) {
477
+ let fname = link:: filename_for_input ( & sess, * style, & lm,
478
+ & t_outputs. out_filename ) ;
479
+ println ! ( "{}" , fname. display( ) ) ;
480
+ }
481
+ }
482
+
483
+ return ;
484
+ }
449
485
if stop_after_phase_1 ( sess) { return ; }
450
486
phase_2_configure_and_expand ( sess, cfg, crate )
451
487
} ;
452
- let analysis = phase_3_run_analysis_passes ( sess, & expanded_crate) ;
453
- if stop_after_phase_3 ( sess) { return ; }
454
488
let outputs = build_output_filenames ( input, outdir, output,
455
489
expanded_crate. attrs , sess) ;
490
+ let analysis = phase_3_run_analysis_passes ( sess, & expanded_crate) ;
491
+ if stop_after_phase_3 ( sess) { return ; }
456
492
let trans = phase_4_translate_to_llvm ( sess, expanded_crate,
457
493
& analysis, outputs) ;
458
494
( outputs, trans)
@@ -789,6 +825,9 @@ pub fn build_session_options(binary: @str,
789
825
} ) . collect ( )
790
826
}
791
827
} ;
828
+ let print_metas = ( matches. opt_present ( "crate-id" ) ,
829
+ matches. opt_present ( "crate-name" ) ,
830
+ matches. opt_present ( "crate-file-name" ) ) ;
792
831
793
832
let sopts = @session:: options {
794
833
outputs : outputs,
@@ -817,6 +856,7 @@ pub fn build_session_options(binary: @str,
817
856
debugging_opts : debugging_opts,
818
857
android_cross_path : android_cross_path,
819
858
write_dependency_info : write_dependency_info,
859
+ print_metas : print_metas,
820
860
} ;
821
861
return sopts;
822
862
}
@@ -897,6 +937,10 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
897
937
optflag ( "" , "dylib" , "Compile a dynamic library crate" ) ,
898
938
optopt ( "" , "linker" , "Program to use for linking instead of the default." , "LINKER" ) ,
899
939
optopt ( "" , "ar" , "Program to use for managing archives instead of the default." , "AR" ) ,
940
+ optflag ( "" , "crate-id" , "Output the crate id and exit" ) ,
941
+ optflag ( "" , "crate-name" , "Output the crate name and exit" ) ,
942
+ optflag ( "" , "crate-file-name" , "Output the file(s) that would be written if compilation \
943
+ continued and exit") ,
900
944
optmulti ( "" , "link-args" , "FLAGS is a space-separated list of flags
901
945
passed to the linker" , "FLAGS" ) ,
902
946
optflag ( "" , "ls" , "List the symbols defined by a library crate" ) ,
0 commit comments