1 //! This module contains files for saving intermediate work-products.
3 use crate::persist
::fs
::*;
4 use rustc
::dep_graph
::{WorkProduct, WorkProductFileKind, WorkProductId}
;
5 use rustc
::session
::Session
;
6 use rustc_fs_util
::link_or_copy
;
8 use std
::path
::PathBuf
;
10 pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
13 files
: &[(WorkProductFileKind
, PathBuf
)],
14 ) -> Option
<(WorkProductId
, WorkProduct
)> {
15 debug
!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name
, files
);
16 if sess
.opts
.incremental
.is_none() {
20 let saved_files
= files
22 .map(|&(kind
, ref path
)| {
23 let extension
= match kind
{
24 WorkProductFileKind
::Object
=> "o",
25 WorkProductFileKind
::Bytecode
=> "bc",
26 WorkProductFileKind
::BytecodeCompressed
=> "bc.z",
28 let file_name
= format
!("{}.{}", cgu_name
, extension
);
29 let path_in_incr_dir
= in_incr_comp_dir_sess(sess
, &file_name
);
30 match link_or_copy(path
, &path_in_incr_dir
) {
31 Ok(_
) => Some((kind
, file_name
)),
34 "error copying object file `{}` \
35 to incremental directory as `{}`: {}",
37 path_in_incr_dir
.display(),
44 .collect
::<Option
<Vec
<_
>>>()?
;
46 let work_product
= WorkProduct { cgu_name: cgu_name.to_string(), saved_files }
;
48 let work_product_id
= WorkProductId
::from_cgu_name(cgu_name
);
49 Some((work_product_id
, work_product
))
52 pub fn delete_workproduct_files(sess
: &Session
, work_product
: &WorkProduct
) {
53 for &(_
, ref file_name
) in &work_product
.saved_files
{
54 let path
= in_incr_comp_dir_sess(sess
, file_name
);
55 match std_fs
::remove_file(&path
) {
59 "file-system error deleting outdated file `{}`: {}",