]> git.proxmox.com Git - rustc.git/blob - src/librustc_incremental/persist/work_product.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / librustc_incremental / persist / work_product.rs
1 //! This module contains files for saving intermediate work-products.
2
3 use crate::persist::fs::*;
4 use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
5 use rustc::session::Session;
6 use rustc_fs_util::link_or_copy;
7 use std::path::PathBuf;
8 use std::fs as std_fs;
9
10 pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
11 sess: &Session,
12 cgu_name: &str,
13 files: &[(WorkProductFileKind, PathBuf)]
14 ) -> Option<(WorkProductId, WorkProduct)> {
15 debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})",
16 cgu_name,
17 files);
18 if sess.opts.incremental.is_none() {
19 return None
20 }
21
22 let saved_files =
23 files.iter()
24 .map(|&(kind, ref path)| {
25 let extension = match kind {
26 WorkProductFileKind::Object => "o",
27 WorkProductFileKind::Bytecode => "bc",
28 WorkProductFileKind::BytecodeCompressed => "bc.z",
29 };
30 let file_name = format!("{}.{}", cgu_name, extension);
31 let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
32 match link_or_copy(path, &path_in_incr_dir) {
33 Ok(_) => Some((kind, file_name)),
34 Err(err) => {
35 sess.warn(&format!("error copying object file `{}` \
36 to incremental directory as `{}`: {}",
37 path.display(),
38 path_in_incr_dir.display(),
39 err));
40 None
41 }
42 }
43 })
44 .collect::<Option<Vec<_>>>()?;
45
46 let work_product = WorkProduct {
47 cgu_name: cgu_name.to_string(),
48 saved_files,
49 };
50
51 let work_product_id = WorkProductId::from_cgu_name(cgu_name);
52 Some((work_product_id, work_product))
53 }
54
55 pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
56 for &(_, ref file_name) in &work_product.saved_files {
57 let path = in_incr_comp_dir_sess(sess, file_name);
58 match std_fs::remove_file(&path) {
59 Ok(()) => { }
60 Err(err) => {
61 sess.warn(
62 &format!("file-system error deleting outdated file `{}`: {}",
63 path.display(), err));
64 }
65 }
66 }
67 }