@@ -16,9 +16,7 @@ use std::{cmp, env, fs};
16
16
17
17
use build_helper:: ci:: CiEnv ;
18
18
use build_helper:: exit;
19
- use build_helper:: git:: {
20
- GitConfig , PathFreshness , check_path_modifications, get_closest_merge_commit, output_result,
21
- } ;
19
+ use build_helper:: git:: { GitConfig , PathFreshness , check_path_modifications, output_result} ;
22
20
use serde:: { Deserialize , Deserializer } ;
23
21
use serde_derive:: Deserialize ;
24
22
#[ cfg( feature = "tracing" ) ]
@@ -3195,19 +3193,22 @@ impl Config {
3195
3193
let commit = if self . rust_info . is_managed_git_subrepository ( ) {
3196
3194
// Look for a version to compare to based on the current commit.
3197
3195
// Only commits merged by bors will have CI artifacts.
3198
- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
3199
- Some ( commit ) => commit ,
3200
- None => {
3196
+ match self . check_modifications ( & allowed_paths) {
3197
+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
3198
+ PathFreshness :: HasLocalModifications { upstream } => {
3201
3199
if if_unchanged {
3202
3200
return None ;
3203
3201
}
3204
- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
3205
- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
3206
- println ! (
3207
- "HELP: consider setting `rust.download-rustc=false` in bootstrap.toml"
3208
- ) ;
3209
- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
3210
- crate :: exit!( 1 ) ;
3202
+
3203
+ if self . is_running_on_ci {
3204
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3205
+ eprintln ! (
3206
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3207
+ ) ;
3208
+ return None ;
3209
+ }
3210
+
3211
+ upstream
3211
3212
}
3212
3213
}
3213
3214
} else {
@@ -3216,19 +3217,6 @@ impl Config {
3216
3217
. expect ( "git-commit-info is missing in the project root" )
3217
3218
} ;
3218
3219
3219
- if self . is_running_on_ci && {
3220
- let head_sha =
3221
- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3222
- let head_sha = head_sha. trim ( ) ;
3223
- commit == head_sha
3224
- } {
3225
- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3226
- eprintln ! (
3227
- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3228
- ) ;
3229
- return None ;
3230
- }
3231
-
3232
3220
if debug_assertions_requested {
3233
3221
eprintln ! (
3234
3222
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3298,61 +3286,16 @@ impl Config {
3298
3286
}
3299
3287
3300
3288
/// Returns true if any of the `paths` have been modified locally.
3301
- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3302
- let freshness =
3303
- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3304
- . unwrap ( ) ;
3305
- match freshness {
3289
+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3290
+ match self . check_modifications ( paths) {
3306
3291
PathFreshness :: LastModifiedUpstream { .. } => false ,
3307
3292
PathFreshness :: HasLocalModifications { .. } => true ,
3308
3293
}
3309
3294
}
3310
3295
3311
- /// Returns the last commit in which any of `modified_paths` were changed,
3312
- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3313
- pub fn last_modified_commit (
3314
- & self ,
3315
- modified_paths : & [ & str ] ,
3316
- option_name : & str ,
3317
- if_unchanged : bool ,
3318
- ) -> Option < String > {
3319
- assert ! (
3320
- self . rust_info. is_managed_git_subrepository( ) ,
3321
- "Can't run `Config::last_modified_commit` on a non-git source."
3322
- ) ;
3323
-
3324
- // Look for a version to compare to based on the current commit.
3325
- // Only commits merged by bors will have CI artifacts.
3326
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3327
- if commit. is_empty ( ) {
3328
- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3329
- println ! ( "help: maybe your repository history is too shallow?" ) ;
3330
- println ! ( "help: consider disabling `{option_name}`" ) ;
3331
- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3332
- crate :: exit!( 1 ) ;
3333
- }
3334
-
3335
- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3336
- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3337
- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3338
-
3339
- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3340
- if has_changes {
3341
- if if_unchanged {
3342
- if self . is_verbose ( ) {
3343
- println ! (
3344
- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3345
- ignoring `{option_name}`"
3346
- ) ;
3347
- }
3348
- return None ;
3349
- }
3350
- println ! (
3351
- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3352
- ) ;
3353
- }
3354
-
3355
- Some ( commit. to_string ( ) )
3296
+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3297
+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3298
+ . unwrap ( )
3356
3299
}
3357
3300
3358
3301
/// Checks if the given target is the same as the host target.
0 commit comments