@@ -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" ) ]
@@ -2948,17 +2946,22 @@ impl Config {
29482946 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
29492947 // Look for a version to compare to based on the current commit.
29502948 // 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 } => {
29542952 if if_unchanged {
29552953 return None ;
29562954 }
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
29622965 }
29632966 }
29642967 } else {
@@ -2967,19 +2970,6 @@ impl Config {
29672970 . expect ( "git-commit-info is missing in the project root" )
29682971 } ;
29692972
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-
29832973 if debug_assertions_requested {
29842974 eprintln ! (
29852975 "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3035,61 +3025,16 @@ impl Config {
30353025 }
30363026
30373027 /// 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) {
30433030 PathFreshness :: LastModifiedUpstream { .. } => false ,
30443031 PathFreshness :: HasLocalModifications { .. } => true ,
30453032 }
30463033 }
30473034
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 ( )
30933038 }
30943039}
30953040
0 commit comments