about summary refs log tree commit diff
path: root/src/librustc_incremental
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-07-21 12:49:59 -0400
committerNiko Matsakis <niko@alum.mit.edu>2016-07-28 12:05:45 -0400
commit58d4b8edd319d0f0d76024504cdfc74f89a001b1 (patch)
tree83a92fe303444117e45ba19cfc78bbef41e2ff7d /src/librustc_incremental
parentcca4804251957646d4840bf33b3b13e3f2b645de (diff)
downloadrust-58d4b8edd319d0f0d76024504cdfc74f89a001b1.tar.gz
rust-58d4b8edd319d0f0d76024504cdfc74f89a001b1.zip
Modify trans to skip generating `.o` files
This checks the `previous_work_products` data from the dep-graph and
tries to simply copy a `.o` file if possible.  We also add new
work-products into the dep-graph, and create edges to/from the dep-node
for a work-product.
Diffstat (limited to 'src/librustc_incremental')
-rw-r--r--src/librustc_incremental/lib.rs2
-rw-r--r--src/librustc_incremental/persist/mod.rs3
-rw-r--r--src/librustc_incremental/persist/work_product.rs61
3 files changed, 66 insertions, 0 deletions
diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs
index 352e5979d01..0d11b0794fe 100644
--- a/src/librustc_incremental/lib.rs
+++ b/src/librustc_incremental/lib.rs
@@ -41,4 +41,6 @@ pub use assert_dep_graph::assert_dep_graph;
 pub use calculate_svh::SvhCalculate;
 pub use persist::load_dep_graph;
 pub use persist::save_dep_graph;
+pub use persist::save_trans_partition;
 pub use persist::save_work_products;
+pub use persist::in_incr_comp_dir;
diff --git a/src/librustc_incremental/persist/mod.rs b/src/librustc_incremental/persist/mod.rs
index 30e7d7873ec..1157f494ce6 100644
--- a/src/librustc_incremental/persist/mod.rs
+++ b/src/librustc_incremental/persist/mod.rs
@@ -19,7 +19,10 @@ mod hash;
 mod load;
 mod save;
 mod util;
+mod work_product;
 
 pub use self::load::load_dep_graph;
 pub use self::save::save_dep_graph;
 pub use self::save::save_work_products;
+pub use self::work_product::save_trans_partition;
+pub use self::util::in_incr_comp_dir;
diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs
new file mode 100644
index 00000000000..01ac3f6c391
--- /dev/null
+++ b/src/librustc_incremental/persist/work_product.rs
@@ -0,0 +1,61 @@
+// Copyright 2012-2015 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.
+
+//! This module contains files for saving intermediate work-products.
+
+use persist::util::*;
+use rustc::dep_graph::{WorkProduct, WorkProductId};
+use rustc::session::Session;
+use std::fs;
+use std::path::Path;
+use std::sync::Arc;
+
+pub fn save_trans_partition(sess: &Session,
+                            partition_name: &str,
+                            partition_hash: u64,
+                            path_to_obj_file: &Path) {
+    debug!("save_trans_partition({:?},{},{})",
+           partition_name,
+           partition_hash,
+           path_to_obj_file.display());
+    if sess.opts.incremental.is_none() {
+        return;
+    }
+    let id = Arc::new(WorkProductId::PartitionObjectFile(partition_name.to_string()));
+    let file_name = format!("cgu-{}", partition_name);
+    let path_in_incr_dir = in_incr_comp_dir(sess, &file_name).unwrap();
+
+    // try to delete the file if it already exists
+    //
+    // FIXME(#34955) we can be smarter here -- if we are re-using, no need to do anything
+    if path_in_incr_dir.exists() {
+        let _ = fs::remove_file(&path_in_incr_dir);
+    }
+
+    match
+        fs::hard_link(path_to_obj_file, &path_in_incr_dir)
+        .or_else(|_| fs::copy(path_to_obj_file, &path_in_incr_dir).map(|_| ()))
+    {
+        Ok(_) => {
+            let work_product = WorkProduct {
+                input_hash: partition_hash,
+                file_name: file_name,
+            };
+            sess.dep_graph.insert_work_product(&id, work_product);
+        }
+        Err(err) => {
+            sess.warn(&format!("error copying object file `{}` \
+                                to incremental directory as `{}`: {}",
+                               path_to_obj_file.display(),
+                               path_in_incr_dir.display(),
+                               err));
+        }
+    }
+}