@@ -20,10 +20,9 @@ use build_helper::git::get_closest_merge_commit;
20
20
21
21
use crate :: core:: builder:: { Builder , RunConfig , ShouldRun , Step } ;
22
22
use crate :: core:: config:: { Config , TargetSelection } ;
23
- use crate :: utils:: channel;
24
23
use crate :: utils:: exec:: command;
25
24
use crate :: utils:: helpers:: {
26
- self , HashStamp , exe, get_clang_cl_resource_dir, output , t, unhashed_basename, up_to_date,
25
+ self , HashStamp , exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
27
26
} ;
28
27
use crate :: { CLang , GitRepo , Kind , generate_smart_stamp_hash} ;
29
28
@@ -157,6 +156,7 @@ pub fn prebuilt_llvm_config(
157
156
}
158
157
159
158
/// This retrieves the LLVM sha we *want* to use, according to git history.
159
+ #[ cfg( not( feature = "bootstrap-self-test" ) ) ]
160
160
pub ( crate ) fn detect_llvm_sha ( config : & Config , is_git : bool ) -> String {
161
161
let llvm_sha = if is_git {
162
162
get_closest_merge_commit ( Some ( & config. src ) , & config. git_config ( ) , & [
@@ -166,7 +166,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
166
166
config. src . join ( "src/version" ) ,
167
167
] )
168
168
. unwrap ( )
169
- } else if let Some ( info) = channel:: read_commit_info_file ( & config. src ) {
169
+ } else if let Some ( info) = crate :: utils :: channel:: read_commit_info_file ( & config. src ) {
170
170
info. sha . trim ( ) . to_owned ( )
171
171
} else {
172
172
"" . to_owned ( )
@@ -242,15 +242,40 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
242
242
243
243
/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
244
244
pub ( crate ) fn is_ci_llvm_modified ( config : & Config ) -> bool {
245
- CiEnv :: is_rust_lang_managed_ci_job ( ) && config. rust_info . is_managed_git_subrepository ( ) && {
246
- // We assume we have access to git, so it's okay to unconditionally pass
247
- // `true` here.
248
- let llvm_sha = detect_llvm_sha ( config, true ) ;
249
- let head_sha =
250
- output ( helpers:: git ( Some ( & config. src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
251
- let head_sha = head_sha. trim ( ) ;
252
- llvm_sha == head_sha
245
+ // If not running in a CI environment, return false.
246
+ if !CiEnv :: is_ci ( ) {
247
+ return false ;
248
+ }
249
+
250
+ // In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
251
+ if CiEnv :: is_rust_lang_managed_ci_job ( ) {
252
+ assert ! (
253
+ config. in_tree_llvm_info. is_managed_git_subrepository( ) ,
254
+ "LLVM submodule must be fetched in rust-lang/rust managed CI builders."
255
+ ) ;
253
256
}
257
+ // If LLVM submodule isn't present, skip the change check as it won't work.
258
+ else if !config. in_tree_llvm_info . is_managed_git_subrepository ( ) {
259
+ return false ;
260
+ }
261
+
262
+ let commit = t ! ( get_closest_merge_commit( Some ( & config. src) , & config. git_config( ) , & [ ] ) ) ;
263
+
264
+ #[ allow( clippy:: let_and_return) ] // makes it look more clear
265
+ let is_modified = !t ! ( helpers:: git( Some ( & config. src) )
266
+ . args( [ "diff-index" , "--quiet" , & commit] )
267
+ . arg( "--" )
268
+ . args( [
269
+ config. src. join( "src/llvm-project" ) ,
270
+ config. src. join( "src/bootstrap/download-ci-llvm-stamp" ) ,
271
+ // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
272
+ config. src. join( "src/version" ) ,
273
+ ] )
274
+ . as_command_mut( )
275
+ . status( ) )
276
+ . success ( ) ;
277
+
278
+ is_modified
254
279
}
255
280
256
281
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
0 commit comments