Rollup merge of #131305 - onur-ozkan:131303, r=Kobzol

make `llvm::is_ci_llvm_modified` logic more precise

Fixes #131303.
This commit is contained in:
Stuart Cook 2024-10-11 17:46:11 +11:00 committed by GitHub
commit c4e7425782
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 33 deletions

View File

@ -20,10 +20,9 @@
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection}; use crate::core::config::{Config, TargetSelection};
use crate::utils::channel;
use crate::utils::exec::command; use crate::utils::exec::command;
use crate::utils::helpers::{ use crate::utils::helpers::{
self, HashStamp, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date, self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
}; };
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash}; use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
@ -166,7 +165,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
config.src.join("src/version"), config.src.join("src/version"),
]) ])
.unwrap() .unwrap()
} else if let Some(info) = channel::read_commit_info_file(&config.src) { } else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
info.sha.trim().to_owned() info.sha.trim().to_owned()
} else { } else {
"".to_owned() "".to_owned()
@ -242,15 +241,29 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
/// Returns true if we're running in CI with modified LLVM (and thus can't download it) /// Returns true if we're running in CI with modified LLVM (and thus can't download it)
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool { pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
CiEnv::is_rust_lang_managed_ci_job() && config.rust_info.is_managed_git_subrepository() && { // If not running in a CI environment, return false.
// We assume we have access to git, so it's okay to unconditionally pass if !CiEnv::is_ci() {
// `true` here. return false;
}
// In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
if CiEnv::is_rust_lang_managed_ci_job() {
assert!(
config.in_tree_llvm_info.is_managed_git_subrepository(),
"LLVM submodule must be fetched in rust-lang/rust managed CI builders."
);
}
// If LLVM submodule isn't present, skip the change check as it won't work.
else if !config.in_tree_llvm_info.is_managed_git_subrepository() {
return false;
}
let llvm_sha = detect_llvm_sha(config, true); let llvm_sha = detect_llvm_sha(config, true);
let head_sha = let head_sha = crate::output(
output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut()); helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut(),
);
let head_sha = head_sha.trim(); let head_sha = head_sha.trim();
llvm_sha == head_sha llvm_sha == head_sha
}
} }
#[derive(Debug, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Clone, Hash, PartialEq, Eq)]

View File

@ -21,29 +21,21 @@ pub(crate) fn parse(config: &str) -> Config {
#[test] #[test]
fn download_ci_llvm() { fn download_ci_llvm() {
if crate::core::build_steps::llvm::is_ci_llvm_modified(&parse("")) { assert!(parse("").llvm_from_ci);
eprintln!("Detected LLVM as non-available: running in CI and modified LLVM in this change"); assert!(parse("llvm.download-ci-llvm = true").llvm_from_ci);
return; assert!(!parse("llvm.download-ci-llvm = false").llvm_from_ci);
}
let parse_llvm = |s| parse(s).llvm_from_ci; let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\"");
let if_unchanged = parse_llvm("llvm.download-ci-llvm = \"if-unchanged\""); if if_unchanged_config.llvm_from_ci {
let has_changes = if_unchanged_config
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
.is_none();
assert!(parse_llvm("llvm.download-ci-llvm = true")); assert!(
assert!(!parse_llvm("llvm.download-ci-llvm = false")); !has_changes,
assert_eq!(parse_llvm(""), if_unchanged); "CI LLVM can't be enabled with 'if-unchanged' while there are changes in LLVM submodule."
assert_eq!(parse_llvm("rust.channel = \"dev\""), if_unchanged);
assert!(parse_llvm("rust.channel = \"stable\""));
assert_eq!(parse_llvm("build.build = \"x86_64-unknown-linux-gnu\""), if_unchanged);
assert_eq!(
parse_llvm(
"llvm.assertions = true \r\n build.build = \"x86_64-unknown-linux-gnu\" \r\n llvm.download-ci-llvm = \"if-unchanged\""
),
if_unchanged
); );
assert!(!parse_llvm( }
"llvm.assertions = true \r\n build.build = \"aarch64-apple-darwin\" \r\n llvm.download-ci-llvm = \"if-unchanged\""
));
} }
// FIXME(onur-ozkan): extend scope of the test // FIXME(onur-ozkan): extend scope of the test