1+ //! Module for managing build stamp files.
2+ //!
3+ //! Contains the core implementation of how bootstrap utilizes stamp files on build processes.
4+
15use std:: path:: { Path , PathBuf } ;
26use std:: { fs, io} ;
37
@@ -6,34 +10,37 @@ use crate::core::config::TargetSelection;
610use crate :: utils:: helpers:: mtime;
711use crate :: { Compiler , Mode , t} ;
812
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.
915#[ derive( Clone ) ]
1016pub struct BuildStamp {
1117 path : PathBuf ,
1218 pub ( crate ) stamp : String ,
1319}
1420
15- impl From < BuildStamp > for PathBuf {
16- fn from ( value : BuildStamp ) -> Self {
17- value. path
18- }
19- }
20-
2121impl AsRef < Path > for BuildStamp {
2222 fn as_ref ( & self ) -> & Path {
2323 & self . path
2424 }
2525}
2626
2727impl 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.
2831 pub fn new ( dir : & Path ) -> Self {
2932 Self { path : dir. join ( ".stamp" ) , stamp : String :: new ( ) }
3033 }
3134
35+ /// Sets stamp content to the specified value.
3236 pub fn with_stamp < S : ToString > ( mut self , stamp : S ) -> Self {
3337 self . stamp = stamp. to_string ( ) ;
3438 self
3539 }
3640
41+ /// Adds a prefix to stamp's name.
42+ ///
43+ /// Prefix cannot start or end with a dot (`.`).
3744 pub fn with_prefix ( mut self , prefix : & str ) -> Self {
3845 assert ! (
3946 !prefix. starts_with( '.' ) && !prefix. ends_with( '.' ) ,
@@ -47,6 +54,7 @@ impl BuildStamp {
4754 self
4855 }
4956
57+ /// Removes the stamp file if it exists.
5058 pub fn remove ( & self ) -> io:: Result < ( ) > {
5159 match fs:: remove_file ( & self . path ) {
5260 Ok ( ( ) ) => Ok ( ( ) ) ,
@@ -60,10 +68,14 @@ impl BuildStamp {
6068 }
6169 }
6270
71+ /// Creates the stamp file.
6372 pub fn write ( & self ) -> io:: Result < ( ) > {
6473 fs:: write ( & self . path , & self . stamp )
6574 }
6675
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.
6779 pub fn is_up_to_date ( & self ) -> bool {
6880 match fs:: read ( & self . path ) {
6981 Ok ( h) => self . stamp . as_bytes ( ) == h. as_slice ( ) ,
0 commit comments