@@ -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" ) ]
@@ -3030,17 +3028,22 @@ impl Config {
30303028 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
30313029 // Look for a version to compare to based on the current commit.
30323030 // 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 } => {
30363034 if if_unchanged {
30373035 return None ;
30383036 }
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
30443047 }
30453048 }
30463049 } else {
@@ -3049,19 +3052,6 @@ impl Config {
30493052 . expect ( "git-commit-info is missing in the project root" )
30503053 } ;
30513054
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-
30653055 if debug_assertions_requested {
30663056 eprintln ! (
30673057 "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3117,61 +3107,16 @@ impl Config {
31173107 }
31183108
31193109 /// 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) {
31253112 PathFreshness :: LastModifiedUpstream { .. } => false ,
31263113 PathFreshness :: HasLocalModifications { .. } => true ,
31273114 }
31283115 }
31293116
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 ( )
31753120 }
31763121}
31773122
0 commit comments