11//! What a task can rebuild, so a later run may find it missing.
22//!
3- //! Inputs are fingerprinted as the task left them, so they include the files
4- //! a task read and then wrote, such as a tool's cache file. A clean checkout
5- //! (CI, a fresh clone) doesn't have those files yet, and running the task
6- //! would write them again, so a later run may find them missing. A file that
7- //! is there must still be as the task left it.
3+ //! Inputs are fingerprinted as the task left them, including files it read
4+ //! and then wrote. A rebuildable file may be missing on a later run, as on
5+ //! a clean checkout. A file that is there must still match the fingerprint.
86//!
9- //! The same goes for an empty folder the task made (built-in ignored paths
10- //! such as `.DS_Store` aside), and for a folder that holds only what the task
11- //! can rebuild: every file (or symlink) in it is one the task wrote, and every
12- //! folder in it is rebuildable too. None of these is fingerprinted at all. A hit
13- //! restores the files and the empty folders, which are archived as folders, if
14- //! they're among the task's outputs, and the files recreate the folders holding
15- //! them; explicit output config can leave them out. Such folders are found after
16- //! the run by climbing from the written paths and the empty folders through
17- //! their parent folders inside the workspace, listing each one once in the real
18- //! file system. A written path or folder that is gone by then plays no part. A
19- //! listing of any other folder leaves out its entries that the task can rebuild,
20- //! which a later run may find missing too.
7+ //! A folder is rebuildable when the task made it and it is empty, or when it
8+ //! contains at least one entry and all entries are rebuildable. Both checks
9+ //! skip built- in ignored entries such as `.DS_Store`. None of these is
10+ //! fingerprinted at all. A hit restores the files and the empty folders, which
11+ //! are archived as folders, if they're among the task's outputs, and the files
12+ //! recreate the folders holding them; explicit output config can leave them
13+ //! out. Such folders are found after the run by climbing from the written
14+ //! paths and the empty folders through their parent folders inside the
15+ //! workspace, listing each one once in the real file system. A written path or
16+ //! folder that is gone by then plays no part. A listing of any other folder
17+ //! leaves out its entries that the task can rebuild, which a later run may
18+ //! find missing too.
2119//!
22- //! The written paths are fspy's records before output exclusions and
23- //! tool-reported `ignoreOutput` paths are applied: those decide what is
24- //! archived, not what the task can rebuild. A rename target that is a folder
25- //! after the run, like Vite's `deps` folder renamed into place, stands for
26- //! writes of every file (and symlink) under it; the folder itself and the
27- //! folders in it don't count as written. The archive takes those files like
28- //! any written file. The rename's source, like Vite's `deps_temp_*` folder,
29- //! isn't recorded, but a path that is gone after the run and that the task
30- //! wrote in counts as written: the task made or removed it. It is
31- //! fingerprinted as missing, which a later run must match either way, so this
20+ //! The written paths come from fspy. A file the task reads and writes is a
21+ //! required input when `ignoreOutput` covers it and the read survives input
22+ //! filtering. Its absence makes the next run miss. Output negative globs
23+ //! only decide what is archived.
24+ //!
25+ //! A rename target that is a folder after the run, like Vite's `deps` folder
26+ //! renamed into place, stands for writes of every file (and symlink) under
27+ //! it. The folder itself and the folders in it don't count as written.
28+ //! The archive takes those files like any written file. The rename's source,
29+ //! like Vite's `deps_temp_*` folder, isn't recorded. A path that is gone after
30+ //! the run counts as written if the task wrote in it. It is fingerprinted
31+ //! as missing, which a later run must match either way, so this
3232//! only tells it apart from a path the task looked for and didn't find. A
3333//! write record on a path that is a folder, from opening it with write
3434//! access, is ignored. A mkdir record counts only for a folder that is empty
@@ -45,12 +45,12 @@ use vt_path::{AbsolutePath, RelativePath, RelativePathBuf};
4545
4646use super :: { fingerprint:: PathFingerprint , ignored_paths:: IgnoredDirEntries } ;
4747
48- /// The paths a task wrote, the empty folders it made, and the folders
49- /// holding only what it can rebuild, relative to the workspace root.
48+ /// The rebuildable paths a task wrote, the empty folders it made, and the
49+ /// folders holding only what it can rebuild, relative to the workspace root.
5050#[ derive( Debug , Default ) ]
5151pub struct Rebuildable {
5252 written : FxHashSet < RelativePathBuf > ,
53- /// The folders the task made, or tried to make, inside the workspace .
53+ /// The folders the task made or tried to make, excluding required paths .
5454 mkdirs : FxHashSet < RelativePathBuf > ,
5555 /// The `mkdirs` that are empty folders.
5656 empty_folders : FxHashSet < RelativePathBuf > ,
@@ -61,19 +61,17 @@ pub struct Rebuildable {
6161}
6262
6363impl Rebuildable {
64- /// Takes the `written` paths and the `rename_targets` as written, with the
65- /// files under a renamed folder in place of the folder, by looking under
66- /// `workspace_root`, which must be done after the run, and the `mkdirs`.
64+ /// Takes the rebuildable `written` paths and `mkdirs`.
6765 /// No folder is rebuildable, and none of the `mkdirs` is an empty folder,
68- /// until [`Self::with_folders`] or [`Self::with_empty_folders`] finds them.
69- pub fn new (
66+ /// until [`Self::with_folders_excluding`] or [`Self::with_empty_folders`] finds them.
67+ #[ cfg_attr(
68+ all( not( fspy) , not( test) ) ,
69+ expect( dead_code, reason = "only called when processing fspy path accesses" )
70+ ) ]
71+ pub ( super ) fn from_written (
7072 written : FxHashSet < RelativePathBuf > ,
71- rename_targets : FxHashSet < RelativePathBuf > ,
7273 mkdirs : FxHashSet < RelativePathBuf > ,
73- workspace_root : & AbsolutePath ,
74- cache_root : Option < & RelativePath > ,
7574 ) -> Self {
76- let written = files_written ( written, rename_targets, workspace_root, cache_root) ;
7775 let mut written_in = FxHashSet :: default ( ) ;
7876 for path in & written {
7977 let mut dir = path. parent ( ) ;
@@ -100,14 +98,19 @@ impl Rebuildable {
10098 /// the task made under `workspace_root`, which must be done after the run.
10199 /// Only fingerprints of the paths the task read ask about folders, so a
102100 /// run without such reads takes [`Self::with_empty_folders`] instead.
101+ #[ cfg_attr(
102+ all( not( fspy) , not( test) ) ,
103+ expect( dead_code, reason = "only called when processing fspy path accesses" )
104+ ) ]
103105 #[ must_use]
104- pub fn with_folders (
106+ pub ( super ) fn with_folders_excluding (
105107 mut self ,
106108 workspace_root : & AbsolutePath ,
107109 cache_root : Option < & RelativePath > ,
110+ required_writes : & FxHashSet < RelativePathBuf > ,
108111 ) -> Self {
109112 ( self . folders , self . empty_folders ) =
110- find_folders ( & self . written , & self . mkdirs , workspace_root, cache_root) ;
113+ find_folders ( & self . written , required_writes , & self . mkdirs , workspace_root, cache_root) ;
111114 self
112115 }
113116
@@ -129,8 +132,8 @@ impl Rebuildable {
129132 self
130133 }
131134
132- /// The paths the task wrote or renamed a file to, and the files under the
133- /// folders it renamed.
135+ /// The rebuildable paths the task wrote or renamed a file to, and the
136+ /// rebuildable files under the folders it renamed.
134137 pub const fn written ( & self ) -> & FxHashSet < RelativePathBuf > {
135138 & self . written
136139 }
@@ -141,12 +144,12 @@ impl Rebuildable {
141144 & self . empty_folders
142145 }
143146
144- /// Whether a later run may find ` path`, which a read found as
145- /// `fingerprint`, missing: the task wrote it, or it is gone after the run
146- /// and the task wrote in it . A write record on a folder, from opening it
147- /// with write access, is ignored. Only a written path that the read found
148- /// as a folder is stat'd under `workspace_root`, to tell a folder from a
149- /// link the task made to one.
147+ /// Whether a later run may find the path missing. A rebuildable write
148+ /// allows this. A post-run `NotFound` also allows it if the task has a
149+ /// rebuildable write below the path . A write record on a folder, from
150+ /// opening it with write access, is ignored. Only a written path that the
151+ /// read found as a folder is stat'd under `workspace_root`, to tell a
152+ /// folder from a link the task made to one.
150153 pub fn may_be_missing (
151154 & self ,
152155 path : & RelativePath ,
@@ -195,7 +198,11 @@ impl Rebuildable {
195198/// under it counts, folder entries are checked against the rebuildable
196199/// folders, and the archive skips folders, so only a read of it has to tell
197200/// (see [`Rebuildable::may_be_missing`]).
198- fn files_written (
201+ #[ cfg_attr(
202+ all( not( fspy) , not( test) ) ,
203+ expect( dead_code, reason = "only called when processing fspy path accesses" )
204+ ) ]
205+ pub ( super ) fn files_written (
199206 mut written : FxHashSet < RelativePathBuf > ,
200207 rename_targets : FxHashSet < RelativePathBuf > ,
201208 workspace_root : & AbsolutePath ,
@@ -276,8 +283,11 @@ fn is_empty_folder(
276283/// candidates too. Climbing stops at the first folder that isn't rebuildable,
277284/// since no folder above it can be, and at the workspace root. A folder that
278285/// is gone plays no part: its parent is decided by the entries it holds.
286+ /// Required writes are skipped so a tracked directory link stays required
287+ /// even if the task wrote through it.
279288fn find_folders (
280289 written : & FxHashSet < RelativePathBuf > ,
290+ required_writes : & FxHashSet < RelativePathBuf > ,
281291 mkdirs : & FxHashSet < RelativePathBuf > ,
282292 workspace_root : & AbsolutePath ,
283293 cache_root : Option < & RelativePath > ,
@@ -300,7 +310,8 @@ fn find_folders(
300310 empty_folders. insert ( dir. to_relative_path_buf ( ) ) ;
301311 }
302312 }
303- let mut candidates: Vec < & RelativePath > = candidates. into_iter ( ) . collect ( ) ;
313+ let mut candidates: Vec < & RelativePath > =
314+ candidates. into_iter ( ) . filter ( |dir| !required_writes. contains ( * dir) ) . collect ( ) ;
304315 sort_deepest_first ( & mut candidates) ;
305316
306317 let mut folders = empty_folders. clone ( ) ;
@@ -351,8 +362,7 @@ fn sort_deepest_first(dirs: &mut [&RelativePath]) {
351362/// aside, which don't count, as in directory listing fingerprints.
352363enum Holds {
353364 Nothing ,
354- /// At least one entry, each a file (or symlink) the task wrote or a
355- /// rebuildable folder.
365+ /// At least one entry, with every entry rebuildable.
356366 OnlyRebuildable ,
357367 /// Anything else, or entries that can't be read or named.
358368 Other ,
@@ -415,3 +425,27 @@ fn is_rebuildable(
415425) -> bool {
416426 if is_dir { folders. contains ( path) } else { written. contains ( path) }
417427}
428+
429+ #[ cfg( test) ]
430+ impl Rebuildable {
431+ pub ( super ) fn new (
432+ written : FxHashSet < RelativePathBuf > ,
433+ rename_targets : FxHashSet < RelativePathBuf > ,
434+ mkdirs : FxHashSet < RelativePathBuf > ,
435+ workspace_root : & AbsolutePath ,
436+ cache_root : Option < & RelativePath > ,
437+ ) -> Self {
438+ Self :: from_written (
439+ files_written ( written, rename_targets, workspace_root, cache_root) ,
440+ mkdirs,
441+ )
442+ }
443+
444+ pub ( super ) fn with_folders (
445+ self ,
446+ workspace_root : & AbsolutePath ,
447+ cache_root : Option < & RelativePath > ,
448+ ) -> Self {
449+ self . with_folders_excluding ( workspace_root, cache_root, & FxHashSet :: default ( ) )
450+ }
451+ }
0 commit comments