@@ -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" ) ]
@@ -3030,17 +3028,22 @@ impl Config {
3030
3028
let commit = if self . rust_info . is_managed_git_subrepository ( ) {
3031
3029
// Look for a version to compare to based on the current commit.
3032
3030
// Only commits merged by bors will have CI artifacts.
3033
- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
3034
- Some ( commit ) => commit ,
3035
- None => {
3031
+ match self . check_modifications ( & allowed_paths) {
3032
+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
3033
+ PathFreshness :: HasLocalModifications { upstream } => {
3036
3034
if if_unchanged {
3037
3035
return None ;
3038
3036
}
3039
- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
3040
- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
3041
- println ! ( "HELP: consider setting `rust.download-rustc=false` in config.toml" ) ;
3042
- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
3043
- crate :: exit!( 1 ) ;
3037
+
3038
+ if CiEnv :: is_ci ( ) {
3039
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3040
+ eprintln ! (
3041
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3042
+ ) ;
3043
+ return None ;
3044
+ }
3045
+
3046
+ upstream
3044
3047
}
3045
3048
}
3046
3049
} else {
@@ -3049,19 +3052,6 @@ impl Config {
3049
3052
. expect ( "git-commit-info is missing in the project root" )
3050
3053
} ;
3051
3054
3052
- if CiEnv :: is_ci ( ) && {
3053
- let head_sha =
3054
- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3055
- let head_sha = head_sha. trim ( ) ;
3056
- commit == head_sha
3057
- } {
3058
- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3059
- eprintln ! (
3060
- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3061
- ) ;
3062
- return None ;
3063
- }
3064
-
3065
3055
if debug_assertions_requested {
3066
3056
eprintln ! (
3067
3057
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3117,61 +3107,16 @@ impl Config {
3117
3107
}
3118
3108
3119
3109
/// Returns true if any of the `paths` have been modified locally.
3120
- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3121
- let freshness =
3122
- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3123
- . unwrap ( ) ;
3124
- match freshness {
3110
+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3111
+ match self . check_modifications ( paths) {
3125
3112
PathFreshness :: LastModifiedUpstream { .. } => false ,
3126
3113
PathFreshness :: HasLocalModifications { .. } => true ,
3127
3114
}
3128
3115
}
3129
3116
3130
- /// Returns the last commit in which any of `modified_paths` were changed,
3131
- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3132
- pub fn last_modified_commit (
3133
- & self ,
3134
- modified_paths : & [ & str ] ,
3135
- option_name : & str ,
3136
- if_unchanged : bool ,
3137
- ) -> Option < String > {
3138
- assert ! (
3139
- self . rust_info. is_managed_git_subrepository( ) ,
3140
- "Can't run `Config::last_modified_commit` on a non-git source."
3141
- ) ;
3142
-
3143
- // Look for a version to compare to based on the current commit.
3144
- // Only commits merged by bors will have CI artifacts.
3145
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3146
- if commit. is_empty ( ) {
3147
- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3148
- println ! ( "help: maybe your repository history is too shallow?" ) ;
3149
- println ! ( "help: consider disabling `{option_name}`" ) ;
3150
- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3151
- crate :: exit!( 1 ) ;
3152
- }
3153
-
3154
- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3155
- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3156
- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3157
-
3158
- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3159
- if has_changes {
3160
- if if_unchanged {
3161
- if self . is_verbose ( ) {
3162
- println ! (
3163
- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3164
- ignoring `{option_name}`"
3165
- ) ;
3166
- }
3167
- return None ;
3168
- }
3169
- println ! (
3170
- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3171
- ) ;
3172
- }
3173
-
3174
- Some ( commit. to_string ( ) )
3117
+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3118
+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3119
+ . unwrap ( )
3175
3120
}
3176
3121
}
3177
3122
0 commit comments