@@ -17,6 +17,7 @@ use crate::core::config::TargetSelection;
17
17
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
18
18
use crate::utils::exec::command;
19
19
use crate::utils::helpers::{self, t};
20
+ use build_helper::git::PathFreshness;
20
21
21
22
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
22
23
pub struct Gcc {
@@ -104,18 +105,30 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
104
105
eprintln!("GCC CI download is only available for the `x86_64-unknown-linux-gnu` target");
105
106
return None;
106
107
}
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
+ }
114
131
}
115
-
116
- let libgccjit = root.join("lib").join("libgccjit.so");
117
- create_lib_alias(builder, &libgccjit);
118
- Some(libgccjit)
119
132
}
120
133
121
134
#[cfg(test)]
@@ -264,31 +277,34 @@ fn ci_gcc_root(config: &crate::Config) -> PathBuf {
264
277
config.out.join(config.build).join("ci-gcc")
265
278
}
266
279
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 .
268
281
#[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(),
277
294
)
278
- .unwrap()
279
295
} 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() } )
281
297
} else {
282
- "".to_owned()
298
+ None
283
299
};
284
300
285
- if gcc_sha.is_empty() {
301
+ let Some(freshness) = freshness else {
286
302
eprintln!("error: could not find commit hash for downloading GCC");
287
303
eprintln!("HELP: maybe your repository history is too shallow?");
288
304
eprintln!("HELP: consider disabling `download-ci-gcc`");
289
305
eprintln!("HELP: or fetch enough history to include one upstream commit");
290
306
panic!();
291
- }
307
+ };
292
308
293
- gcc_sha
309
+ freshness
294
310
}
0 commit comments