@@ -15,9 +15,7 @@ use std::{cmp, env, fs};
15
15
16
16
use build_helper:: ci:: CiEnv ;
17
17
use build_helper:: exit;
18
- use build_helper:: git:: {
19
- GitConfig , PathFreshness , check_path_modifications, get_closest_merge_commit, output_result,
20
- } ;
18
+ use build_helper:: git:: { GitConfig , PathFreshness , check_path_modifications, output_result} ;
21
19
use serde:: { Deserialize , Deserializer } ;
22
20
use serde_derive:: Deserialize ;
23
21
#[ cfg( feature = "tracing" ) ]
@@ -3045,19 +3043,22 @@ impl Config {
3045
3043
let commit = if self . rust_info . is_managed_git_subrepository ( ) {
3046
3044
// Look for a version to compare to based on the current commit.
3047
3045
// Only commits merged by bors will have CI artifacts.
3048
- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
3049
- Some ( commit ) => commit ,
3050
- None => {
3046
+ match self . check_modifications ( & allowed_paths) {
3047
+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
3048
+ PathFreshness :: HasLocalModifications { upstream } => {
3051
3049
if if_unchanged {
3052
3050
return None ;
3053
3051
}
3054
- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
3055
- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
3056
- println ! (
3057
- "HELP: consider setting `rust.download-rustc=false` in bootstrap.toml"
3058
- ) ;
3059
- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
3060
- crate :: exit!( 1 ) ;
3052
+
3053
+ if CiEnv :: is_ci ( ) {
3054
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3055
+ eprintln ! (
3056
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3057
+ ) ;
3058
+ return None ;
3059
+ }
3060
+
3061
+ upstream
3061
3062
}
3062
3063
}
3063
3064
} else {
@@ -3066,19 +3067,6 @@ impl Config {
3066
3067
. expect ( "git-commit-info is missing in the project root" )
3067
3068
} ;
3068
3069
3069
- if CiEnv :: is_ci ( ) && {
3070
- let head_sha =
3071
- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3072
- let head_sha = head_sha. trim ( ) ;
3073
- commit == head_sha
3074
- } {
3075
- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3076
- eprintln ! (
3077
- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3078
- ) ;
3079
- return None ;
3080
- }
3081
-
3082
3070
if debug_assertions_requested {
3083
3071
eprintln ! (
3084
3072
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3134,61 +3122,16 @@ impl Config {
3134
3122
}
3135
3123
3136
3124
/// Returns true if any of the `paths` have been modified locally.
3137
- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3138
- let freshness =
3139
- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3140
- . unwrap ( ) ;
3141
- match freshness {
3125
+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3126
+ match self . check_modifications ( paths) {
3142
3127
PathFreshness :: LastModifiedUpstream { .. } => false ,
3143
3128
PathFreshness :: HasLocalModifications { .. } => true ,
3144
3129
}
3145
3130
}
3146
3131
3147
- /// Returns the last commit in which any of `modified_paths` were changed,
3148
- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3149
- pub fn last_modified_commit (
3150
- & self ,
3151
- modified_paths : & [ & str ] ,
3152
- option_name : & str ,
3153
- if_unchanged : bool ,
3154
- ) -> Option < String > {
3155
- assert ! (
3156
- self . rust_info. is_managed_git_subrepository( ) ,
3157
- "Can't run `Config::last_modified_commit` on a non-git source."
3158
- ) ;
3159
-
3160
- // Look for a version to compare to based on the current commit.
3161
- // Only commits merged by bors will have CI artifacts.
3162
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3163
- if commit. is_empty ( ) {
3164
- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3165
- println ! ( "help: maybe your repository history is too shallow?" ) ;
3166
- println ! ( "help: consider disabling `{option_name}`" ) ;
3167
- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3168
- crate :: exit!( 1 ) ;
3169
- }
3170
-
3171
- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3172
- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3173
- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3174
-
3175
- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3176
- if has_changes {
3177
- if if_unchanged {
3178
- if self . is_verbose ( ) {
3179
- println ! (
3180
- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3181
- ignoring `{option_name}`"
3182
- ) ;
3183
- }
3184
- return None ;
3185
- }
3186
- println ! (
3187
- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3188
- ) ;
3189
- }
3190
-
3191
- Some ( commit. to_string ( ) )
3132
+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3133
+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3134
+ . unwrap ( )
3192
3135
}
3193
3136
}
3194
3137
0 commit comments