@@ -100,7 +100,6 @@ pub mod write {
100
100
use util:: common:: time;
101
101
102
102
use std:: c_str:: ToCStr ;
103
- use std:: io;
104
103
use std:: libc:: { c_uint, c_int} ;
105
104
use std:: path:: Path ;
106
105
use std:: run;
@@ -297,21 +296,17 @@ pub mod write {
297
296
assembly. as_str ( ) . unwrap ( ) . to_owned ( ) ] ;
298
297
299
298
debug ! ( "{} '{}'" , cc, args. connect( "' '" ) ) ;
300
- let opt_prog = {
301
- let _guard = io:: ignore_io_error ( ) ;
302
- run:: process_output ( cc, args)
303
- } ;
304
- match opt_prog {
305
- Some ( prog) => {
299
+ match run:: process_output ( cc, args) {
300
+ Ok ( prog) => {
306
301
if !prog. status . success ( ) {
307
302
sess. err ( format ! ( "linking with `{}` failed: {}" , cc, prog. status) ) ;
308
303
sess. note ( format ! ( "{} arguments: '{}'" , cc, args. connect( "' '" ) ) ) ;
309
304
sess. note ( str:: from_utf8_owned ( prog. error + prog. output ) . unwrap ( ) ) ;
310
305
sess. abort_if_errors ( ) ;
311
306
}
312
307
} ,
313
- None => {
314
- sess. err ( format ! ( "could not exec the linker `{}`" , cc) ) ;
308
+ Err ( e ) => {
309
+ sess. err ( format ! ( "could not exec the linker `{}`: {} " , cc, e ) ) ;
315
310
sess. abort_if_errors ( ) ;
316
311
}
317
312
}
@@ -768,6 +763,15 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
768
763
}
769
764
}
770
765
766
+ fn remove ( sess : Session , path : & Path ) {
767
+ match fs:: unlink ( path) {
768
+ Ok ( ..) => { }
769
+ Err ( e) => {
770
+ sess. err ( format ! ( "failed to remove {}: {}" , path. display( ) , e) ) ;
771
+ }
772
+ }
773
+ }
774
+
771
775
/// Perform the linkage portion of the compilation phase. This will generate all
772
776
/// of the requested outputs for this compilation session.
773
777
pub fn link_binary ( sess : Session ,
@@ -785,17 +789,15 @@ pub fn link_binary(sess: Session,
785
789
786
790
// Remove the temporary object file and metadata if we aren't saving temps
787
791
if !sess. opts . save_temps {
788
- fs :: unlink ( obj_filename) ;
789
- fs :: unlink ( & obj_filename. with_extension ( "metadata.o" ) ) ;
792
+ remove ( sess , obj_filename) ;
793
+ remove ( sess , & obj_filename. with_extension ( "metadata.o" ) ) ;
790
794
}
791
795
792
796
out_filenames
793
797
}
794
798
795
799
fn is_writeable ( p : & Path ) -> bool {
796
- use std:: io;
797
-
798
- match io:: result ( || p. stat ( ) ) {
800
+ match p. stat ( ) {
799
801
Err ( ..) => true ,
800
802
Ok ( m) => m. perm & io:: UserWrite == io:: UserWrite
801
803
}
@@ -884,7 +886,7 @@ fn link_rlib(sess: Session,
884
886
for & ( ref l, kind) in used_libraries. get ( ) . iter ( ) {
885
887
match kind {
886
888
cstore:: NativeStatic => {
887
- a. add_native_library ( l. as_slice ( ) ) ;
889
+ a. add_native_library ( l. as_slice ( ) ) . unwrap ( ) ;
888
890
}
889
891
cstore:: NativeFramework | cstore:: NativeUnknown => { }
890
892
}
@@ -919,16 +921,23 @@ fn link_rlib(sess: Session,
919
921
// the same filename for metadata (stomping over one another)
920
922
let tmpdir = TempDir :: new ( "rustc" ) . expect ( "needs a temp dir" ) ;
921
923
let metadata = tmpdir. path ( ) . join ( METADATA_FILENAME ) ;
922
- fs:: File :: create ( & metadata) . write ( trans. metadata ) ;
924
+ match fs:: File :: create ( & metadata) . write ( trans. metadata ) {
925
+ Ok ( ..) => { }
926
+ Err ( e) => {
927
+ sess. err ( format ! ( "failed to write {}: {}" ,
928
+ metadata. display( ) , e) ) ;
929
+ sess. abort_if_errors ( ) ;
930
+ }
931
+ }
923
932
a. add_file ( & metadata, false ) ;
924
- fs :: unlink ( & metadata) ;
933
+ remove ( sess , & metadata) ;
925
934
926
935
// For LTO purposes, the bytecode of this library is also inserted
927
936
// into the archive.
928
937
let bc = obj_filename. with_extension ( "bc" ) ;
929
938
a. add_file ( & bc, false ) ;
930
939
if !sess. opts . save_temps {
931
- fs :: unlink ( & bc) ;
940
+ remove ( sess , & bc) ;
932
941
}
933
942
934
943
// After adding all files to the archive, we need to update the
@@ -959,7 +968,7 @@ fn link_rlib(sess: Session,
959
968
// metadata file).
960
969
fn link_staticlib ( sess : Session , obj_filename : & Path , out_filename : & Path ) {
961
970
let mut a = link_rlib ( sess, None , obj_filename, out_filename) ;
962
- a. add_native_library ( "morestack" ) ;
971
+ a. add_native_library ( "morestack" ) . unwrap ( ) ;
963
972
964
973
let crates = sess. cstore . get_used_crates ( cstore:: RequireStatic ) ;
965
974
for & ( cnum, ref path) in crates. iter ( ) {
@@ -970,7 +979,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
970
979
continue
971
980
}
972
981
} ;
973
- a. add_rlib ( & p, name, sess. lto ( ) ) ;
982
+ a. add_rlib ( & p, name, sess. lto ( ) ) . unwrap ( ) ;
974
983
let native_libs = csearch:: get_native_libraries ( sess. cstore , cnum) ;
975
984
for & ( kind, ref lib) in native_libs. iter ( ) {
976
985
let name = match kind {
@@ -1004,23 +1013,19 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
1004
1013
1005
1014
// Invoke the system linker
1006
1015
debug ! ( "{} {}" , cc_prog, cc_args. connect( " " ) ) ;
1007
- let opt_prog = {
1008
- let _guard = io:: ignore_io_error ( ) ;
1009
- time ( sess. time_passes ( ) , "running linker" , ( ) , |( ) |
1010
- run:: process_output ( cc_prog, cc_args) )
1011
- } ;
1012
-
1013
- match opt_prog {
1014
- Some ( prog) => {
1016
+ let prog = time ( sess. time_passes ( ) , "running linker" , ( ) , |( ) |
1017
+ run:: process_output ( cc_prog, cc_args) ) ;
1018
+ match prog {
1019
+ Ok ( prog) => {
1015
1020
if !prog. status . success ( ) {
1016
1021
sess. err ( format ! ( "linking with `{}` failed: {}" , cc_prog, prog. status) ) ;
1017
1022
sess. note ( format ! ( "{} arguments: '{}'" , cc_prog, cc_args. connect( "' '" ) ) ) ;
1018
1023
sess. note ( str:: from_utf8_owned ( prog. error + prog. output ) . unwrap ( ) ) ;
1019
1024
sess. abort_if_errors ( ) ;
1020
1025
}
1021
1026
} ,
1022
- None => {
1023
- sess. err ( format ! ( "could not exec the linker `{}`" , cc_prog) ) ;
1027
+ Err ( e ) => {
1028
+ sess. err ( format ! ( "could not exec the linker `{}`: {} " , cc_prog, e ) ) ;
1024
1029
sess. abort_if_errors ( ) ;
1025
1030
}
1026
1031
}
@@ -1030,8 +1035,14 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
1030
1035
// the symbols
1031
1036
if sess. targ_cfg . os == abi:: OsMacos && sess. opts . debuginfo {
1032
1037
// FIXME (#9639): This needs to handle non-utf8 paths
1033
- run:: process_status ( "dsymutil" ,
1034
- [ out_filename. as_str ( ) . unwrap ( ) . to_owned ( ) ] ) ;
1038
+ match run:: process_status ( "dsymutil" ,
1039
+ [ out_filename. as_str ( ) . unwrap ( ) . to_owned ( ) ] ) {
1040
+ Ok ( ..) => { }
1041
+ Err ( e) => {
1042
+ sess. err ( format ! ( "failed to run dsymutil: {}" , e) ) ;
1043
+ sess. abort_if_errors ( ) ;
1044
+ }
1045
+ }
1035
1046
}
1036
1047
}
1037
1048
@@ -1225,7 +1236,16 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
1225
1236
time ( sess. time_passes ( ) , format ! ( "altering {}.rlib" , name) ,
1226
1237
( ) , |( ) | {
1227
1238
let dst = tmpdir. join ( cratepath. filename ( ) . unwrap ( ) ) ;
1228
- fs:: copy ( & cratepath, & dst) ;
1239
+ match fs:: copy ( & cratepath, & dst) {
1240
+ Ok ( ..) => { }
1241
+ Err ( e) => {
1242
+ sess. err ( format ! ( "failed to copy {} to {}: {}" ,
1243
+ cratepath. display( ) ,
1244
+ dst. display( ) ,
1245
+ e) ) ;
1246
+ sess. abort_if_errors ( ) ;
1247
+ }
1248
+ }
1229
1249
let dst_str = dst. as_str ( ) . unwrap ( ) . to_owned ( ) ;
1230
1250
let mut archive = Archive :: open ( sess, dst) ;
1231
1251
archive. remove_file ( format ! ( "{}.o" , name) ) ;
0 commit comments