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