Skip to content

Commit 8db1b48

Browse files
committed
make llvm::is_ci_llvm_modified logic more precise
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 11ee3a8 commit 8db1b48

File tree

1 file changed

+36
-11
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+36
-11
lines changed

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

+36-11
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ 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::channel;
2423
use crate::utils::exec::command;
2524
use crate::utils::helpers::{
26-
self, HashStamp, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
25+
self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
2726
};
2827
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
2928

@@ -157,6 +156,7 @@ pub fn prebuilt_llvm_config(
157156
}
158157

159158
/// This retrieves the LLVM sha we *want* to use, according to git history.
159+
#[cfg(not(feature = "bootstrap-self-test"))]
160160
pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
161161
let llvm_sha = if is_git {
162162
get_closest_merge_commit(Some(&config.src), &config.git_config(), &[
@@ -166,7 +166,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
166166
config.src.join("src/version"),
167167
])
168168
.unwrap()
169-
} else if let Some(info) = channel::read_commit_info_file(&config.src) {
169+
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
170170
info.sha.trim().to_owned()
171171
} else {
172172
"".to_owned()
@@ -242,15 +242,40 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
242242

243243
/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
244244
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
245-
CiEnv::is_rust_lang_managed_ci_job() && config.rust_info.is_managed_git_subrepository() && {
246-
// We assume we have access to git, so it's okay to unconditionally pass
247-
// `true` here.
248-
let llvm_sha = detect_llvm_sha(config, true);
249-
let head_sha =
250-
output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut());
251-
let head_sha = head_sha.trim();
252-
llvm_sha == head_sha
245+
// If not running in a CI environment, return false.
246+
if !CiEnv::is_ci() {
247+
return false;
248+
}
249+
250+
// In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
251+
if CiEnv::is_rust_lang_managed_ci_job() {
252+
assert!(
253+
config.in_tree_llvm_info.is_managed_git_subrepository(),
254+
"LLVM submodule must be fetched in rust-lang/rust managed CI builders."
255+
);
253256
}
257+
// If LLVM submodule isn't present, skip the change check as it won't work.
258+
else if !config.in_tree_llvm_info.is_managed_git_subrepository() {
259+
return false;
260+
}
261+
262+
let commit = t!(get_closest_merge_commit(Some(&config.src), &config.git_config(), &[]));
263+
264+
#[allow(clippy::let_and_return)] // makes it look more clear
265+
let is_modified = !t!(helpers::git(Some(&config.src))
266+
.args(["diff-index", "--quiet", &commit])
267+
.arg("--")
268+
.args([
269+
config.src.join("src/llvm-project"),
270+
config.src.join("src/bootstrap/download-ci-llvm-stamp"),
271+
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
272+
config.src.join("src/version"),
273+
])
274+
.as_command_mut()
275+
.status())
276+
.success();
277+
278+
is_modified
254279
}
255280

256281
#[derive(Debug, Clone, Hash, PartialEq, Eq)]

0 commit comments

Comments
 (0)