@@ -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" ) ]
@@ -2981,17 +2979,22 @@ impl Config {
29812979 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
29822980 // Look for a version to compare to based on the current commit.
29832981 // 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 } => {
29872985 if if_unchanged {
29882986 return None ;
29892987 }
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
29952998 }
29962999 }
29973000 } else {
@@ -3000,19 +3003,6 @@ impl Config {
30003003 . expect ( "git-commit-info is missing in the project root" )
30013004 } ;
30023005
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-
30163006 if debug_assertions_requested {
30173007 eprintln ! (
30183008 "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3068,61 +3058,16 @@ impl Config {
30683058 }
30693059
30703060 /// 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) {
30763063 PathFreshness :: LastModifiedUpstream { .. } => false ,
30773064 PathFreshness :: HasLocalModifications { .. } => true ,
30783065 }
30793066 }
30803067
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 ( )
31263071 }
31273072}
31283073
0 commit comments