about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSiegeLord <slabode@aim.com>2013-12-26 14:55:10 -0500
committerSiegeLord <slabode@aim.com>2013-12-31 15:28:02 -0500
commita7a9e488a47ef9ca2f9cc9f73903b2ac3f54fc4c (patch)
tree8ac6d3ad5cc6d5db3e1f10b007966110f926b0a5
parent5ff7b283731b795930d1e6782ae1639c83595e91 (diff)
downloadrust-a7a9e488a47ef9ca2f9cc9f73903b2ac3f54fc4c.tar.gz
rust-a7a9e488a47ef9ca2f9cc9f73903b2ac3f54fc4c.zip
Generate --dep-info earlier in the compillation.
-rw-r--r--src/librustc/driver/driver.rs74
-rw-r--r--src/librustpkg/util.rs2
2 files changed, 45 insertions, 31 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index dba811d822f..c4f2b409247 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -392,14 +392,48 @@ pub fn phase_5_run_llvm_passes(sess: Session,
 /// This should produce either a finished executable or library.
 pub fn phase_6_link_output(sess: Session,
                            trans: &CrateTranslation,
-                           input: &input,
                            outputs: &OutputFilenames) {
-    let outputs = time(sess.time_passes(), "linking", (), |_|
+    time(sess.time_passes(), "linking", (), |_|
          link::link_binary(sess,
                            trans,
                            &outputs.obj_filename,
                            &outputs.out_filename,
                            &trans.link));
+}
+
+pub fn stop_after_phase_3(sess: Session) -> bool {
+   if sess.opts.no_trans {
+        debug!("invoked with --no-trans, returning early from compile_input");
+        return true;
+    }
+    return false;
+}
+
+pub fn stop_after_phase_1(sess: Session) -> bool {
+    if sess.opts.parse_only {
+        debug!("invoked with --parse-only, returning early from compile_input");
+        return true;
+    }
+    return false;
+}
+
+pub fn stop_after_phase_5(sess: Session) -> bool {
+    if sess.opts.output_type != link::output_type_exe {
+        debug!("not building executable, returning early from compile_input");
+        return true;
+    }
+    return false;
+}
+
+fn write_out_deps(sess: Session, input: &input, outputs: &OutputFilenames, crate: &ast::Crate)
+{
+    let lm = link::build_link_meta(sess, crate.attrs, &outputs.obj_filename,
+                                       &mut ::util::sha2::Sha256::new());
+
+    let sess_outputs = sess.outputs.borrow();
+    let out_filenames = sess_outputs.get().iter()
+        .map(|&output| link::filename_for_input(&sess, output, &lm, &outputs.out_filename))
+        .to_owned_vec();
 
     // Write out dependency rules to the dep-info file if requested with --dep-info
     let deps_filename = match sess.opts.write_dependency_info {
@@ -409,7 +443,7 @@ pub fn phase_6_link_output(sess: Session,
         (true, None) => match *input {
             file_input(ref input_path) => {
                 let filestem = input_path.filestem().expect("input file must have stem");
-                let filename = outputs[0].dir_path().join(filestem).with_extension("d");
+                let filename = out_filenames[0].dir_path().join(filestem).with_extension("d");
                 filename
             },
             str_input(..) => {
@@ -419,40 +453,17 @@ pub fn phase_6_link_output(sess: Session,
         },
         _ => return,
     };
+
     // Build a list of files used to compile the output and
     // write Makefile-compatible dependency rules
     let files: ~[@str] = sess.codemap.files.iter()
         .filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None })
         .collect();
     let mut file = io::File::create(&deps_filename);
-    for output in outputs.iter() {
+    for path in out_filenames.iter() {
         write!(&mut file as &mut Writer,
-               "{}: {}\n\n", output.display(), files.connect(" "));
-    }
-}
-
-pub fn stop_after_phase_3(sess: Session) -> bool {
-   if sess.opts.no_trans {
-        debug!("invoked with --no-trans, returning early from compile_input");
-        return true;
+               "{}: {}\n\n", path.display(), files.connect(" "));
     }
-    return false;
-}
-
-pub fn stop_after_phase_1(sess: Session) -> bool {
-    if sess.opts.parse_only {
-        debug!("invoked with --parse-only, returning early from compile_input");
-        return true;
-    }
-    return false;
-}
-
-pub fn stop_after_phase_5(sess: Session) -> bool {
-    if sess.opts.output_type != link::output_type_exe {
-        debug!("not building executable, returning early from compile_input");
-        return true;
-    }
-    return false;
 }
 
 pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
@@ -468,6 +479,9 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
         };
         let outputs = build_output_filenames(input, outdir, output,
                                              expanded_crate.attrs, sess);
+
+        write_out_deps(sess, input, outputs, &expanded_crate);
+
         let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
         if stop_after_phase_3(sess) { return; }
         let trans = phase_4_translate_to_llvm(sess, expanded_crate,
@@ -476,7 +490,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
     };
     phase_5_run_llvm_passes(sess, &trans, outputs);
     if stop_after_phase_5(sess) { return; }
-    phase_6_link_output(sess, &trans, input, outputs);
+    phase_6_link_output(sess, &trans, outputs);
 }
 
 struct IdentifiedAnnotation {
diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs
index 4ec752aeb39..af940e34789 100644
--- a/src/librustpkg/util.rs
+++ b/src/librustpkg/util.rs
@@ -405,7 +405,7 @@ pub fn compile_crate_from_input(input: &Path,
     // -c
     if driver::stop_after_phase_5(sess)
         || stop_before == Link || stop_before == Assemble { return Some(outputs.out_filename); }
-    driver::phase_6_link_output(sess, &translation, &file_input, outputs);
+    driver::phase_6_link_output(sess, &translation, outputs);
 
     // Register dependency on the source file
     // FIXME (#9639): This needs to handle non-utf8 paths