Skip to content

Commit 615131b

Browse files
committed
migrate generate_smart_stamp_hash
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent cacb4fe commit 615131b

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

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

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

15+
use crate::Kind;
1516
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1617
use crate::core::config::TargetSelection;
17-
use crate::utils::build_stamp::BuildStamp;
18+
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
1819
use crate::utils::exec::command;
1920
use crate::utils::helpers::{self, t};
20-
use crate::{Kind, generate_smart_stamp_hash};
2121

2222
pub struct Meta {
2323
stamp: BuildStamp,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ 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;
23+
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
2424
use crate::utils::exec::command;
2525
use crate::utils::helpers::{
2626
self, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
2727
};
28-
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
28+
use crate::{CLang, GitRepo, Kind};
2929

3030
#[derive(Clone)]
3131
pub struct LlvmResult {

src/bootstrap/src/lib.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ use std::{env, fs, io, str};
2727

2828
use build_helper::ci::gha;
2929
use build_helper::exit;
30-
use sha2::digest::Digest;
3130
use termcolor::{ColorChoice, StandardStream, WriteColor};
3231
use utils::build_stamp::BuildStamp;
3332
use utils::channel::GitInfo;
34-
use utils::helpers::hex_encode;
3533

3634
use crate::core::builder;
37-
use crate::core::builder::{Builder, Kind};
35+
use crate::core::builder::Kind;
3836
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, Target, TargetSelection, flags};
3937
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
4038
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, output, set_file_times, symlink_dir};
@@ -1902,52 +1900,6 @@ fn envify(s: &str) -> String {
19021900
.collect()
19031901
}
19041902

1905-
/// Computes a hash representing the state of a repository/submodule and additional input.
1906-
///
1907-
/// It uses `git diff` for the actual changes, and `git status` for including the untracked
1908-
/// files in the specified directory. The additional input is also incorporated into the
1909-
/// computation of the hash.
1910-
///
1911-
/// # Parameters
1912-
///
1913-
/// - `dir`: A reference to the directory path of the target repository/submodule.
1914-
/// - `additional_input`: An additional input to be included in the hash.
1915-
///
1916-
/// # Panics
1917-
///
1918-
/// In case of errors during `git` command execution (e.g., in tarball sources), default values
1919-
/// are used to prevent panics.
1920-
pub fn generate_smart_stamp_hash(
1921-
builder: &Builder<'_>,
1922-
dir: &Path,
1923-
additional_input: &str,
1924-
) -> String {
1925-
let diff = helpers::git(Some(dir))
1926-
.allow_failure()
1927-
.arg("diff")
1928-
.run_capture_stdout(builder)
1929-
.stdout_if_ok()
1930-
.unwrap_or_default();
1931-
1932-
let status = helpers::git(Some(dir))
1933-
.allow_failure()
1934-
.arg("status")
1935-
.arg("--porcelain")
1936-
.arg("-z")
1937-
.arg("--untracked-files=normal")
1938-
.run_capture_stdout(builder)
1939-
.stdout_if_ok()
1940-
.unwrap_or_default();
1941-
1942-
let mut hasher = sha2::Sha256::new();
1943-
1944-
hasher.update(diff);
1945-
hasher.update(status);
1946-
hasher.update(additional_input);
1947-
1948-
hex_encode(hasher.finalize().as_slice())
1949-
}
1950-
19511903
/// Ensures that the behavior dump directory is properly initialized.
19521904
pub fn prepare_behaviour_dump_dir(build: &Build) {
19531905
static INITIALIZED: OnceLock<bool> = OnceLock::new();

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
use std::path::{Path, PathBuf};
66
use std::{fs, io};
77

8+
use sha2::digest::Digest;
9+
810
use crate::core::builder::Builder;
911
use crate::core::config::TargetSelection;
10-
use crate::utils::helpers::mtime;
11-
use crate::{Compiler, Mode, t};
12+
use crate::utils::helpers::{hex_encode, mtime};
13+
use crate::{Compiler, Mode, helpers, t};
1214

1315
#[cfg(test)]
1416
mod tests;
@@ -139,3 +141,49 @@ pub fn librustc_stamp(
139141
) -> BuildStamp {
140142
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc")
141143
}
144+
145+
/// Computes a hash representing the state of a repository/submodule and additional input.
146+
///
147+
/// It uses `git diff` for the actual changes, and `git status` for including the untracked
148+
/// files in the specified directory. The additional input is also incorporated into the
149+
/// computation of the hash.
150+
///
151+
/// # Parameters
152+
///
153+
/// - `dir`: A reference to the directory path of the target repository/submodule.
154+
/// - `additional_input`: An additional input to be included in the hash.
155+
///
156+
/// # Panics
157+
///
158+
/// In case of errors during `git` command execution (e.g., in tarball sources), default values
159+
/// are used to prevent panics.
160+
pub fn generate_smart_stamp_hash(
161+
builder: &Builder<'_>,
162+
dir: &Path,
163+
additional_input: &str,
164+
) -> String {
165+
let diff = helpers::git(Some(dir))
166+
.allow_failure()
167+
.arg("diff")
168+
.run_capture_stdout(builder)
169+
.stdout_if_ok()
170+
.unwrap_or_default();
171+
172+
let status = helpers::git(Some(dir))
173+
.allow_failure()
174+
.arg("status")
175+
.arg("--porcelain")
176+
.arg("-z")
177+
.arg("--untracked-files=normal")
178+
.run_capture_stdout(builder)
179+
.stdout_if_ok()
180+
.unwrap_or_default();
181+
182+
let mut hasher = sha2::Sha256::new();
183+
184+
hasher.update(diff);
185+
hasher.update(status);
186+
hasher.update(additional_input);
187+
188+
hex_encode(hasher.finalize().as_slice())
189+
}

0 commit comments

Comments
 (0)