]> git.proxmox.com Git - rustc.git/blob - src/librustc_incremental/persist/work_product.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / librustc_incremental / persist / work_product.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This module contains files for saving intermediate work-products.
12
13 use persist::util::*;
14 use rustc::dep_graph::{WorkProduct, WorkProductId};
15 use rustc::session::Session;
16 use rustc::session::config::OutputType;
17 use rustc::util::fs::link_or_copy;
18 use std::path::PathBuf;
19 use std::sync::Arc;
20
21 pub fn save_trans_partition(sess: &Session,
22 cgu_name: &str,
23 partition_hash: u64,
24 files: &[(OutputType, PathBuf)]) {
25 debug!("save_trans_partition({:?},{},{:?})",
26 cgu_name,
27 partition_hash,
28 files);
29 if sess.opts.incremental.is_none() {
30 return;
31 }
32 let work_product_id = Arc::new(WorkProductId(cgu_name.to_string()));
33
34 let saved_files: Option<Vec<_>> =
35 files.iter()
36 .map(|&(kind, ref path)| {
37 let file_name = format!("cgu-{}.{}", cgu_name, kind.extension());
38 let path_in_incr_dir = in_incr_comp_dir(sess, &file_name).unwrap();
39 match link_or_copy(path, &path_in_incr_dir) {
40 Ok(_) => Some((kind, file_name)),
41 Err(err) => {
42 sess.warn(&format!("error copying object file `{}` \
43 to incremental directory as `{}`: {}",
44 path.display(),
45 path_in_incr_dir.display(),
46 err));
47 None
48 }
49 }
50 })
51 .collect();
52 let saved_files = match saved_files {
53 Some(v) => v,
54 None => return,
55 };
56
57 let work_product = WorkProduct {
58 input_hash: partition_hash,
59 saved_files: saved_files,
60 };
61
62 sess.dep_graph.insert_work_product(&work_product_id, work_product);
63 }