about summary refs log tree commit diff
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2025-01-09 10:33:30 +0300
committeronur-ozkan <work@onurozkan.dev>2025-01-12 08:43:05 +0300
commitc68c721b506b4dd2688eaad8dba40a0a4150a874 (patch)
tree3a58e5330db6f05327058cf58aa80b2254679813
parente3de3c767e5438016dcd909b51dc6262f9a1fd88 (diff)
downloadrust-c68c721b506b4dd2688eaad8dba40a0a4150a874.tar.gz
rust-c68c721b506b4dd2688eaad8dba40a0a4150a874.zip
migrate `HashStamp` to `BuildStamp`
Signed-off-by: onur-ozkan <work@onurozkan.dev>
-rw-r--r--src/bootstrap/src/core/build_steps/gcc.rs14
-rw-r--r--src/bootstrap/src/core/build_steps/llvm.rs35
-rw-r--r--src/bootstrap/src/utils/build_stamp.rs8
-rw-r--r--src/bootstrap/src/utils/helpers.rs38
4 files changed, 29 insertions, 66 deletions
diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs
index b950bec11fd..e67ad7b166e 100644
--- a/src/bootstrap/src/core/build_steps/gcc.rs
+++ b/src/bootstrap/src/core/build_steps/gcc.rs
@@ -14,12 +14,13 @@ use std::sync::OnceLock;
 
 use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
 use crate::core::config::TargetSelection;
+use crate::utils::build_stamp::BuildStamp;
 use crate::utils::exec::command;
-use crate::utils::helpers::{self, HashStamp, t};
+use crate::utils::helpers::{self, t};
 use crate::{Kind, generate_smart_stamp_hash};
 
 pub struct Meta {
-    stamp: HashStamp,
+    stamp: BuildStamp,
     out_dir: PathBuf,
     install_dir: PathBuf,
     root: PathBuf,
@@ -54,18 +55,17 @@ pub fn prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> Gc
         )
     });
 
-    let stamp = out_dir.join("gcc-finished-building");
-    let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
+    let stamp = BuildStamp::new(&out_dir).with_prefix("gcc").with_stamp(smart_stamp_hash);
 
