]>
Commit | Line | Data |
---|---|---|
a2a8927a XL |
1 | //! Functions for saving and removing intermediate [work products]. |
2 | //! | |
3 | //! [work products]: WorkProduct | |
5bcae85e | 4 | |
9fa01778 | 5 | use crate::persist::fs::*; |
b7449926 | 6 | use rustc_fs_util::link_or_copy; |
f9f354fc | 7 | use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; |
ba9703b0 | 8 | use rustc_session::Session; |
32a655c1 | 9 | use std::fs as std_fs; |
dfeec247 | 10 | use std::path::PathBuf; |
5bcae85e | 11 | |
a2a8927a | 12 | /// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it. |
f9f354fc | 13 | pub fn copy_cgu_workproduct_to_incr_comp_cache_dir( |
94b46f34 XL |
14 | sess: &Session, |
15 | cgu_name: &str, | |
f9f354fc | 16 | path: &Option<PathBuf>, |
94b46f34 | 17 | ) -> Option<(WorkProductId, WorkProduct)> { |
f9f354fc | 18 | debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path); |
74b04a01 | 19 | sess.opts.incremental.as_ref()?; |
5bcae85e | 20 | |
f9f354fc XL |
21 | let saved_file = if let Some(path) = path { |
22 | let file_name = format!("{}.o", cgu_name); | |
23 | let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name); | |
24 | match link_or_copy(path, &path_in_incr_dir) { | |
25 | Ok(_) => Some(file_name), | |
26 | Err(err) => { | |
27 | sess.warn(&format!( | |
28 | "error copying object file `{}` to incremental directory as `{}`: {}", | |
29 | path.display(), | |
30 | path_in_incr_dir.display(), | |
31 | err | |
32 | )); | |
33 | return None; | |
dfeec247 | 34 | } |
f9f354fc XL |
35 | } |
36 | } else { | |
37 | None | |
38 | }; | |
5bcae85e | 39 | |
f9f354fc | 40 | let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file }; |
5bcae85e | 41 | |
94b46f34 XL |
42 | let work_product_id = WorkProductId::from_cgu_name(cgu_name); |
43 | Some((work_product_id, work_product)) | |
5bcae85e | 44 | } |
32a655c1 | 45 | |
a2a8927a | 46 | /// Removes files for a given work product. |
32a655c1 | 47 | pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) { |
f9f354fc | 48 | if let Some(ref file_name) = work_product.saved_file { |
32a655c1 SL |
49 | let path = in_incr_comp_dir_sess(sess, file_name); |
50 | match std_fs::remove_file(&path) { | |
dfeec247 | 51 | Ok(()) => {} |
32a655c1 | 52 | Err(err) => { |
dfeec247 XL |
53 | sess.warn(&format!( |
54 | "file-system error deleting outdated file `{}`: {}", | |
55 | path.display(), | |
56 | err | |
57 | )); | |
32a655c1 SL |
58 | } |
59 | } | |
60 | } | |
61 | } |