1 //! This module contains files for saving intermediate work-products.
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;
8 use std::path::PathBuf;
10 pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
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()?;
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),
25 "error copying object file `{}` to incremental directory as `{}`: {}",
27 path_in_incr_dir.display(),
37 let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
39 let work_product_id = WorkProductId::from_cgu_name(cgu_name);
40 Some((work_product_id, work_product))
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) {
50 "file-system error deleting outdated file `{}`: {}",