From 91ce07f6f2a8091837ba356a2aeb5f407dd82dc8 Mon Sep 17 00:00:00 2001 From: Andrew Paprocki Date: Sat, 19 Apr 2014 13:18:13 -0400 Subject: [PATCH] rustc: Check --dep-info target path Add sane error messages if the user specifies an invalid path or directory for the --dep-info argument. Fail if writing the dependencies returns an Err for any reason. --- src/librustc/driver/driver.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 7da9d6f82bcfa..7c40bef67fc2c 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -536,6 +536,14 @@ fn write_out_deps(sess: &Session, _ => return Ok(()), }; + // Check that the directory exists and the target is not a directory + if !deps_filename.dir_path().exists() { + sess.fatal("directory specified by --dep-info does not exist."); + } + if deps_filename.is_dir() { + sess.fatal("file specified by --dep-info is a directory."); + } + // Build a list of files used to compile the output and // write Makefile-compatible dependency rules let files: Vec<~str> = sess.codemap().files.borrow() @@ -575,7 +583,11 @@ 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(); + let r = write_out_deps(&sess, input, &outputs, &expanded_crate); + match r { + Err(e) => fail!("writing dependencies failed due to {}", e), + _ => r.unwrap(), + } if stop_after_phase_2(&sess) { return; }