1
+ //! Module for managing build stamp files.
2
+ //!
3
+ //! Contains the core implementation of how bootstrap utilizes stamp files on build processes.
4
+
1
5
use std:: path:: { Path , PathBuf } ;
2
6
use std:: { fs, io} ;
3
7
@@ -6,34 +10,37 @@ use crate::core::config::TargetSelection;
6
10
use crate :: utils:: helpers:: mtime;
7
11
use crate :: { Compiler , Mode , t} ;
8
12
13
+ /// Manages a stamp file to track build state. The file is created in the given
14
+ /// directory and can have custom content and name.
9
15
#[ derive( Clone ) ]
10
16
pub struct BuildStamp {
11
17
path : PathBuf ,
12
18
pub ( crate ) stamp : String ,
13
19
}
14
20
15
- impl From < BuildStamp > for PathBuf {
16
- fn from ( value : BuildStamp ) -> Self {
17
- value. path
18
- }
19
- }
20
-
21
21
impl AsRef < Path > for BuildStamp {
22
22
fn as_ref ( & self ) -> & Path {
23
23
& self . path
24
24
}
25
25
}
26
26
27
27
impl BuildStamp {
28
+ /// Creates a new `BuildStamp` for a given directory.
29
+ ///
30
+ /// By default, stamp will be an empty file named `.stamp` within the specified directory.
28
31
pub fn new ( dir : & Path ) -> Self {
29
32
Self { path : dir. join ( ".stamp" ) , stamp : String :: new ( ) }
30
33
}
31
34
35
+ /// Sets stamp content to the specified value.
32
36
pub fn with_stamp < S : ToString > ( mut self , stamp : S ) -> Self {
33
37
self . stamp = stamp. to_string ( ) ;
34
38
self
35
39
}
36
40
41
+ /// Adds a prefix to stamp's name.
42
+ ///
43
+ /// Prefix cannot start or end with a dot (`.`).
37
44
pub fn with_prefix ( mut self , prefix : & str ) -> Self {
38
45
assert ! (
39
46
!prefix. starts_with( '.' ) && !prefix. ends_with( '.' ) ,
@@ -47,6 +54,7 @@ impl BuildStamp {
47
54
self
48
55
}
49
56
57
+ /// Removes the stamp file if it exists.
50
58
pub fn remove ( & self ) -> io:: Result < ( ) > {
51
59
match fs:: remove_file ( & self . path ) {
52
60
Ok ( ( ) ) => Ok ( ( ) ) ,
@@ -60,10 +68,14 @@ impl BuildStamp {
60
68
}
61
69
}
62
70
71
+ /// Creates the stamp file.
63
72
pub fn write ( & self ) -> io:: Result < ( ) > {
64
73
fs:: write ( & self . path , & self . stamp )
65
74
}
66
75
76
+ /// Checks if the stamp file is up-to-date.
77
+ ///
78
+ /// It is considered up-to-date if file content matches with the stamp string.
67
79
pub fn is_up_to_date ( & self ) -> bool {
68
80
match fs:: read ( & self . path ) {
69
81
Ok ( h) => self . stamp . as_bytes ( ) == h. as_slice ( ) ,
0 commit comments