Skip to content

Commit 1090d89

Browse files
committed
improve ci-rustc finding logic
Signed-off-by: onur-ozkan <[email protected]>
1 parent eb5e623 commit 1090d89

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::str::FromStr;
1313
use std::sync::OnceLock;
1414
use std::{cmp, env, fs};
1515

16+
use build_helper::ci::CiEnv;
1617
use build_helper::exit;
1718
use build_helper::git::{GitConfig, get_closest_merge_commit, output_result};
1819
use serde::{Deserialize, Deserializer};
@@ -2718,21 +2719,28 @@ impl Config {
27182719
download_rustc: Option<StringOrBool>,
27192720
llvm_assertions: bool,
27202721
) -> Option<String> {
2722+
if !is_download_ci_available(&self.build.triple, llvm_assertions) {
2723+
return None;
2724+
}
2725+
27212726
// If `download-rustc` is not set, default to rebuilding.
27222727
let if_unchanged = match download_rustc {
27232728
None | Some(StringOrBool::Bool(false)) => return None,
27242729
Some(StringOrBool::Bool(true)) => false,
2725-
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
2726-
is_download_ci_available(&self.build.triple, llvm_assertions)
2727-
}
2730+
Some(StringOrBool::String(s)) if s == "if-unchanged" => true,
27282731
Some(StringOrBool::String(other)) => {
27292732
panic!("unrecognized option for download-rustc: {other}")
27302733
}
27312734
};
27322735

27332736
// Look for a version to compare to based on the current commit.
27342737
// Only commits merged by bors will have CI artifacts.
2735-
let commit = get_closest_merge_commit(Some(&self.src), &self.git_config(), &[]).unwrap();
2738+
let commit = get_closest_merge_commit(
2739+
Some(&self.src),
2740+
&self.git_config(),
2741+
&[self.src.join("compiler"), self.src.join("library")],
2742+
)
2743+
.unwrap();
27362744
if commit.is_empty() {
27372745
println!("ERROR: could not find commit hash for downloading rustc");
27382746
println!("HELP: maybe your repository history is too shallow?");
@@ -2741,6 +2749,19 @@ impl Config {
27412749
crate::exit!(1);
27422750
}
27432751

2752+
if CiEnv::is_ci() && {
2753+
let head_sha =
2754+
output(helpers::git(Some(&self.src)).arg("rev-parse").arg("HEAD").as_command_mut());
2755+
let head_sha = head_sha.trim();
2756+
commit == head_sha
2757+
} {
2758+
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
2759+
eprintln!(
2760+
"`rustc.download-ci` functionality will be skipped as artifacts are not available."
2761+
);
2762+
return None;
2763+
}
2764+
27442765
// Warn if there were changes to the compiler or standard library since the ancestor commit.
27452766
let has_changes = !t!(helpers::git(Some(&self.src))
27462767
.args(["diff-index", "--quiet", &commit])

0 commit comments

Comments
 (0)