Skip to content

Commit 2c4aa29

Browse files
Move HashStamp to helpers
1 parent 6db83ef commit 2c4aa29

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use std::fs;
1212
use std::path::PathBuf;
1313
use std::sync::OnceLock;
1414

15-
use super::llvm::HashStamp;
1615
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1716
use crate::core::config::TargetSelection;
1817
use crate::utils::exec::command;
19-
use crate::utils::helpers::{self, t};
18+
use crate::utils::helpers::{self, t, HashStamp};
2019
use crate::{generate_smart_stamp_hash, Kind};
2120

2221
pub struct Meta {

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

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
//! LLVM and compiler-rt are essentially just wired up to everything else to
99
//! ensure that they're always in place if needed.
1010
11+
use std::env;
1112
use std::env::consts::EXE_EXTENSION;
1213
use std::ffi::{OsStr, OsString};
1314
use std::fs::{self, File};
1415
use std::path::{Path, PathBuf};
1516
use std::sync::OnceLock;
16-
use std::{env, io};
1717

1818
use build_helper::ci::CiEnv;
1919

@@ -22,7 +22,7 @@ use crate::core::config::{Config, TargetSelection};
2222
use crate::utils::channel;
2323
use crate::utils::exec::command;
2424
use crate::utils::helpers::{
25-
self, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
25+
self, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date, HashStamp,
2626
};
2727
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2828

@@ -1242,44 +1242,6 @@ fn supported_sanitizers(
12421242
}
12431243
}
12441244

1245-
pub(super) struct HashStamp {
1246-
pub(super) path: PathBuf,
1247-
pub(super) hash: Option<Vec<u8>>,
1248-
}
1249-
1250-
impl HashStamp {
1251-
pub(super) fn new(path: PathBuf, hash: Option<&str>) -> Self {
1252-
HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
1253-
}
1254-
1255-
pub(super) fn is_done(&self) -> bool {
1256-
match fs::read(&self.path) {
1257-
Ok(h) => self.hash.as_deref().unwrap_or(b"") == h.as_slice(),
1258-
Err(e) if e.kind() == io::ErrorKind::NotFound => false,
1259-
Err(e) => {
1260-
panic!("failed to read stamp file `{}`: {}", self.path.display(), e);
1261-
}
1262-
}
1263-
}
1264-
1265-
pub(super) fn remove(&self) -> io::Result<()> {
1266-
match fs::remove_file(&self.path) {
1267-
Ok(()) => Ok(()),
1268-
Err(e) => {
1269-
if e.kind() == io::ErrorKind::NotFound {
1270-
Ok(())
1271-
} else {
1272-
Err(e)
1273-
}
1274-
}
1275-
}
1276-
}
1277-
1278-
pub(super) fn write(&self) -> io::Result<()> {
1279-
fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
1280-
}
1281-
}
1282-
12831245
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12841246
pub struct CrtBeginEnd {
12851247
pub target: TargetSelection,

src/bootstrap/src/utils/helpers.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,41 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Resu
556556
};
557557
f.set_times(times)
558558
}
559+
560+
pub struct HashStamp {
561+
pub path: PathBuf,
562+
pub hash: Option<Vec<u8>>,
563+
}
564+
565+
impl HashStamp {
566+
pub fn new(path: PathBuf, hash: Option<&str>) -> Self {
567+
HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
568+
}
569+
570+
pub fn is_done(&self) -> bool {
571+
match fs::read(&self.path) {
572+
Ok(h) => self.hash.as_deref().unwrap_or(b"") == h.as_slice(),
573+
Err(e) if e.kind() == io::ErrorKind::NotFound => false,
574+
Err(e) => {
575+
panic!("failed to read stamp file `{}`: {}", self.path.display(), e);
576+
}
577+
}
578+
}
579+
580+
pub fn remove(&self) -> io::Result<()> {
581+
match fs::remove_file(&self.path) {
582+
Ok(()) => Ok(()),
583+
Err(e) => {
584+
if e.kind() == io::ErrorKind::NotFound {
585+
Ok(())
586+
} else {
587+
Err(e)
588+
}
589+
}
590+
}
591+
}
592+
593+
pub fn write(&self) -> io::Result<()> {
594+
fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
595+
}
596+
}

0 commit comments

Comments
 (0)