@@ -15,9 +15,7 @@ use std::{cmp, env, fs};
1515
1616use build_helper:: ci:: CiEnv ;
1717use 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} ;
2119use serde:: { Deserialize , Deserializer } ;
2220use serde_derive:: Deserialize ;
2321#[ cfg( feature = "tracing" ) ]
@@ -3053,19 +3051,22 @@ impl Config {
30533051 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
30543052 // Look for a version to compare to based on the current commit.
30553053 // Only commits merged by bors will have CI artifacts.
3056- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
3057- Some ( commit ) => commit ,
3058- None => {
3054+ match self . check_modifications ( & allowed_paths) {
3055+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
3056+ PathFreshness :: HasLocalModifications { upstream } => {
30593057 if if_unchanged {
30603058 return None ;
30613059 }
3062- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
3063- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
3064- println ! (
3065- "HELP: consider setting `rust.download-rustc=false` in bootstrap.toml"
3066- ) ;
3067- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
3068- crate :: exit!( 1 ) ;
3060+
3061+ if self . is_running_on_ci {
3062+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3063+ eprintln ! (
3064+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3065+ ) ;
3066+ return None ;
3067+ }
3068+
3069+ upstream
30693070 }
30703071 }
30713072 } else {
@@ -3074,19 +3075,6 @@ impl Config {
30743075 . expect ( "git-commit-info is missing in the project root" )
30753076 } ;
30763077
3077- if self . is_running_on_ci && {
3078- let head_sha =
3079- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3080- let head_sha = head_sha. trim ( ) ;
3081- commit == head_sha
3082- } {
3083- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3084- eprintln ! (
3085- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3086- ) ;
3087- return None ;
3088- }
3089-
30903078 if debug_assertions_requested {
30913079 eprintln ! (
30923080 "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3156,61 +3144,16 @@ impl Config {
31563144 }
31573145
31583146 /// Returns true if any of the `paths` have been modified locally.
3159- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3160- let freshness =
3161- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3162- . unwrap ( ) ;
3163- match freshness {
3147+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3148+ match self . check_modifications ( paths) {
31643149 PathFreshness :: LastModifiedUpstream { .. } => false ,
31653150 PathFreshness :: HasLocalModifications { .. } => true ,
31663151 }
31673152 }
31683153
3169- /// Returns the last commit in which any of `modified_paths` were changed,
3170- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3171- pub fn last_modified_commit (
3172- & self ,
3173- modified_paths : & [ & str ] ,
3174- option_name : & str ,
3175- if_unchanged : bool ,
3176- ) -> Option < String > {
3177- assert ! (
3178- self . rust_info. is_managed_git_subrepository( ) ,
3179- "Can't run `Config::last_modified_commit` on a non-git source."
3180- ) ;
3181-
3182- // Look for a version to compare to based on the current commit.
3183- // Only commits merged by bors will have CI artifacts.
3184- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3185- if commit. is_empty ( ) {
3186- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3187- println ! ( "help: maybe your repository history is too shallow?" ) ;
3188- println ! ( "help: consider disabling `{option_name}`" ) ;
3189- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3190- crate :: exit!( 1 ) ;
3191- }
3192-
3193- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3194- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3195- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3196-
3197- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3198- if has_changes {
3199- if if_unchanged {
3200- if self . is_verbose ( ) {
3201- println ! (
3202- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3203- ignoring `{option_name}`"
3204- ) ;
3205- }
3206- return None ;
3207- }
3208- println ! (
3209- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3210- ) ;
3211- }
3212-
3213- Some ( commit. to_string ( ) )
3154+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3155+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3156+ . unwrap ( )
32143157 }
32153158
32163159 pub fn ci_env ( & self ) -> CiEnv {
0 commit comments