Skip to content

Commit 1c03f2f

Browse files
committed
---
yaml --- r: 148849 b: refs/heads/try2 c: 5e8ba72 h: refs/heads/master i: 148847: 9941993 v: v3
1 parent cbd5d14 commit 1c03f2f

File tree

12 files changed

+201
-154
lines changed

12 files changed

+201
-154
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: b211b00d21fc7c03c3c378ad5eab60666a00fc08
8+
refs/heads/try2: 5e8ba7252a162fc6a3c5186904947f5969d732af
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/back/archive.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use lib::llvm::{ArchiveRef, llvm};
1717

1818
use std::cast;
1919
use std::io::fs;
20+
use std::io;
2021
use std::libc;
2122
use std::os;
2223
use std::run::{ProcessOptions, Process, ProcessOutput};
@@ -50,9 +51,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
5051
Some(p) => { debug!("inside {}", p.display()); }
5152
None => {}
5253
}
53-
let mut opt_prog = Process::new(ar, args.as_slice(), opts);
54-
match opt_prog {
55-
Some(ref mut prog) => {
54+
match Process::new(ar, args.as_slice(), opts) {
55+
Ok(mut prog) => {
5656
let o = prog.finish_with_output();
5757
if !o.status.success() {
5858
sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
@@ -63,8 +63,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
6363
}
6464
o
6565
},
66-
None => {
67-
sess.err(format!("could not exec `{}`", ar));
66+
Err(e) => {
67+
sess.err(format!("could not exec `{}`: {}", ar, e));
6868
sess.abort_if_errors();
6969
fail!("rustc::back::archive::run_ar() should not reach this point");
7070
}
@@ -94,32 +94,33 @@ impl Archive {
9494
let archive = os::make_absolute(&self.dst);
9595
run_ar(self.sess, "x", Some(loc.path()), [&archive,
9696
&Path::new(file)]);
97-
fs::File::open(&loc.path().join(file)).read_to_end()
97+
fs::File::open(&loc.path().join(file)).read_to_end().unwrap()
9898
} else {
9999
run_ar(self.sess, "p", None, [&self.dst, &Path::new(file)]).output
100100
}
101101
}
102102

103103
/// Adds all of the contents of a native library to this archive. This will
104104
/// search in the relevant locations for a library named `name`.
105-
pub fn add_native_library(&mut self, name: &str) {
105+
pub fn add_native_library(&mut self, name: &str) -> io::IoResult<()> {
106106
let location = self.find_library(name);
107-
self.add_archive(&location, name, []);
107+
self.add_archive(&location, name, [])
108108
}
109109

110110
/// Adds all of the contents of the rlib at the specified path to this
111111
/// archive.
112112
///
113113
/// This ignores adding the bytecode from the rlib, and if LTO is enabled
114114
/// then the object file also isn't added.
115-
pub fn add_rlib(&mut self, rlib: &Path, name: &str, lto: bool) {
115+
pub fn add_rlib(&mut self, rlib: &Path, name: &str,
116+
lto: bool) -> io::IoResult<()> {
116117
let object = format!("{}.o", name);
117118
let bytecode = format!("{}.bc", name);
118119
let mut ignore = ~[METADATA_FILENAME, bytecode.as_slice()];
119120
if lto {
120121
ignore.push(object.as_slice());
121122
}
122-
self.add_archive(rlib, name, ignore);
123+
self.add_archive(rlib, name, ignore)
123124
}
124125

125126
/// Adds an arbitrary file to this archive
@@ -144,7 +145,8 @@ impl Archive {
144145
str::from_utf8(output.output).unwrap().lines().map(|s| s.to_owned()).collect()
145146
}
146147

147-
fn add_archive(&mut self, archive: &Path, name: &str, skip: &[&str]) {
148+
fn add_archive(&mut self, archive: &Path, name: &str,
149+
skip: &[&str]) -> io::IoResult<()> {
148150
let loc = TempDir::new("rsar").unwrap();
149151

150152
// First, extract the contents of the archive to a temporary directory
@@ -159,7 +161,7 @@ impl Archive {
159161
// We skip any files explicitly desired for skipping, and we also skip
160162
// all SYMDEF files as these are just magical placeholders which get
161163
// re-created when we make a new archive anyway.
162-
let files = fs::readdir(loc.path());
164+
let files = if_ok!(fs::readdir(loc.path()));
163165
let mut inputs = ~[];
164166
for file in files.iter() {
165167
let filename = file.filename_str().unwrap();
@@ -168,14 +170,15 @@ impl Archive {
168170

169171
let filename = format!("r-{}-{}", name, filename);
170172
let new_filename = file.with_filename(filename);
171-
fs::rename(file, &new_filename);
173+
if_ok!(fs::rename(file, &new_filename));
172174
inputs.push(new_filename);
173175
}
174176

175177
// Finally, add all the renamed files to this archive
176178
let mut args = ~[&self.dst];
177179
args.extend(&mut inputs.iter());
178180
run_ar(self.sess, "r", None, args.as_slice());
181+
Ok(())
179182
}
180183

181184
fn find_library(&self, name: &str) -> Path {

branches/try2/src/librustc/back/link.rs

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub mod write {
100100
use util::common::time;
101101

102102
use std::c_str::ToCStr;
103-
use std::io;
104103
use std::libc::{c_uint, c_int};
105104
use std::path::Path;
106105
use std::run;
@@ -297,21 +296,17 @@ pub mod write {
297296
assembly.as_str().unwrap().to_owned()];
298297

299298
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) => {
306301
if !prog.status.success() {
307302
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
308303
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
309304
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
310305
sess.abort_if_errors();
311306
}
312307
},
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));
315310
sess.abort_if_errors();
316311
}
317312
}
@@ -768,6 +763,15 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
768763
}
769764
}
770765

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+
771775
/// Perform the linkage portion of the compilation phase. This will generate all
772776
/// of the requested outputs for this compilation session.
773777
pub fn link_binary(sess: Session,
@@ -785,17 +789,15 @@ pub fn link_binary(sess: Session,
785789

786790
// Remove the temporary object file and metadata if we aren't saving temps
787791
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"));
790794
}
791795

792796
out_filenames
793797
}
794798

795799
fn is_writeable(p: &Path) -> bool {
796-
use std::io;
797-
798-
match io::result(|| p.stat()) {
800+
match p.stat() {
799801
Err(..) => true,
800802
Ok(m) => m.perm & io::UserWrite == io::UserWrite
801803
}
@@ -884,7 +886,7 @@ fn link_rlib(sess: Session,
884886
for &(ref l, kind) in used_libraries.get().iter() {
885887
match kind {
886888
cstore::NativeStatic => {
887-
a.add_native_library(l.as_slice());
889+
a.add_native_library(l.as_slice()).unwrap();
888890
}
889891
cstore::NativeFramework | cstore::NativeUnknown => {}
890892
}
@@ -919,16 +921,23 @@ fn link_rlib(sess: Session,
919921
// the same filename for metadata (stomping over one another)
920922
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
921923
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+
}
923932
a.add_file(&metadata, false);
924-
fs::unlink(&metadata);
933+
remove(sess, &metadata);
925934

926935
// For LTO purposes, the bytecode of this library is also inserted
927936
// into the archive.
928937
let bc = obj_filename.with_extension("bc");
929938
a.add_file(&bc, false);
930939
if !sess.opts.save_temps {
931-
fs::unlink(&bc);
940+
remove(sess, &bc);
932941
}
933942

934943
// After adding all files to the archive, we need to update the
@@ -959,7 +968,7 @@ fn link_rlib(sess: Session,
959968
// metadata file).
960969
fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
961970
let mut a = link_rlib(sess, None, obj_filename, out_filename);
962-
a.add_native_library("morestack");
971+
a.add_native_library("morestack").unwrap();
963972

964973
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
965974
for &(cnum, ref path) in crates.iter() {
@@ -970,7 +979,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
970979
continue
971980
}
972981
};
973-
a.add_rlib(&p, name, sess.lto());
982+
a.add_rlib(&p, name, sess.lto()).unwrap();
974983
let native_libs = csearch::get_native_libraries(sess.cstore, cnum);
975984
for &(kind, ref lib) in native_libs.iter() {
976985
let name = match kind {
@@ -1004,23 +1013,19 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10041013

10051014
// Invoke the system linker
10061015
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) => {
10151020
if !prog.status.success() {
10161021
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
10171022
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
10181023
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
10191024
sess.abort_if_errors();
10201025
}
10211026
},
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));
10241029
sess.abort_if_errors();
10251030
}
10261031
}
@@ -1030,8 +1035,14 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10301035
// the symbols
10311036
if sess.targ_cfg.os == abi::OsMacos && sess.opts.debuginfo {
10321037
// 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+
}
10351046
}
10361047
}
10371048

@@ -1225,7 +1236,16 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
12251236
time(sess.time_passes(), format!("altering {}.rlib", name),
12261237
(), |()| {
12271238
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+
}
12291249
let dst_str = dst.as_str().unwrap().to_owned();
12301250
let mut archive = Archive::open(sess, dst);
12311251
archive.remove_file(format!("{}.o", name));

0 commit comments

Comments
 (0)