Skip to content

Commit c68c721

Browse files
committed
migrate HashStamp to BuildStamp
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent e3de3c7 commit c68c721

File tree

4 files changed

+29
-66
lines changed

4 files changed

+29
-66
lines changed

src/bootstrap/src/core/build_steps/gcc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use std::sync::OnceLock;
1414

1515
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1616
use crate::core::config::TargetSelection;
17+
use crate::utils::build_stamp::BuildStamp;
1718
use crate::utils::exec::command;
18-
use crate::utils::helpers::{self, HashStamp, t};
19+
use crate::utils::helpers::{self, t};
1920
use crate::{Kind, generate_smart_stamp_hash};
2021

2122
pub struct Meta {
22-
stamp: HashStamp,
23+
stamp: BuildStamp,
2324
out_dir: PathBuf,
2425
install_dir: PathBuf,
2526
root: PathBuf,
@@ -54,18 +55,17 @@ pub fn prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> Gc
5455
)
5556
});
5657

57-
let stamp = out_dir.join("gcc-finished-building");
58-
let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
58+
let stamp = BuildStamp::new(&out_dir).with_prefix("gcc").with_stamp(smart_stamp_hash);
5959

60-
if stamp.is_done() {
61-
if stamp.hash.is_none() {
60+
if stamp.is_up_to_date() {
61+
if stamp.stamp.is_empty() {
6262
builder.info(
6363
"Could not determine the GCC submodule commit hash. \
6464
Assuming that an GCC rebuild is not necessary.",
6565
);
6666
builder.info(&format!(
6767
"To force GCC to rebuild, remove the file `{}`",
68-
stamp.path.display()
68+
stamp.as_ref().display()
6969
));
7070
}
7171
return GccBuildStatus::AlreadyBuilt;

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ use build_helper::git::get_closest_merge_commit;
2020

2121
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2222
use crate::core::config::{Config, TargetSelection};
23+
use crate::utils::build_stamp::BuildStamp;
2324
use crate::utils::exec::command;
2425
use crate::utils::helpers::{
25-
self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
26+
self, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
2627
};
2728
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
2829

@@ -36,7 +37,7 @@ pub struct LlvmResult {
3637
}
3738

3839
pub struct Meta {
39-
stamp: HashStamp,
40+
stamp: BuildStamp,
4041
res: LlvmResult,
4142
out_dir: PathBuf,
4243
root: String,
@@ -135,18 +136,17 @@ pub fn prebuilt_llvm_config(
135136
)
136137
});
137138

138-
let stamp = out_dir.join("llvm-finished-building");
139-
let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
139+
let stamp = BuildStamp::new(&out_dir).with_prefix("llvm").with_stamp(smart_stamp_hash);
140140

141-
if stamp.is_done() {
142-
if stamp.hash.is_none() {
141+
if stamp.is_up_to_date() {
142+
if stamp.stamp.is_empty() {
143143
builder.info(
144144
"Could not determine the LLVM submodule commit hash. \
145145
Assuming that an LLVM rebuild is not necessary.",
146146
);
147147
builder.info(&format!(
148148
"To force LLVM to rebuild, remove the file `{}`",
149-
stamp.path.display()
149+
stamp.as_ref().display()
150150
));
151151
}
152152
return LlvmBuildStatus::AlreadyBuilt(res);
@@ -922,18 +922,17 @@ impl Step for Enzyme {
922922
});
923923

924924
let out_dir = builder.enzyme_out(target);
925-
let stamp = out_dir.join("enzyme-finished-building");
926-
let stamp = HashStamp::new(stamp, Some(smart_stamp_hash));
925+
let stamp = BuildStamp::new(&out_dir).with_prefix("enzyme").with_prefix(smart_stamp_hash);
927926

928-
if stamp.is_done() {
929-
if stamp.hash.is_none() {
927+
if stamp.is_up_to_date() {
928+
if stamp.stamp.is_empty() {
930929
builder.info(
931930
"Could not determine the Enzyme submodule commit hash. \
932931
Assuming that an Enzyme rebuild is not necessary.",
933932
);
934933
builder.info(&format!(
935934
"To force Enzyme to rebuild, remove the file `{}`",
936-
stamp.path.display()
935+
stamp.as_ref().display()
937936
));
938937
}
939938
return out_dir;
@@ -1131,16 +1130,18 @@ impl Step for Sanitizers {
11311130
return runtimes;
11321131
}
11331132

1134-
let stamp = out_dir.join("sanitizers-finished-building");
1135-
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
1133+
let stamp = BuildStamp::new(&out_dir)
1134+
.with_prefix("sanitizers")
1135+
.with_stamp(builder.in_tree_llvm_info.sha().map(String::from).unwrap_or_default());
11361136

1137-
if stamp.is_done() {
1138-
if stamp.hash.is_none() {
1137+
if stamp.is_up_to_date() {
1138+
if stamp.stamp.is_empty() {
11391139
builder.info(&format!(
11401140
"Rebuild sanitizers by removing the file `{}`",
1141-
stamp.path.display()
1141+
stamp.as_ref().display()
11421142
));
11431143
}
1144+
11441145
return runtimes;
11451146
}
11461147

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fs, io};
44
#[derive(Clone)]
55
pub struct BuildStamp {
66
path: PathBuf,
7-
stamp: String,
7+
pub(crate) stamp: String,
88
}
99

1010
impl From<BuildStamp> for PathBuf {
@@ -24,8 +24,8 @@ impl BuildStamp {
2424
Self { path: dir.join(".stamp"), stamp: String::new() }
2525
}
2626

27-
pub fn with_stamp(mut self, stamp: String) -> Self {
28-
self.stamp = stamp;
27+
pub fn with_stamp<S: ToString>(mut self, stamp: S) -> Self {
28+
self.stamp = stamp.to_string();
2929
self
3030
}
3131

@@ -42,7 +42,7 @@ impl BuildStamp {
4242
self
4343
}
4444

45-
pub fn remove(self) -> io::Result<()> {
45+
pub fn remove(&self) -> io::Result<()> {
4646
match fs::remove_file(&self.path) {
4747
Ok(()) => Ok(()),
4848
Err(e) => {

src/bootstrap/src/utils/helpers.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -598,41 +598,3 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Resu
598598
};
599599
f.set_times(times)
600600
}
601-
602-
pub struct HashStamp {
603-
pub path: PathBuf,
604-
pub hash: Option<Vec<u8>>,
605-
}
606-
607-
impl HashStamp {
608-
pub fn new(path: PathBuf, hash: Option<&str>) -> Self {
609-
HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
610-
}
611-
612-
pub fn is_done(&self) -> bool {
613-
match fs::read(&self.path) {
614-
Ok(h) => self.hash.as_deref().unwrap_or(b"") == h.as_slice(),
615-
Err(e) if e.kind() == io::ErrorKind::NotFound => false,
616-
Err(e) => {
617-
panic!("failed to read stamp file `{}`: {}", self.path.display(), e);
618-
}
619-
}
620-
}
621-
622-
pub fn remove(&self) -> io::Result<()> {
623-
match fs::remove_file(&self.path) {
624-
Ok(()) => Ok(()),
625-
Err(e) => {
626-
if e.kind() == io::ErrorKind::NotFound {
627-
Ok(())
628-
} else {
629-
Err(e)
630-
}
631-
}
632-
}
633-
}
634-
635-
pub fn write(&self) -> io::Result<()> {
636-
fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
637-
}
638-
}

0 commit comments

Comments
 (0)