diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-08-12 16:54:07 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-09-06 16:01:47 +0200 |
| commit | 2c4aa2960e57eace72ac3fc310faf5a59d5e2305 (patch) | |
| tree | 26a31f742c15aba3b5aa67ff9f579839010f3959 | |
| parent | 6db83ef8eb62e9ac1dd44e8ce31568324acad6d7 (diff) | |
| download | rust-2c4aa2960e57eace72ac3fc310faf5a59d5e2305.tar.gz rust-2c4aa2960e57eace72ac3fc310faf5a59d5e2305.zip | |
Move HashStamp to helpers
| -rw-r--r-- | src/bootstrap/src/core/build_steps/gcc.rs | 3 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/llvm.rs | 42 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/helpers.rs | 38 |
3 files changed, 41 insertions, 42 deletions
diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs index 8c0257522c9..a9cdf2414f4 100644 --- a/src/bootstrap/src/core/build_steps/gcc.rs +++ b/src/bootstrap/src/core/build_steps/gcc.rs @@ -12,11 +12,10 @@ use std::fs; 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 { diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index d729952adce..50d0cffd36c 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -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::core::config::{Config, TargetSelection}; 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, diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index a856c99ff55..11e01190189 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -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"")) + } +} |
