Move source-output conflict checking into compile_input
This commit is contained in:
@@ -71,6 +71,7 @@ use profile;
|
|||||||
|
|
||||||
pub fn compile_input(sess: &Session,
|
pub fn compile_input(sess: &Session,
|
||||||
cstore: &CStore,
|
cstore: &CStore,
|
||||||
|
input_path: &Option<PathBuf>,
|
||||||
input: &Input,
|
input: &Input,
|
||||||
outdir: &Option<PathBuf>,
|
outdir: &Option<PathBuf>,
|
||||||
output: &Option<PathBuf>,
|
output: &Option<PathBuf>,
|
||||||
@@ -142,6 +143,20 @@ pub fn compile_input(sess: &Session,
|
|||||||
};
|
};
|
||||||
|
|
||||||
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
|
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
|
||||||
|
|
||||||
|
// Ensure the source file isn't accidentally overwritten during compilation.
|
||||||
|
match *input_path {
|
||||||
|
Some(ref input_path) => {
|
||||||
|
if outputs.contains_path(input_path) && sess.opts.will_create_output_file() {
|
||||||
|
sess.err(&format!(
|
||||||
|
"the input file \"{}\" would be overwritten by the generated executable",
|
||||||
|
input_path.display()));
|
||||||
|
return Err(CompileIncomplete::Stopped);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
let crate_name =
|
let crate_name =
|
||||||
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
|
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
|
||||||
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
|
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
|
||||||
|
|||||||
@@ -237,20 +237,6 @@ pub fn run_compiler<'a>(args: &[String],
|
|||||||
rustc_trans::init(&sess);
|
rustc_trans::init(&sess);
|
||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
|
|
||||||
// Ensure the source file isn't accidentally overwritten during compilation.
|
|
||||||
match input_file_path {
|
|
||||||
Some(input_file_path) => {
|
|
||||||
if driver::build_output_filenames(&input, &odir, &ofile, &[], &sess)
|
|
||||||
.contains_path(&input_file_path) && sess.opts.will_create_output_file() {
|
|
||||||
sess.err(&format!(
|
|
||||||
"the input file \"{}\" would be overwritten by the generated executable",
|
|
||||||
input_file_path.display()));
|
|
||||||
return (Err(CompileIncomplete::Stopped), Some(sess));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut cfg = config::build_configuration(&sess, cfg);
|
let mut cfg = config::build_configuration(&sess, cfg);
|
||||||
target_features::add_configuration(&mut cfg, &sess);
|
target_features::add_configuration(&mut cfg, &sess);
|
||||||
sess.parse_sess.config = cfg;
|
sess.parse_sess.config = cfg;
|
||||||
@@ -266,6 +252,7 @@ pub fn run_compiler<'a>(args: &[String],
|
|||||||
let control = callbacks.build_controller(&sess, &matches);
|
let control = callbacks.build_controller(&sess, &matches);
|
||||||
(driver::compile_input(&sess,
|
(driver::compile_input(&sess,
|
||||||
&cstore,
|
&cstore,
|
||||||
|
&input_file_path,
|
||||||
&input,
|
&input,
|
||||||
&odir,
|
&odir,
|
||||||
&ofile,
|
&ofile,
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, cfgs: Vec<String>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
let res = panic::catch_unwind(AssertUnwindSafe(|| {
|
let res = panic::catch_unwind(AssertUnwindSafe(|| {
|
||||||
driver::compile_input(&sess, &cstore, &input, &out, &None, None, &control)
|
driver::compile_input(&sess, &cstore, &None, &input, &out, &None, None, &control)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let compile_result = match res {
|
let compile_result = match res {
|
||||||
|
|||||||
Reference in New Issue
Block a user