@@ -384,13 +384,34 @@ pub fn phase_5_run_llvm_passes(sess: Session,
384
384
/// This should produce either a finished executable or library.
385
385
pub fn phase_6_link_output ( sess : Session ,
386
386
trans : & CrateTranslation ,
387
+ input : & input ,
387
388
outputs : & OutputFilenames ) {
388
- time ( sess. time_passes ( ) , "linking" , ( ) , |_|
389
+ let outputs = time ( sess. time_passes ( ) , "linking" , ( ) , |_|
389
390
link:: link_binary ( sess,
390
391
trans,
391
392
& outputs. obj_filename ,
392
393
& outputs. out_filename ,
393
394
& trans. link ) ) ;
395
+
396
+ // Write out dependency rules to the .d file if requested
397
+ if sess. opts . write_dependency_info {
398
+ match * input {
399
+ file_input( ref input_path) => {
400
+ let files: ~[ @str ] = sess. codemap . files . iter ( )
401
+ . filter_map ( |fmap| if fmap. is_real_file ( ) { Some ( fmap. name ) } else { None } )
402
+ . collect ( ) ;
403
+ let mut output_path = outputs[ 0 ] . dir_path ( ) ;
404
+ let filestem = input_path. filestem ( ) . expect ( "input file must have stem" ) ;
405
+ output_path. push ( Path :: new ( filestem) . with_extension ( "d" ) ) ;
406
+ let mut file = io:: File :: create ( & output_path) ;
407
+ for output in outputs. iter ( ) {
408
+ write ! ( & mut file as & mut Writer ,
409
+ "{}: {}\n \n " , output. display( ) , files. connect( " " ) ) ;
410
+ }
411
+ }
412
+ str_input( _) => { }
413
+ }
414
+ }
394
415
}
395
416
396
417
pub fn stop_after_phase_3 ( sess : Session ) -> bool {
@@ -438,7 +459,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
438
459
} ;
439
460
phase_5_run_llvm_passes ( sess, & trans, outputs) ;
440
461
if stop_after_phase_5 ( sess) { return ; }
441
- phase_6_link_output ( sess, & trans, outputs) ;
462
+ phase_6_link_output ( sess, & trans, input , outputs) ;
442
463
}
443
464
444
465
struct IdentifiedAnnotation {
@@ -750,6 +771,7 @@ pub fn build_session_options(binary: @str,
750
771
let cfg = parse_cfgspecs ( matches. opt_strs ( "cfg" ) , demitter) ;
751
772
let test = matches. opt_present ( "test" ) ;
752
773
let android_cross_path = matches. opt_str ( "android-cross-path" ) ;
774
+ let write_dependency_info = matches. opt_present ( "dep-info" ) ;
753
775
754
776
let custom_passes = match matches. opt_str ( "passes" ) {
755
777
None => ~[ ] ,
@@ -793,7 +815,8 @@ pub fn build_session_options(binary: @str,
793
815
parse_only : parse_only,
794
816
no_trans : no_trans,
795
817
debugging_opts : debugging_opts,
796
- android_cross_path : android_cross_path
818
+ android_cross_path : android_cross_path,
819
+ write_dependency_info : write_dependency_info,
797
820
} ;
798
821
return sopts;
799
822
}
@@ -902,6 +925,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
902
925
or identified (fully parenthesized,
903
926
AST nodes and blocks with IDs)" , "TYPE" ) ,
904
927
optflag ( "S" , "" , "Compile only; do not assemble or link" ) ,
928
+ optflag ( "" , "dep-info" ,
929
+ "Output dependency info to .d file after compiling" ) ,
905
930
optflag ( "" , "save-temps" ,
906
931
"Write intermediate files (.bc, .opt.bc, .o)
907
932
in addition to normal output" ) ,
0 commit comments