@@ -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,94 @@ 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
+ // Git is needed to track modifications here, but tarball source is not available.
2112
+ // If not modified here or built through tarball source, we maintain consistency
2113
+ // with '"if available"'.
2114
+ if !self . rust_info . is_from_tarball ( )
2115
+ && self
2116
+ . last_modified_commit ( & [ "src/llvm-project" ] , "download-ci-llvm" , true )
2117
+ . is_none ( )
2118
+ {
2119
+ // there are some untracked changes in the the given paths.
2120
+ false
2121
+ } else {
2122
+ llvm:: is_ci_llvm_available ( & self , asserts)
2123
+ }
2124
+ }
2125
+ Some ( StringOrBool :: String ( other) ) => {
2126
+ panic ! ( "unrecognized option for download-ci-llvm: {:?}" , other)
2127
+ }
2128
+ }
2129
+ }
2130
+
2131
+ /// Returns the last commit in which any of `modified_paths` were changed,
2132
+ /// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
2133
+ pub fn last_modified_commit (
2134
+ & self ,
2135
+ modified_paths : & [ & str ] ,
2136
+ option_name : & str ,
2137
+ if_unchanged : bool ,
2138
+ ) -> Option < String > {
2139
+ // Handle running from a directory other than the top level
2140
+ let top_level = output ( self . git ( ) . args ( & [ "rev-parse" , "--show-toplevel" ] ) ) ;
2141
+ let top_level = top_level. trim_end ( ) ;
2142
+
2143
+ // Look for a version to compare to based on the current commit.
2144
+ // Only commits merged by bors will have CI artifacts.
2145
+ let merge_base = output (
2146
+ self . git ( )
2147
+ . arg ( "rev-list" )
2148
+ . arg ( format ! ( "--author={}" , self . stage0_metadata. config. git_merge_commit_email) )
2149
+ . args ( & [ "-n1" , "--first-parent" , "HEAD" ] ) ,
2150
+ ) ;
2151
+ let commit = merge_base. trim_end ( ) ;
2152
+ if commit. is_empty ( ) {
2153
+ println ! ( "error: could not find commit hash for downloading components from CI" ) ;
2154
+ println ! ( "help: maybe your repository history is too shallow?" ) ;
2155
+ println ! ( "help: consider disabling `{option_name}`" ) ;
2156
+ println ! ( "help: or fetch enough history to include one upstream commit" ) ;
2157
+ crate :: exit!( 1 ) ;
2158
+ }
2159
+
2160
+ // Warn if there were changes to the compiler or standard library since the ancestor commit.
2161
+ let mut git = self . git ( ) ;
2162
+ git. args ( & [ "diff-index" , "--quiet" , & commit, "--" ] ) ;
2163
+
2164
+ for path in modified_paths {
2165
+ git. arg ( format ! ( "{top_level}/{path}" ) ) ;
2166
+ }
2167
+
2168
+ let has_changes = !t ! ( git. status( ) ) . success ( ) ;
2169
+ if has_changes {
2170
+ if if_unchanged {
2171
+ if self . verbose > 0 {
2172
+ println ! (
2173
+ "warning: saw changes to one of {modified_paths:?} since {commit}; \
2174
+ ignoring `{option_name}`"
2175
+ ) ;
2176
+ }
2177
+ return None ;
2178
+ }
2179
+ println ! (
2180
+ "warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
2181
+ ) ;
2182
+ }
2183
+
2184
+ Some ( commit. to_string ( ) )
2185
+ }
2107
2186
}
2108
2187
2109
2188
fn set < T > ( field : & mut T , val : Option < T > ) {
0 commit comments