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:
parent
de7845ac72
commit
c62daa6ed3
3 changed files with 44 additions and 19 deletions
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
8
src/test/run-make/error-writing-dependencies/Makefile
Normal file
8
src/test/run-make/error-writing-dependencies/Makefile
Normal 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"
|
||||
11
src/test/run-make/error-writing-dependencies/foo.rs
Normal file
11
src/test/run-make/error-writing-dependencies/foo.rs
Normal 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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue