Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1d1f248

Browse files
committed
Use check_path_modifications for detecting local GCC changes
1 parent 082ab9c commit 1d1f248

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

src/bootstrap/src/core/build_steps/gcc.rs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::core::config::TargetSelection;
1717
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
1818
use crate::utils::exec::command;
1919
use crate::utils::helpers::{self, t};
20+
use build_helper::git::PathFreshness;
2021

2122
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
2223
pub struct Gcc {
@@ -104,18 +105,30 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
104105
eprintln!("GCC CI download is only available for the `x86_64-unknown-linux-gnu` target");
105106
return None;
106107
}
107-
let sha =
108-
detect_gcc_sha(&builder.config, builder.config.rust_info.is_managed_git_subrepository());
109-
let root = ci_gcc_root(&builder.config);
110-
let gcc_stamp = BuildStamp::new(&root).with_prefix("gcc").add_stamp(&sha);
111-
if !gcc_stamp.is_up_to_date() && !builder.config.dry_run() {
112-
builder.config.download_ci_gcc(&sha, &root);
113-
t!(gcc_stamp.write());
108+
let source = detect_gcc_freshness(
109+
&builder.config,
110+
builder.config.rust_info.is_managed_git_subrepository(),
111+
);
112+
match source {
113+
PathFreshness::LastModifiedUpstream { upstream } => {
114+
// Download from upstream CI
115+
let root = ci_gcc_root(&builder.config);
116+
let gcc_stamp = BuildStamp::new(&root).with_prefix("gcc").add_stamp(&upstream);
117+
if !gcc_stamp.is_up_to_date() && !builder.config.dry_run() {
118+
builder.config.download_ci_gcc(&upstream, &root);
119+
t!(gcc_stamp.write());
120+
}
121+
122+
let libgccjit = root.join("lib").join("libgccjit.so");
123+
create_lib_alias(builder, &libgccjit);
124+
Some(libgccjit)
125+
}
126+
PathFreshness::HasLocalModifications { .. } => {
127+
// We have local modifications, rebuild GCC.
128+
eprintln!("Found local GCC modifications, GCC will *not* be downloaded");
129+
None
130+
}
114131
}
115-
116-
let libgccjit = root.join("lib").join("libgccjit.so");
117-
create_lib_alias(builder, &libgccjit);
118-
Some(libgccjit)
119132
}
120133

121134
#[cfg(test)]
@@ -264,31 +277,34 @@ fn ci_gcc_root(config: &crate::Config) -> PathBuf {
264277
config.out.join(config.build).join("ci-gcc")
265278
}
266279

267-
/// This retrieves the GCC sha we *want* to use, according to git history.
280+
/// Detect whether GCC sources have been modified locally or not.
268281
#[cfg(not(test))]
269-
fn detect_gcc_sha(config: &crate::Config, is_git: bool) -> String {
270-
use build_helper::git::get_closest_merge_commit;
271-
272-
let gcc_sha = if is_git {
273-
get_closest_merge_commit(
274-
Some(&config.src),
275-
&config.git_config(),
276-
&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"],
282+
fn detect_gcc_freshness(config: &crate::Config, is_git: bool) -> build_helper::git::PathFreshness {
283+
use build_helper::git::{PathFreshness, check_path_modifications};
284+
285+
let freshness = if is_git {
286+
Some(
287+
check_path_modifications(
288+
Some(&config.src),
289+
&config.git_config(),
290+
&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"],
291+
config.ci_env(),
292+
)
293+
.unwrap(),
277294
)
278-
.unwrap()
279295
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
280-
info.sha.trim().to_owned()
296+
Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() })
281297
} else {
282-
"".to_owned()
298+
None
283299
};
284300

285-
if gcc_sha.is_empty() {
301+
let Some(freshness) = freshness else {
286302
eprintln!("error: could not find commit hash for downloading GCC");
287303
eprintln!("HELP: maybe your repository history is too shallow?");
288304
eprintln!("HELP: consider disabling `download-ci-gcc`");
289305
eprintln!("HELP: or fetch enough history to include one upstream commit");
290306
panic!();
291-
}
307+
};
292308

293-
gcc_sha
309+
freshness
294310
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,10 @@ impl Config {
33793379
_ => !self.is_system_llvm(target),
33803380
}
33813381
}
3382+
3383+
pub fn ci_env(&self) -> CiEnv {
3384+
if self.is_running_on_ci { CiEnv::GitHubActions } else { CiEnv::None }
3385+
}
33823386
}
33833387

33843388
/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.

0 commit comments

Comments
 (0)