diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index cf0e7e161c1f..6674ef8abb4a 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -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; } diff --git a/src/test/run-make/error-writing-dependencies/Makefile b/src/test/run-make/error-writing-dependencies/Makefile new file mode 100644 index 000000000000..9f91618bda49 --- /dev/null +++ b/src/test/run-make/error-writing-dependencies/Makefile @@ -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" diff --git a/src/test/run-make/error-writing-dependencies/foo.rs b/src/test/run-make/error-writing-dependencies/foo.rs new file mode 100644 index 000000000000..8ae3d072362e --- /dev/null +++ b/src/test/run-make/error-writing-dependencies/foo.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {}