@@ -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" ) ]
@@ -2948,17 +2946,22 @@ impl Config {
2948
2946
let commit = if self . rust_info . is_managed_git_subrepository ( ) {
2949
2947
// Look for a version to compare to based on the current commit.
2950
2948
// Only commits merged by bors will have CI artifacts.
2951
- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
2952
- Some ( commit ) => commit ,
2953
- None => {
2949
+ match self . check_modifications ( & allowed_paths) {
2950
+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
2951
+ PathFreshness :: HasLocalModifications { upstream } => {
2954
2952
if if_unchanged {
2955
2953
return None ;
2956
2954
}
2957
- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
2958
- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
2959
- println ! ( "HELP: consider setting `rust.download-rustc=false` in config.toml" ) ;
2960
- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
2961
- crate :: exit!( 1 ) ;
2955
+
2956
+ if CiEnv :: is_ci ( ) {
2957
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
2958
+ eprintln ! (
2959
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
2960
+ ) ;
2961
+ return None ;
2962
+ }
2963
+
2964
+ upstream
2962
2965
}
2963
2966
}
2964
2967
} else {
@@ -2967,19 +2970,6 @@ impl Config {
2967
2970
. expect ( "git-commit-info is missing in the project root" )
2968
2971
} ;
2969
2972
2970
- if CiEnv :: is_ci ( ) && {
2971
- let head_sha =
2972
- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
2973
- let head_sha = head_sha. trim ( ) ;
2974
- commit == head_sha
2975
- } {
2976
- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
2977
- eprintln ! (
2978
- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
2979
- ) ;
2980
- return None ;
2981
- }
2982
-
2983
2973
if debug_assertions_requested {
2984
2974
eprintln ! (
2985
2975
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3035,61 +3025,16 @@ impl Config {
3035
3025
}
3036
3026
3037
3027
/// Returns true if any of the `paths` have been modified locally.
3038
- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3039
- let freshness =
3040
- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3041
- . unwrap ( ) ;
3042
- match freshness {
3028
+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3029
+ match self . check_modifications ( paths) {
3043
3030
PathFreshness :: LastModifiedUpstream { .. } => false ,
3044
3031
PathFreshness :: HasLocalModifications { .. } => true ,
3045
3032
}
3046
3033
}
3047
3034
3048
- /// Returns the last commit in which any of `modified_paths` were changed,
3049
- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3050
- pub fn last_modified_commit (
3051
- & self ,
3052
- modified_paths : & [ & str ] ,
3053
- option_name : & str ,
3054
- if_unchanged : bool ,
3055
- ) -> Option < String > {
3056
- assert ! (
3057
- self . rust_info. is_managed_git_subrepository( ) ,
3058
- "Can't run `Config::last_modified_commit` on a non-git source."
3059
- ) ;
3060
-
3061
- // Look for a version to compare to based on the current commit.
3062
- // Only commits merged by bors will have CI artifacts.
3063
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3064
- if commit. is_empty ( ) {
3065
- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3066
- println ! ( "help: maybe your repository history is too shallow?" ) ;
3067
- println ! ( "help: consider disabling `{option_name}`" ) ;
3068
- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3069
- crate :: exit!( 1 ) ;
3070
- }
3071
-
3072
- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3073
- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3074
- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3075
-
3076
- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3077
- if has_changes {
3078
- if if_unchanged {
3079
- if self . is_verbose ( ) {
3080
- println ! (
3081
- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3082
- ignoring `{option_name}`"
3083
- ) ;
3084
- }
3085
- return None ;
3086
- }
3087
- println ! (
3088
- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3089
- ) ;
3090
- }
3091
-
3092
- Some ( commit. to_string ( ) )
3035
+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3036
+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3037
+ . unwrap ( )
3093
3038
}
3094
3039
}
3095
3040
0 commit comments