Move HashStamp to helpers
This commit is contained in:
parent
6db83ef8eb
commit
2c4aa2960e
@ -12,11 +12,10 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use super::llvm::HashStamp;
|
||||
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
|
||||
use crate::core::config::TargetSelection;
|
||||
use crate::utils::exec::command;
|
||||
use crate::utils::helpers::{self, t};
|
||||
use crate::utils::helpers::{self, t, HashStamp};
|
||||
use crate::{generate_smart_stamp_hash, Kind};
|
||||
|
||||
pub struct Meta {
|
||||
|
@ -8,12 +8,12 @@
|
||||
//! LLVM and compiler-rt are essentially just wired up to everything else to
|
||||
//! ensure that they're always in place if needed.
|
||||
|
||||
use std::env;
|
||||
use std::env::consts::EXE_EXTENSION;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::OnceLock;
|
||||
use std::{env, io};
|
||||
|
||||
use build_helper::ci::CiEnv;
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
use crate::utils::channel;
|
||||
use crate::utils::exec::command;
|
||||
use crate::utils::helpers::{
|
||||
self, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
|
||||
self, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date, HashStamp,
|
||||
};
|
||||
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
|
||||
|
||||
@ -1242,44 +1242,6 @@ fn supported_sanitizers(
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct HashStamp {
|
||||
pub(super) path: PathBuf,
|
||||
pub(super) hash: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl HashStamp {
|
||||
pub(super) fn new(path: PathBuf, hash: Option<&str>) -> Self {
|
||||
HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
|
||||
}
|
||||
|
||||
pub(super) 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(super) 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(super) fn write(&self) -> io::Result<()> {
|
||||
fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct CrtBeginEnd {
|
||||
pub target: TargetSelection,
|
||||
|
@ -556,3 +556,41 @@ 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""))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user