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