-    if stamp.is_done() {
-        if stamp.hash.is_none() {
+    if stamp.is_up_to_date() {
+        if stamp.stamp.is_empty() {
             builder.info(
                 "Could not determine the GCC submodule commit hash. \
                      Assuming that an GCC rebuild is not necessary.",
             );
             builder.info(&format!(
                 "To force GCC to rebuild, remove the file `{}`",
-                stamp.path.display()
+                stamp.as_ref().display()
             ));
         }
         return GccBuildStatus::AlreadyBuilt;
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index be5b4057051..c4cbcd6bfed 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -20,9 +20,10 @@ use build_helper::git::get_closest_merge_commit;
 
 use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
 use crate::core::config::{Config, TargetSelection};
+use crate::utils::build_stamp::BuildStamp;
 use crate::utils::exec::command;
 use crate::utils::helpers::{
-    self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
+    self, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
 };
 use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
 
@@ -36,7 +37,7 @@ pub struct LlvmResult {
 }
 
 pub struct Meta {
-    stamp: HashStamp,
+    stamp: BuildStamp,
     res: LlvmResult,
     out_dir: PathBuf,
     root: String,
@@ -135,18 +136,17 @@ pub fn prebuilt_llvm_config(
         )
     });
 
-    let stamp = out_dir.join("llvm-finished-building");
-    let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
+    let stamp = BuildStamp::new(&out_dir).with_prefix("llvm").with_stamp(smart_stamp_hash);
 
-    if stamp.is_done() {
-        if stamp.hash.is_none() {
+    if stamp.is_up_to_date() {
+        if stamp.stamp.is_empty() {
             builder.info(
                 "Could not determine the LLVM submodule commit hash. \
                      Assuming that an LLVM rebuild is not necessary.",
             );
             builder.info(&format!(
                 "To force LLVM to rebuild, remove the file `{}`",
-                stamp.path.display()
+                stamp.as_ref().display()
             ));
         }
         return LlvmBuildStatus::AlreadyBuilt(res);
@@ -922,18 +922,17 @@ impl Step for Enzyme {
         });
 
         let out_dir = builder.enzyme_out(target);
-        let stamp = out_dir.join("enzyme-finished-building");
-        let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
+        let stamp = BuildStamp::new(&out_dir).with_prefix("enzyme").with_prefix(smart_stamp_hash);
 
-        if stamp.is_done() {
-            if stamp.hash.is_none() {
+        if stamp.is_up_to_date() {
+            if stamp.stamp.is_empty() {
                 builder.info(
                     "Could not determine the Enzyme submodule commit hash. \
                      Assuming that an Enzyme rebuild is not necessary.",
                 );
                 builder.info(&format!(
                     "To force Enzyme to rebuild, remove the file `{}`",
-                    stamp.path.display()
+                    stamp.as_ref().display()
                 ));
             }
             return out_dir;
@@ -1131,16 +1130,18 @@ impl Step for Sanitizers {
             return runtimes;
         }
 
-        let stamp = out_dir.join("sanitizers-finished-building");
-        let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
+        let stamp = BuildStamp::new(&out_dir)
+            .with_prefix("sanitizers")
+            .with_stamp(builder.in_tree_llvm_info.sha().map(String::from).unwrap_or_default());
 
-        if stamp.is_done() {
-            if stamp.hash.is_none() {
+        if stamp.is_up_to_date() {
+            if stamp.stamp.is_empty() {
                 builder.info(&format!(
                     "Rebuild sanitizers by removing the file `{}`",
-                    stamp.path.display()
+                    stamp.as_ref().display()
                 ));
             }
+
             return runtimes;
         }
 
diff --git a/src/bootstrap/src/utils/build_stamp.rs b/src/bootstrap/src/utils/build_stamp.rs
index 84eaab93ebc..67a9e9d1204 100644
--- a/src/bootstrap/src/utils/build_stamp.rs
+++ b/src/bootstrap/src/utils/build_stamp.rs
@@ -4,7 +4,7 @@ use std::{fs, io};
 #[derive(Clone)]
 pub struct BuildStamp {
     path: PathBuf,
-    stamp: String,
+    pub(crate) stamp: String,
 }
 
 impl From<BuildStamp> for PathBuf {
@@ -24,8 +24,8 @@ impl BuildStamp {
         Self { path: dir.join(".stamp"), stamp: String::new() }
     }
 
-    pub fn with_stamp(mut self, stamp: String) -> Self {
-        self.stamp = stamp;
+    pub fn with_stamp<S: ToString>(mut self, stamp: S) -> Self {
+        self.stamp = stamp.to_string();
         self
     }
 
@@ -42,7 +42,7 @@ impl BuildStamp {
         self
     }
 
-    pub fn remove(self) -> io::Result<()> {
+    pub fn remove(&self) -> io::Result<()> {
         match fs::remove_file(&self.path) {
             Ok(()) => Ok(()),
             Err(e) => {
diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs
index 42041bb5944..55797af4c61 100644
--- a/src/bootstrap/src/utils/helpers.rs
+++ b/src/bootstrap/src/utils/helpers.rs
@@ -598,41 +598,3 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Resu
     };
     f.set_times(times)
 }
-
-pub struct HashStamp {
-    pub path: PathBuf,
-    pub hash: Option<Vec<u8>>,
-}
-
-impl HashStamp {
-    pub fn new(path: PathBuf, hash: Option<&str>) -> Self {
-        HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
-    }
-
-    pub fn is_done(&self) -> bool {
-        match fs::read(&self.path) {
-            Ok(h) => self.hash.as_deref().unwrap_or(b"") == h.as_slice(),
-            Err(e) if e.kind() == io::ErrorKind::NotFound => false,
-            Err(e) => {
-                panic!("failed to read stamp file `{}`: {}", self.path.display(), e);
-            }
-        }
-    }
-
-    pub fn remove(&self) -> io::Result<()> {
-        match fs::remove_file(&self.path) {
-            Ok(()) => Ok(()),
-            Err(e) => {
-                if e.kind() == io::ErrorKind::NotFound {
-                    Ok(())
-                } else {
-                    Err(e)
-                }
-            }
-        }
-    }
-
-    pub fn write(&self) -> io::Result<()> {
-        fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
-    }
-}