Skip to content

Commit

Permalink
improve ci-rustc finding logic
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
onur-ozkan committed Oct 8, 2024
1 parent eb5e623 commit 1090d89
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use std::str::FromStr;
use std::sync::OnceLock;
use std::{cmp, env, fs};

use build_helper::ci::CiEnv;
use build_helper::exit;
use build_helper::git::{GitConfig, get_closest_merge_commit, output_result};
use serde::{Deserialize, Deserializer};
@@ -2718,21 +2719,28 @@ impl Config {
download_rustc: Option<StringOrBool>,
llvm_assertions: bool,
) -> Option<String> {
if !is_download_ci_available(&self.build.triple, llvm_assertions) {
return None;
}

// If `download-rustc` is not set, default to rebuilding.
let if_unchanged = match download_rustc {
None | Some(StringOrBool::Bool(false)) => return None,
Some(StringOrBool::Bool(true)) => false,
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
is_download_ci_available(&self.build.triple, llvm_assertions)
}
Some(StringOrBool::String(s)) if s == "if-unchanged" => true,
Some(StringOrBool::String(other)) => {
panic!("unrecognized option for download-rustc: {other}")
}
};

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

if CiEnv::is_ci() && {
let head_sha =
output(helpers::git(Some(&self.src)).arg("rev-parse").arg("HEAD").as_command_mut());
let head_sha = head_sha.trim();
commit == head_sha
} {
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
eprintln!(
"`rustc.download-ci` functionality will be skipped as artifacts are not available."
);
return None;
}

// Warn if there were changes to the compiler or standard library since the ancestor commit.
let has_changes = !t!(helpers::git(Some(&self.src))
.args(["diff-index", "--quiet", &commit])

0 comments on commit 1090d89

Please sign in to comment.