Skip to content

Commit e6f82d6

Browse files
committed
Recompile LLVM when it changes in the git sources
Utilize a smart hash for 'llvm-finished-building' to enable recompilation of LLVM with each change in the git sources. Each change generates a unique hash value in 'llvm-finished-building', which ensures LLVM compilations only triggered with further changes. Signed-off-by: onur-ozkan <[email protected]>
1 parent 73bc121 commit e6f82d6

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2020
use crate::core::config::{Config, TargetSelection};
2121
use crate::utils::channel;
2222
use crate::utils::helpers::{self, exe, get_clang_cl_resource_dir, output, t, up_to_date};
23-
use crate::{CLang, GitRepo, Kind};
23+
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2424

2525
use build_helper::ci::CiEnv;
2626
use build_helper::git::get_git_merge_base;
@@ -105,8 +105,13 @@ pub fn prebuilt_llvm_config(
105105
let llvm_cmake_dir = out_dir.join("lib/cmake/llvm");
106106
let res = LlvmResult { llvm_config: build_llvm_config, llvm_cmake_dir };
107107

108+
let smart_stamp_hash = generate_smart_stamp_hash(
109+
&builder.config.src.join("src/llvm-project"),
110+
&builder.in_tree_llvm_info.sha().unwrap_or_default(),
111+
);
112+
108113
let stamp = out_dir.join("llvm-finished-building");
109-
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
114+
let stamp = HashStamp::new(stamp, Some(&smart_stamp_hash));
110115

111116
if stamp.is_done() {
112117
if stamp.hash.is_none() {

src/bootstrap/src/lib.rs

+44
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use build_helper::exit;
3131
use build_helper::util::fail;
3232
use filetime::FileTime;
3333
use once_cell::sync::OnceCell;
34+
use sha2::digest::Digest;
3435
use termcolor::{ColorChoice, StandardStream, WriteColor};
3536
use utils::channel::GitInfo;
3637

@@ -1872,3 +1873,46 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<usize> {
18721873
.cloned()
18731874
.collect()
18741875
}
1876+
1877+
/// Computes a hash representing the state of a repository/submodule and additional input.
1878+
///
1879+
/// It uses `git diff` for the actual changes, and `git status` for including the untracked
1880+
/// files in the specified directory. The additional input is also incorporated into the
1881+
/// computation of the hash.
1882+
///
1883+
/// # Parameters
1884+
///
1885+
/// - `dir`: A reference to the directory path of the target repository/submodule.
1886+
/// - `additional_input`: An additional input to be included in the hash.
1887+
///
1888+
///
1889+
/// # Panics
1890+
///
1891+
/// In case of errors during `git` command execution (e.g., in tarball sources), default values
1892+
/// are used to prevent panics.
1893+
pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
1894+
let root_diff = std::process::Command::new("git")
1895+
.current_dir(dir)
1896+
.arg("diff")
1897+
.output()
1898+
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
1899+
.unwrap_or_default();
1900+
1901+
let root_status = std::process::Command::new("git")
1902+
.current_dir(dir)
1903+
.arg("status")
1904+
.arg("--porcelain")
1905+
.arg("-z")
1906+
.arg("--untracked-files=normal")
1907+
.output()
1908+
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
1909+
.unwrap_or_default();
1910+
1911+
let mut hasher = sha2::Sha256::new();
1912+
1913+
hasher.update(root_diff);
1914+
hasher.update(root_status);
1915+
hasher.update(additional_input);
1916+
1917+
hex::encode(hasher.finalize().as_slice())
1918+
}

0 commit comments

Comments
 (0)