]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_incremental/src/persist/work_product.rs
Auto merge of #87252 - RalfJung:miri, r=RalfJung
[rust.git] / compiler / rustc_incremental / src / persist / work_product.rs
1 //! This module contains files for saving intermediate work-products.
2
3 use crate::persist::fs::*;
4 use rustc_fs_util::link_or_copy;
5 use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
6 use rustc_session::Session;
7 use std::fs as std_fs;
8 use std::path::PathBuf;
9
10 pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
11     sess: &Session,
12     cgu_name: &str,
13     path: &Option<PathBuf>,
14 ) -> Option<(WorkProductId, WorkProduct)> {
15     debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
16     sess.opts.incremental.as_ref()?;
17
18     let saved_file = if let Some(path) = path {
19         let file_name = format!("{}.o", cgu_name);
20         let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
21         match link_or_copy(path, &path_in_incr_dir) {
22             Ok(_) => Some(file_name),
23             Err(err) => {
24                 sess.warn(&format!(
25                     "error copying object file `{}` to incremental directory as `{}`: {}",
26                     path.display(),
27                     path_in_incr_dir.display(),
28                     err
29                 ));
30                 return None;
31             }
32         }
33     } else {
34         None
35     };
36
37     let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
38
39     let work_product_id = WorkProductId::from_cgu_name(cgu_name);
40     Some((work_product_id, work_product))
41 }
42
43 pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
44     if let Some(ref file_name) = work_product.saved_file {
45         let path = in_incr_comp_dir_sess(sess, file_name);
46         match std_fs::remove_file(&path) {
47             Ok(()) => {}
48             Err(err) => {
49                 sess.warn(&format!(
50                     "file-system error deleting outdated file `{}`: {}",
51                     path.display(),
52                     err
53                 ));
54             }
55         }
56     }
57 }