@@ -16,9 +16,7 @@ use std::{cmp, env, fs};
1616
1717use build_helper:: ci:: CiEnv ;
1818use build_helper:: exit;
19- use build_helper:: git:: {
20- GitConfig , PathFreshness , check_path_modifications, get_closest_merge_commit, output_result,
21- } ;
19+ use build_helper:: git:: { GitConfig , PathFreshness , check_path_modifications, output_result} ;
2220use serde:: { Deserialize , Deserializer } ;
2321use serde_derive:: Deserialize ;
2422#[ cfg( feature = "tracing" ) ]
@@ -3195,19 +3193,22 @@ impl Config {
31953193 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
31963194 // Look for a version to compare to based on the current commit.
31973195 // Only commits merged by bors will have CI artifacts.
3198- match self . last_modified_commit ( & allowed_paths, "download-rustc" , if_unchanged ) {
3199- Some ( commit ) => commit ,
3200- None => {
3196+ match self . check_modifications ( & allowed_paths) {
3197+ PathFreshness :: LastModifiedUpstream { upstream } => upstream ,
3198+ PathFreshness :: HasLocalModifications { upstream } => {
32013199 if if_unchanged {
32023200 return None ;
32033201 }
3204- println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
3205- println ! ( "HELP: maybe your repository history is too shallow?" ) ;
3206- println ! (
3207- "HELP: consider setting `rust.download-rustc=false` in bootstrap.toml"
3208- ) ;
3209- println ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
3210- crate :: exit!( 1 ) ;
3202+
3203+ if self . is_running_on_ci {
3204+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3205+ eprintln ! (
3206+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3207+ ) ;
3208+ return None ;
3209+ }
3210+
3211+ upstream
32113212 }
32123213 }
32133214 } else {
@@ -3216,19 +3217,6 @@ impl Config {
32163217 . expect ( "git-commit-info is missing in the project root" )
32173218 } ;
32183219
3219- if self . is_running_on_ci && {
3220- let head_sha =
3221- output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
3222- let head_sha = head_sha. trim ( ) ;
3223- commit == head_sha
3224- } {
3225- eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
3226- eprintln ! (
3227- "`rustc.download-ci` functionality will be skipped as artifacts are not available."
3228- ) ;
3229- return None ;
3230- }
3231-
32323220 if debug_assertions_requested {
32333221 eprintln ! (
32343222 "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3298,61 +3286,16 @@ impl Config {
32983286 }
32993287
33003288 /// Returns true if any of the `paths` have been modified locally.
3301- fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3302- let freshness =
3303- check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3304- . unwrap ( ) ;
3305- match freshness {
3289+ pub fn has_changes_from_upstream ( & self , paths : & [ & str ] ) -> bool {
3290+ match self . check_modifications ( paths) {
33063291 PathFreshness :: LastModifiedUpstream { .. } => false ,
33073292 PathFreshness :: HasLocalModifications { .. } => true ,
33083293 }
33093294 }
33103295
3311- /// Returns the last commit in which any of `modified_paths` were changed,
3312- /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3313- pub fn last_modified_commit (
3314- & self ,
3315- modified_paths : & [ & str ] ,
3316- option_name : & str ,
3317- if_unchanged : bool ,
3318- ) -> Option < String > {
3319- assert ! (
3320- self . rust_info. is_managed_git_subrepository( ) ,
3321- "Can't run `Config::last_modified_commit` on a non-git source."
3322- ) ;
3323-
3324- // Look for a version to compare to based on the current commit.
3325- // Only commits merged by bors will have CI artifacts.
3326- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
3327- if commit. is_empty ( ) {
3328- println ! ( "error: could not find commit hash for downloading components from CI" ) ;
3329- println ! ( "help: maybe your repository history is too shallow?" ) ;
3330- println ! ( "help: consider disabling `{option_name}`" ) ;
3331- println ! ( "help: or fetch enough history to include one upstream commit" ) ;
3332- crate :: exit!( 1 ) ;
3333- }
3334-
3335- // Warn if there were changes to the compiler or standard library since the ancestor commit.
3336- let mut git = helpers:: git ( Some ( & self . src ) ) ;
3337- git. args ( [ "diff-index" , "--quiet" , & commit, "--" ] ) . args ( modified_paths) ;
3338-
3339- let has_changes = !t ! ( git. as_command_mut( ) . status( ) ) . success ( ) ;
3340- if has_changes {
3341- if if_unchanged {
3342- if self . is_verbose ( ) {
3343- println ! (
3344- "warning: saw changes to one of {modified_paths:?} since {commit}; \
3345- ignoring `{option_name}`"
3346- ) ;
3347- }
3348- return None ;
3349- }
3350- println ! (
3351- "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3352- ) ;
3353- }
3354-
3355- Some ( commit. to_string ( ) )
3296+ fn check_modifications ( & self , paths : & [ & str ] ) -> PathFreshness {
3297+ check_path_modifications ( Some ( & self . src ) , & self . git_config ( ) , paths, CiEnv :: current ( ) )
3298+ . unwrap ( )
33563299 }
33573300
33583301 /// Checks if the given target is the same as the host target.
0 commit comments