@@ -438,6 +438,53 @@ fn opts() -> [getopts::opt] {
438
438
optflag ( "stack-growth" ) , optflag ( "check-unsafe" ) ] ;
439
439
}
440
440
441
+ fn build_output_filenames ( ifile : str , ofile : option:: t < str > ,
442
+ sopts : @session:: options )
443
+ -> @{ out_filename : str , obj_filename : str } {
444
+ let obj_filename = "" ;
445
+ let saved_out_filename: str = "" ;
446
+ let stop_after_codegen =
447
+ sopts. output_type != link:: output_type_exe ||
448
+ sopts. static && sopts. library ;
449
+ alt ofile {
450
+ none. {
451
+ // "-" as input file will cause the parser to read from stdin so we
452
+ // have to make up a name
453
+ // We want to toss everything after the final '.'
454
+ let parts =
455
+ if !input_is_stdin ( ifile) {
456
+ str:: split ( ifile, '.' as u8 )
457
+ } else { [ "default" , "rs" ] } ;
458
+ vec:: pop ( parts) ;
459
+ let base_filename = str:: connect ( parts, "." ) ;
460
+ let suffix =
461
+ alt sopts. output_type {
462
+ link:: output_type_none. { "none" }
463
+ link:: output_type_bitcode. { "bc" }
464
+ link:: output_type_assembly. { "s" }
465
+ // Object and exe output both use the '.o' extension here
466
+ link:: output_type_object. | link:: output_type_exe. {
467
+ "o"
468
+ }
469
+ } ;
470
+ obj_filename = base_filename + "." + suffix;
471
+
472
+ if sopts. library {
473
+ saved_out_filename = std:: os:: dylib_filename ( base_filename) ;
474
+ } else {
475
+ saved_out_filename = base_filename;
476
+ }
477
+ }
478
+ some ( out_file) {
479
+ // FIXME: what about windows? This will create a foo.exe.o.
480
+ saved_out_filename = out_file;
481
+ obj_filename =
482
+ if stop_after_codegen { out_file } else { out_file + ".o" } ;
483
+ }
484
+ }
485
+ ret @{ out_filename: saved_out_filename, obj_filename: obj_filename} ;
486
+ }
487
+
441
488
fn main( args: [ str] ) {
442
489
let binary = vec:: shift ( args) ;
443
490
let match =
@@ -459,14 +506,14 @@ fn main(args: [str]) {
459
506
let sopts = build_session_options( match) ;
460
507
let sess = build_session( sopts) ;
461
508
let n_inputs = vec:: len:: < str > ( match. free) ;
462
- let output_file = getopts:: opt_maybe_str( match, "o" ) ;
509
+ let ofile = getopts:: opt_maybe_str( match, "o" ) ;
510
+ let ifile = match . free[ 0 ] ;
511
+ let outputs = build_output_filenames( ifile, ofile, sopts) ;
463
512
if n_inputs == 0 u {
464
513
sess. fatal ( "No input filename given." ) ;
465
514
} else if n_inputs > 1 u {
466
515
sess. fatal ( "Multiple input filenames provided." ) ;
467
516
}
468
- let ifile = match . free[ 0 ] ;
469
- let saved_out_filename: str = "" ;
470
517
let cfg = build_configuration ( sess, binary, ifile) ;
471
518
let pretty =
472
519
option:: map :: < str ,
@@ -484,47 +531,13 @@ fn main(args: [str]) {
484
531
sopts. output_type != link:: output_type_exe ||
485
532
sopts. static && sopts. library ;
486
533
487
- let ofile = "" ;
488
- alt output_file {
489
- none. {
490
- // "-" as input file will cause the parser to read from stdin so we
491
- // have to make up a name
492
- // We want to toss everything after the final '.'
493
- let parts =
494
- if !input_is_stdin ( ifile) {
495
- str:: split ( ifile, '.' as u8 )
496
- } else { [ "default" , "rs" ] } ;
497
- vec:: pop ( parts) ;
498
- let base_filename = str:: connect ( parts, "." ) ;
499
- let suffix =
500
- alt sopts. output_type {
501
- link:: output_type_none. { "none" }
502
- link:: output_type_bitcode. { "bc" }
503
- link:: output_type_assembly. { "s" }
504
- // Object and exe output both use the '.o' extension here
505
- link:: output_type_object. | link:: output_type_exe. {
506
- "o"
507
- }
508
- } ;
509
- ofile = base_filename + "." + suffix;
534
+ let temp_filename = outputs. obj_filename ;
510
535
511
- if sopts. library {
512
- saved_out_filename = std:: os:: dylib_filename ( base_filename) ;
513
- } else {
514
- saved_out_filename = base_filename;
515
- }
516
- }
517
- some( out_file) {
518
- saved_out_filename = out_file;
519
- ofile =
520
- if !stop_after_codegen { out_file + ".o" } else { out_file } ;
521
- }
522
- }
536
+ compile_input ( sess, cfg, ifile, temp_filename) ;
523
537
524
- compile_input ( sess, cfg, ifile, ofile) ;
525
538
if stop_after_codegen { ret; }
526
539
527
- link:: link_binary ( sess, ofile , saved_out_filename ) ;
540
+ link:: link_binary ( sess, temp_filename , outputs . out_filename ) ;
528
541
}
529
542
530
543
#[ cfg( test) ]
0 commit comments