]> git.lizzy.rs Git - rust.git/blob - src/librustc_incremental/persist/work_product.rs
Rollup merge of #44562 - eddyb:ugh-rustdoc, r=nikomatsakis
[rust.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::fs::*;
14 use rustc::dep_graph::{WorkProduct, WorkProductId, DepGraph};
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::fs as std_fs;
20
21 pub fn save_trans_partition(sess: &Session,
22                             dep_graph: &DepGraph,
23                             cgu_name: &str,
24                             partition_hash: u64,
25                             files: &[(OutputType, PathBuf)]) {
26     debug!("save_trans_partition({:?},{},{:?})",
27            cgu_name,
28            partition_hash,
29            files);
30     if sess.opts.incremental.is_none() {
31         return;
32     }
33     let work_product_id = WorkProductId::from_cgu_name(cgu_name);
34
35     let saved_files: Option<Vec<_>> =
36         files.iter()
37              .map(|&(kind, ref path)| {
38                  let file_name = format!("cgu-{}.{}", cgu_name, kind.extension());
39                  let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
40                  match link_or_copy(path, &path_in_incr_dir) {
41                      Ok(_) => Some((kind, file_name)),
42                      Err(err) => {
43                          sess.warn(&format!("error copying object file `{}` \
44                                              to incremental directory as `{}`: {}",
45                                             path.display(),
46                                             path_in_incr_dir.display(),
47                                             err));
48                          None
49                      }
50                  }
51              })
52              .collect();
53     let saved_files = match saved_files {
54         Some(v) => v,
55         None => return,
56     };
57
58     let work_product = WorkProduct {
59         cgu_name: cgu_name.to_string(),
60         input_hash: partition_hash,
61         saved_files,
62     };
63
64     dep_graph.insert_work_product(&work_product_id, work_product);
65 }
66
67 pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
68     for &(_, ref file_name) in &work_product.saved_files {
69         let path = in_incr_comp_dir_sess(sess, file_name);
70         match std_fs::remove_file(&path) {
71             Ok(()) => { }
72             Err(err) => {
73                 sess.warn(
74                     &format!("file-system error deleting outdated file `{}`: {}",
75                              path.display(), err));
76             }
77         }
78     }
79 }