rustc: Give a friendlier error when writing deps

When an error is encountered when writing dependencies, this presents a nicer
error rather than an ICE.

Closes #13517
This commit is contained in:
Alex Crichton 2014-04-15 07:35:17 -07:00
parent de7845ac72
commit c62daa6ed3
3 changed files with 44 additions and 19 deletions

View file

@ -495,7 +495,7 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
fn write_out_deps(sess: &Session,
input: &Input,
outputs: &OutputFilenames,
krate: &ast::Crate) -> io::IoResult<()> {
krate: &ast::Crate) {
let id = link::find_crate_id(krate.attrs.as_slice(), outputs.out_filestem);
let mut out_filenames = Vec::new();
@ -524,28 +524,34 @@ fn write_out_deps(sess: &Session,
StrInput(..) => {
sess.warn("can not write --dep-info without a filename \
when compiling stdin.");
return Ok(());
return
},
},
_ => return Ok(()),
_ => return,
};
// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: Vec<~str> = sess.codemap().files.borrow()
.iter().filter_map(|fmap| {
if fmap.is_real_file() {
Some(fmap.name.clone())
} else {
None
}
}).collect();
let mut file = try!(io::File::create(&deps_filename));
for path in out_filenames.iter() {
try!(write!(&mut file as &mut Writer,
"{}: {}\n\n", path.display(), files.connect(" ")));
let result = (|| {
// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: Vec<~str> = sess.codemap().files.borrow()
.iter().filter(|fmap| fmap.is_real_file())
.map(|fmap| fmap.name.clone())
.collect();
let mut file = try!(io::File::create(&deps_filename));
for path in out_filenames.iter() {
try!(write!(&mut file as &mut Writer,
"{}: {}\n\n", path.display(), files.connect(" ")));
}
Ok(())
})();
match result {
Ok(()) => {}
Err(e) => {
sess.fatal(format!("error writing dependencies to `{}`: {}",
deps_filename.display(), e));
}
}
Ok(())
}
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
@ -569,7 +575,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
krate, &id);
(outputs, expanded_crate, ast_map)
};
write_out_deps(&sess, input, &outputs, &expanded_crate).unwrap();
write_out_deps(&sess, input, &outputs, &expanded_crate);
if stop_after_phase_2(&sess) { return; }

View file

@ -0,0 +1,8 @@
-include ../tools.mk
all:
# Let's get a nice error message
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | \
grep "error writing dependencies"
# Make sure the filename shows up
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | grep "baz"

View file

@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {}