@@ -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" ) ]
@@ -2981,17 +2979,22 @@ impl Config {
2981
2979
let commit = if self . rust_info . is_managed_git_subrepository ( ) {
2982
2980
// Look for a version to compare to based on the current commit.
2983
2981
// Only commits merged by bors will have CI artifacts.
2984
- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
2985
- Some ( commit ) => commit ,
2986
- None => {
2982
+ match self . check_modifications ( & allowed_paths) {
2983
+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
2984
+ PathFreshness :: HasLocalModifications { upstream } => {
2987
2985
if if_unchanged {
2988
2986
return None ;
2989
2987
}
2990
- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
2991
- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
2992
- println ! ( "HELP: consider setting `rust.download-rustc=false` in config.toml" ) ;
2993
- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
2994
- crate :: exit!( 1 ) ;
2988
+
2989
+ if CiEnv :: is_ci ( ) {
2990
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
2991
+ eprintln ! (
2992
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
2993
+ ) ;
2994
+ return None ;
2995
+ }
2996
+
2997
+ upstream
2995
2998
}
2996
2999
}
2997
3000
} else {
@@ -3000,19 +3003,6 @@ impl Config {
3000
3003
. expect ( "git-commit-info is missing in the project root" )
3001
3004
} ;
3002
3005
3003
- if CiEnv :: is_ci ( ) && {
3004
- let head_sha =
3005
- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3006
- let head_sha = head_sha. trim ( ) ;
3007
- commit == head_sha
3008
- } {
3009
- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3010
- eprintln ! (
3011
- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3012
- ) ;
3013
- return None ;
3014
- }
3015
-
3016
3006
if debug_assertions_requested {
3017
3007
eprintln ! (
3018
3008
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3068,61 +3058,16 @@ impl Config {
3068
3058
}
3069
3059
3070
3060
/// Returns true if any of the `paths` have been modified locally.
3071
- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3072
- let freshness =
3073
- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3074
- . unwrap ( ) ;
3075
- match freshness {
3061
+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3062
+ match self . check_modifications ( paths) {
3076
3063
PathFreshness :: LastModifiedUpstream { .. } => false ,
3077
3064
PathFreshness :: HasLocalModifications { .. } => true ,
3078
3065
}
3079
3066
}
3080
3067
3081
- /// Returns the last commit in which any of `modified_paths` were changed,
3082
- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3083
- pub fn last_modified_commit (
3084
- & self ,
3085
- modified_paths : & [ & str ] ,
3086
- option_name : & str ,
3087
- if_unchanged : bool ,
3088
- ) -> Option < String > {
3089
- assert ! (
3090
- self . rust_info. is_managed_git_subrepository( ) ,
3091
- "Can't run `Config::last_modified_commit` on a non-git source."
3092
- ) ;
3093
-
3094
- // Look for a version to compare to based on the current commit.
3095
- // Only commits merged by bors will have CI artifacts.
3096
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3097
- if commit. is_empty ( ) {
3098
- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3099
- println ! ( "help: maybe your repository history is too shallow?" ) ;
3100
- println ! ( "help: consider disabling `{option_name}`" ) ;
3101
- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3102
- crate :: exit!( 1 ) ;
3103
- }
3104
-
3105
- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3106
- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3107
- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3108
-
3109
- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3110
- if has_changes {
3111
- if if_unchanged {
3112
- if self . is_verbose ( ) {
3113
- println ! (
3114
- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3115
- ignoring `{option_name}`"
3116
- ) ;
3117
- }
3118
- return None ;
3119
- }
3120
- println ! (
3121
- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3122
- ) ;
3123
- }
3124
-
3125
- Some ( commit. to_string ( ) )
3068
+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3069
+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3070
+ . unwrap ( )
3126
3071
}
3127
3072
}
3128
3073
0 commit comments