]>
Commit | Line | Data |
---|---|---|
5bcae85e SL |
1 | //! This module contains files for saving intermediate work-products. |
2 | ||
9fa01778 | 3 | use crate::persist::fs::*; |
b7449926 | 4 | use rustc_fs_util::link_or_copy; |
f9f354fc | 5 | use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; |
ba9703b0 | 6 | use rustc_session::Session; |
32a655c1 | 7 | use std::fs as std_fs; |
dfeec247 | 8 | use std::path::PathBuf; |
5bcae85e | 9 | |
f9f354fc | 10 | pub fn copy_cgu_workproduct_to_incr_comp_cache_dir( |
94b46f34 XL |
11 | sess: &Session, |
12 | cgu_name: &str, | |
f9f354fc | 13 | path: &Option<PathBuf>, |
94b46f34 | 14 | ) -> Option<(WorkProductId, WorkProduct)> { |
f9f354fc | 15 | debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path); |
74b04a01 | 16 | sess.opts.incremental.as_ref()?; |
5bcae85e | 17 | |
f9f354fc XL |
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; | |
dfeec247 | 31 | } |
f9f354fc XL |
32 | } |
33 | } else { | |
34 | None | |
35 | }; | |
5bcae85e | 36 | |
f9f354fc | 37 | let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file }; |
5bcae85e | 38 | |
94b46f34 XL |
39 | let work_product_id = WorkProductId::from_cgu_name(cgu_name); |
40 | Some((work_product_id, work_product)) | |
5bcae85e | 41 | } |
32a655c1 SL |
42 | |
43 | pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) { | |
f9f354fc | 44 | if let Some(ref file_name) = work_product.saved_file { |
32a655c1 SL |
45 | let path = in_incr_comp_dir_sess(sess, file_name); |
46 | match std_fs::remove_file(&path) { | |
dfeec247 | 47 | Ok(()) => {} |
32a655c1 | 48 | Err(err) => { |
dfeec247 XL |
49 | sess.warn(&format!( |
50 | "file-system error deleting outdated file `{}`: {}", | |
51 | path.display(), | |
52 | err | |
53 | )); | |
32a655c1 SL |
54 | } |
55 | } | |
56 | } | |
57 | } |