@@ -15,7 +15,7 @@ use std::sync::OnceLock;
15
15
use std:: { env, fs} ;
16
16
17
17
use build_helper:: ci:: CiEnv ;
18
- use build_helper:: git:: get_closest_merge_commit ;
18
+ use build_helper:: git:: { PathFreshness , check_path_modifications } ;
19
19
#[ cfg( feature = "tracing" ) ]
20
20
use tracing:: instrument;
21
21
@@ -174,35 +174,38 @@ pub fn prebuilt_llvm_config(
174
174
LlvmBuildStatus :: ShouldBuild ( Meta { stamp, res, out_dir, root : root. into ( ) } )
175
175
}
176
176
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 ( ) ,
189
193
)
190
- . unwrap ( )
191
194
} 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 ( ) } )
193
196
} else {
194
- "" . to_owned ( )
197
+ None
195
198
} ;
196
199
197
- if llvm_sha . is_empty ( ) {
200
+ let Some ( freshness ) = freshness else {
198
201
eprintln ! ( "error: could not find commit hash for downloading LLVM" ) ;
199
202
eprintln ! ( "HELP: maybe your repository history is too shallow?" ) ;
200
203
eprintln ! ( "HELP: consider disabling `download-ci-llvm`" ) ;
201
204
eprintln ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
202
205
panic ! ( ) ;
203
- }
206
+ } ;
204
207
205
- llvm_sha
208
+ freshness
206
209
}
207
210
208
211
/// Returns whether the CI-found LLVM is currently usable.
@@ -282,12 +285,7 @@ pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
282
285
return false ;
283
286
}
284
287
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 { .. } )
291
289
}
292
290
293
291
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
0 commit comments