@@ -13,6 +13,7 @@ use std::str::FromStr;
13
13
use std:: sync:: OnceLock ;
14
14
use std:: { cmp, env, fs} ;
15
15
16
+ use build_helper:: ci:: CiEnv ;
16
17
use build_helper:: exit;
17
18
use build_helper:: git:: { GitConfig , get_closest_merge_commit, output_result} ;
18
19
use serde:: { Deserialize , Deserializer } ;
@@ -2718,21 +2719,28 @@ impl Config {
2718
2719
download_rustc : Option < StringOrBool > ,
2719
2720
llvm_assertions : bool ,
2720
2721
) -> Option < String > {
2722
+ if !is_download_ci_available ( & self . build . triple , llvm_assertions) {
2723
+ return None ;
2724
+ }
2725
+
2721
2726
// If `download-rustc` is not set, default to rebuilding.
2722
2727
let if_unchanged = match download_rustc {
2723
2728
None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
2724
2729
Some ( StringOrBool :: Bool ( true ) ) => false ,
2725
- Some ( StringOrBool :: String ( s) ) if s == "if-unchanged" => {
2726
- is_download_ci_available ( & self . build . triple , llvm_assertions)
2727
- }
2730
+ Some ( StringOrBool :: String ( s) ) if s == "if-unchanged" => true ,
2728
2731
Some ( StringOrBool :: String ( other) ) => {
2729
2732
panic ! ( "unrecognized option for download-rustc: {other}" )
2730
2733
}
2731
2734
} ;
2732
2735
2733
2736
// Look for a version to compare to based on the current commit.
2734
2737
// Only commits merged by bors will have CI artifacts.
2735
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
2738
+ let commit = get_closest_merge_commit (
2739
+ Some ( & self . src ) ,
2740
+ & self . git_config ( ) ,
2741
+ & [ self . src . join ( "compiler" ) , self . src . join ( "library" ) ] ,
2742
+ )
2743
+ . unwrap ( ) ;
2736
2744
if commit. is_empty ( ) {
2737
2745
println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
2738
2746
println ! ( "HELP: maybe your repository history is too shallow?" ) ;
@@ -2741,6 +2749,19 @@ impl Config {
2741
2749
crate :: exit!( 1 ) ;
2742
2750
}
2743
2751
2752
+ if CiEnv :: is_ci ( ) && {
2753
+ let head_sha =
2754
+ output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
2755
+ let head_sha = head_sha. trim ( ) ;
2756
+ commit == head_sha
2757
+ } {
2758
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
2759
+ eprintln ! (
2760
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
2761
+ ) ;
2762
+ return None ;
2763
+ }
2764
+
2744
2765
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2745
2766
let has_changes = !t ! ( helpers:: git( Some ( & self . src) )
2746
2767
. args( [ "diff-index" , "--quiet" , & commit] )
0 commit comments