@@ -19,6 +19,7 @@ use std::process::Command;
19
19
use std:: str:: FromStr ;
20
20
21
21
use crate :: core:: build_steps:: compile:: CODEGEN_BACKEND_PREFIX ;
22
+ use crate :: core:: build_steps:: llvm;
22
23
use crate :: core:: config:: flags:: { Color , Flags , Warnings } ;
23
24
use crate :: utils:: cache:: { Interned , INTERNER } ;
24
25
use crate :: utils:: channel:: { self , GitInfo } ;
@@ -1530,17 +1531,7 @@ impl Config {
1530
1531
config. llvm_build_config = llvm. build_config . clone ( ) . unwrap_or ( Default :: default ( ) ) ;
1531
1532
1532
1533
let asserts = llvm_assertions. unwrap_or ( false ) ;
1533
- config. llvm_from_ci = match llvm. download_ci_llvm {
1534
- Some ( StringOrBool :: String ( s) ) => {
1535
- assert_eq ! ( s, "if-available" , "unknown option `{s}` for download-ci-llvm" ) ;
1536
- crate :: core:: build_steps:: llvm:: is_ci_llvm_available ( & config, asserts)
1537
- }
1538
- Some ( StringOrBool :: Bool ( b) ) => b,
1539
- None => {
1540
- config. channel == "dev"
1541
- && crate :: core:: build_steps:: llvm:: is_ci_llvm_available ( & config, asserts)
1542
- }
1543
- } ;
1534
+ config. llvm_from_ci = config. parse_download_ci_llvm ( llvm. download_ci_llvm , asserts) ;
1544
1535
1545
1536
if config. llvm_from_ci {
1546
1537
// None of the LLVM options, except assertions, are supported
@@ -2104,6 +2095,90 @@ impl Config {
2104
2095
2105
2096
Some ( commit. to_string ( ) )
2106
2097
}
2098
+
2099
+ fn parse_download_ci_llvm (
2100
+ & self ,
2101
+ download_ci_llvm : Option < StringOrBool > ,
2102
+ asserts : bool ,
2103
+ ) -> bool {
2104
+ match download_ci_llvm {
2105
+ None => self . channel == "dev" && llvm:: is_ci_llvm_available ( & self , asserts) ,
2106
+ Some ( StringOrBool :: Bool ( b) ) => b,
2107
+ Some ( StringOrBool :: String ( s) ) if s == "if-available" => {
2108
+ llvm:: is_ci_llvm_available ( & self , asserts)
2109
+ }
2110
+ Some ( StringOrBool :: String ( s) ) if s == "if-unchanged" => {
2111
+ if self
2112
+ . last_modified_commit ( & [ "src/llvm-project" ] , "download-ci-llvm" , true )
2113
+ . is_none ( )
2114
+ {
2115
+ // there are some untracked changes in the the given paths.
2116
+ false
2117
+ } else {
2118
+ llvm:: is_ci_llvm_available ( & self , asserts)
2119
+ }
2120
+ }
2121
+ Some ( StringOrBool :: String ( other) ) => {
2122
+ panic ! ( "unrecognized option for download-ci-llvm: {:?}" , other)
2123
+ }
2124
+ }
2125
+ }
2126
+
2127
+ /// Returns the last commit in which any of `modified_paths` were changed,
2128
+ /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
2129
+ pub fn last_modified_commit (
2130
+ & self ,
2131
+ modified_paths : & [ & str ] ,
2132
+ option_name : & str ,
2133
+ if_unchanged : bool ,
2134
+ ) -> Option < String > {
2135
+ // Handle running from a directory other than the top level
2136
+ let top_level = output ( self . git ( ) . args ( & [ "rev-parse" , "--show-toplevel" ] ) ) ;
2137
+ let top_level = top_level. trim_end ( ) ;
2138
+
2139
+ // Look for a version to compare to based on the current commit.
2140
+ // Only commits merged by bors will have CI artifacts.
2141
+ let merge_base = output (
2142
+ self . git ( )
2143
+ . arg ( "rev-list" )
2144
+ . arg ( format ! ( "--author={}" , self . stage0_metadata. config. git_merge_commit_email) )
2145
+ . args ( & [ "-n1" , "--first-parent" , "HEAD" ] ) ,
2146
+ ) ;
2147
+ let commit = merge_base. trim_end ( ) ;
2148
+ if commit. is_empty ( ) {
2149
+ println ! ( "error: could not find commit hash for downloading components from CI" ) ;
2150
+ println ! ( "help: maybe your repository history is too shallow?" ) ;
2151
+ println ! ( "help: consider disabling `{option_name}`" ) ;
2152
+ println ! ( "help: or fetch enough history to include one upstream commit" ) ;
2153
+ crate :: exit!( 1 ) ;
2154
+ }
2155
+
2156
+ // Warn if there were changes to the compiler or standard library since the ancestor commit.
2157
+ let mut git = self . git ( ) ;
2158
+ git. args ( & [ "diff-index" , "--quiet" , & commit, "--" ] ) ;
2159
+
2160
+ for path in modified_paths {
2161
+ git. arg ( format ! ( "{top_level}/{path}" ) ) ;
2162
+ }
2163
+
2164
+ let has_changes = !t ! ( git. status( ) ) . success ( ) ;
2165
+ if has_changes {
2166
+ if if_unchanged {
2167
+ if self . verbose > 0 {
2168
+ println ! (
2169
+ "warning: saw changes to one of {modified_paths:?} since {commit}; \
2170
+ ignoring `{option_name}`"
2171
+ ) ;
2172
+ }
2173
+ return None ;
2174
+ }
2175
+ println ! (
2176
+ "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
2177
+ ) ;
2178
+ }
2179
+
2180
+ Some ( commit. to_string ( ) )
2181
+ }
2107
2182
}
2108
2183
2109
2184
fn set < T > ( field : & mut T , val : Option < T > ) {
0 commit comments