@@ -15,7 +15,7 @@ use std::sync::OnceLock;
1515use std:: { env, fs} ;
1616
1717use build_helper:: ci:: CiEnv ;
18- use build_helper:: git:: get_closest_merge_commit ;
18+ use build_helper:: git:: { PathFreshness , check_path_modifications } ;
1919#[ cfg( feature = "tracing" ) ]
2020use tracing:: instrument;
2121
@@ -174,35 +174,38 @@ pub fn prebuilt_llvm_config(
174174 LlvmBuildStatus :: ShouldBuild ( Meta { stamp, res, out_dir, root : root. into ( ) } )
175175}
176176
177- /// This retrieves the LLVM sha we *want* to use, according to git history.
178- pub ( crate ) fn detect_llvm_sha ( config : & Config , is_git : bool ) -> String {
179- let llvm_sha = if is_git {
180- get_closest_merge_commit (
181- Some ( & config. src ) ,
182- & config. git_config ( ) ,
183- & [
184- config. src . join ( "src/llvm-project" ) ,
185- config. src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
186- // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
187- config. src . join ( "src/version" ) ,
188- ] ,
177+ /// Detect whether LLVM sources have been modified locally or not.
178+ pub ( crate ) fn detect_llvm_freshness ( config : & Config , is_git : bool ) -> PathFreshness {
179+ let freshness = if is_git {
180+ Some (
181+ check_path_modifications (
182+ Some ( & config. src ) ,
183+ & config. git_config ( ) ,
184+ & [
185+ "src/llvm-project" ,
186+ "src/bootstrap/download-ci-llvm-stamp" ,
187+ // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
188+ "src/version" ,
189+ ] ,
190+ CiEnv :: current ( ) ,
191+ )
192+ . unwrap ( ) ,
189193 )
190- . unwrap ( )
191194 } else if let Some ( info) = crate :: utils:: channel:: read_commit_info_file ( & config. src ) {
192- info. sha . trim ( ) . to_owned ( )
195+ Some ( PathFreshness :: LastModifiedUpstream { upstream : info. sha . trim ( ) . to_owned ( ) } )
193196 } else {
194- "" . to_owned ( )
197+ None
195198 } ;
196199
197- if llvm_sha . is_empty ( ) {
200+ let Some ( freshness ) = freshness else {
198201 eprintln ! ( "error: could not find commit hash for downloading LLVM" ) ;
199202 eprintln ! ( "HELP: maybe your repository history is too shallow?" ) ;
200203 eprintln ! ( "HELP: consider disabling `download-ci-llvm`" ) ;
201204 eprintln ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
202205 panic ! ( ) ;
203- }
206+ } ;
204207
205- llvm_sha
208+ freshness
206209}
207210
208211/// Returns whether the CI-found LLVM is currently usable.
@@ -282,12 +285,7 @@ pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
282285 return false ;
283286 }
284287
285- let llvm_sha = detect_llvm_sha ( config, true ) ;
286- let head_sha = crate :: output (
287- helpers:: git ( Some ( & config. src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ,
288- ) ;
289- let head_sha = head_sha. trim ( ) ;
290- llvm_sha == head_sha
288+ matches ! ( detect_llvm_freshness( config, true ) , PathFreshness :: HasLocalModifications { .. } )
291289}
292290
293291#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
0 commit comments