]> git.proxmox.com Git - rustc.git/blame - src/librustc_incremental/persist/work_product.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_incremental / persist / work_product.rs
CommitLineData
5bcae85e
SL
1//! This module contains files for saving intermediate work-products.
2
9fa01778 3use crate::persist::fs::*;
b7449926 4use rustc_fs_util::link_or_copy;
ba9703b0
XL
5use rustc_middle::dep_graph::{WorkProduct, WorkProductFileKind, WorkProductId};
6use rustc_session::Session;
32a655c1 7use std::fs as std_fs;
dfeec247 8use std::path::PathBuf;
5bcae85e 9
94b46f34
XL
10pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
11 sess: &Session,
12 cgu_name: &str,
dfeec247 13 files: &[(WorkProductFileKind, PathBuf)],
94b46f34 14) -> Option<(WorkProductId, WorkProduct)> {
dfeec247 15 debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
74b04a01 16 sess.opts.incremental.as_ref()?;
5bcae85e 17
dfeec247
XL
18 let saved_files = files
19 .iter()
20 .map(|&(kind, ref path)| {
21 let extension = match kind {
22 WorkProductFileKind::Object => "o",
23 WorkProductFileKind::Bytecode => "bc",
24 WorkProductFileKind::BytecodeCompressed => "bc.z",
25 };
26 let file_name = format!("{}.{}", cgu_name, extension);
27 let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
28 match link_or_copy(path, &path_in_incr_dir) {
29 Ok(_) => Some((kind, file_name)),
30 Err(err) => {
31 sess.warn(&format!(
32 "error copying object file `{}` \
5bcae85e 33 to incremental directory as `{}`: {}",
dfeec247
XL
34 path.display(),
35 path_in_incr_dir.display(),
36 err
37 ));
38 None
39 }
40 }
41 })
42 .collect::<Option<Vec<_>>>()?;
5bcae85e 43
dfeec247 44 let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
5bcae85e 45
94b46f34
XL
46 let work_product_id = WorkProductId::from_cgu_name(cgu_name);
47 Some((work_product_id, work_product))
5bcae85e 48}
32a655c1
SL
49
50pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
51 for &(_, ref file_name) in &work_product.saved_files {
52 let path = in_incr_comp_dir_sess(sess, file_name);
53 match std_fs::remove_file(&path) {
dfeec247 54 Ok(()) => {}
32a655c1 55 Err(err) => {
dfeec247
XL
56 sess.warn(&format!(
57 "file-system error deleting outdated file `{}`: {}",
58 path.display(),
59 err
60 ));
32a655c1
SL
61 }
62 }
63 }
64}