@@ -17,6 +17,7 @@ use std::path::{Path, PathBuf};
1717use std:: process:: Command ;
1818
1919use crate :: builder:: { Builder , RunConfig , ShouldRun , Step } ;
20+ use crate :: channel;
2021use crate :: config:: TargetSelection ;
2122use crate :: util:: get_clang_cl_resource_dir;
2223use crate :: util:: { self , exe, output, program_out_of_date, t, up_to_date} ;
@@ -115,32 +116,37 @@ pub fn prebuilt_llvm_config(
115116}
116117
117118/// This retrieves the LLVM sha we *want* to use, according to git history.
118- pub ( crate ) fn detect_llvm_sha ( config : & crate :: config:: Config ) -> String {
119- let mut rev_list = config. git ( ) ;
120- rev_list. args ( & [
121- PathBuf :: from ( "rev-list" ) ,
122- format ! ( "--author={}" , config. stage0_metadata. config. git_merge_commit_email) . into ( ) ,
123- "-n1" . into ( ) ,
124- "--first-parent" . into ( ) ,
125- "HEAD" . into ( ) ,
126- "--" . into ( ) ,
127- config. src . join ( "src/llvm-project" ) ,
128- config. src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
129- // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
130- config. src . join ( "src/version" ) ,
131- ] ) ;
132- let llvm_sha = output ( & mut rev_list) ;
133- let llvm_sha = llvm_sha. trim ( ) ;
134-
135- if llvm_sha == "" {
119+ pub ( crate ) fn detect_llvm_sha ( config : & crate :: config:: Config , is_git : bool ) -> String {
120+ let llvm_sha = if is_git {
121+ let mut rev_list = config. git ( ) ;
122+ rev_list. args ( & [
123+ PathBuf :: from ( "rev-list" ) ,
124+ format ! ( "--author={}" , config. stage0_metadata. config. git_merge_commit_email) . into ( ) ,
125+ "-n1" . into ( ) ,
126+ "--first-parent" . into ( ) ,
127+ "HEAD" . into ( ) ,
128+ "--" . into ( ) ,
129+ config. src . join ( "src/llvm-project" ) ,
130+ config. src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
131+ // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
132+ config. src . join ( "src/version" ) ,
133+ ] ) ;
134+ output ( & mut rev_list) . trim ( ) . to_owned ( )
135+ } else if let Some ( info) = channel:: read_commit_info_file ( & config. src ) {
136+ info. sha . trim ( ) . to_owned ( )
137+ } else {
138+ "" . to_owned ( )
139+ } ;
140+
141+ if & llvm_sha == "" {
136142 eprintln ! ( "error: could not find commit hash for downloading LLVM" ) ;
137143 eprintln ! ( "help: maybe your repository history is too shallow?" ) ;
138144 eprintln ! ( "help: consider disabling `download-ci-llvm`" ) ;
139145 eprintln ! ( "help: or fetch enough history to include one upstream commit" ) ;
140146 panic ! ( ) ;
141147 }
142148
143- llvm_sha. to_owned ( )
149+ llvm_sha
144150}
145151
146152/// Returns whether the CI-found LLVM is currently usable.
@@ -194,7 +200,9 @@ pub(crate) fn is_ci_llvm_available(config: &crate::config::Config, asserts: bool
194200 }
195201
196202 if crate :: util:: CiEnv :: is_ci ( ) {
197- let llvm_sha = detect_llvm_sha ( config) ;
203+ // We assume we have access to git, so it's okay to unconditionally pass
204+ // `true` here.
205+ let llvm_sha = detect_llvm_sha ( config, true ) ;
198206 let head_sha = output ( config. git ( ) . arg ( "rev-parse" ) . arg ( "HEAD" ) ) ;
199207 let head_sha = head_sha. trim ( ) ;
200208 if llvm_sha == head_sha {
@@ -215,7 +223,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
215223 }
216224 let llvm_root = config. ci_llvm_root ( ) ;
217225 let llvm_stamp = llvm_root. join ( ".llvm-stamp" ) ;
218- let llvm_sha = detect_llvm_sha ( & config) ;
226+ let llvm_sha = detect_llvm_sha ( & config, builder . rust_info . is_managed_git_subrepository ( ) ) ;
219227 let key = format ! ( "{}{}" , llvm_sha, config. llvm_assertions) ;
220228 if program_out_of_date ( & llvm_stamp, & key) && !config. dry_run {
221229 download_ci_llvm ( builder, & llvm_sha) ;
@@ -260,7 +268,7 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
260268 } else {
261269 & builder. config . stage0_metadata . config . artifacts_server
262270 } ;
263- let channel = builder. config . artifact_channel ( llvm_sha) ;
271+ let channel = builder. config . artifact_channel ( builder , llvm_sha) ;
264272 let filename = format ! ( "rust-dev-{}-{}.tar.xz" , channel, builder. build. build. triple) ;
265273 let tarball = rustc_cache. join ( & filename) ;
266274 if !tarball. exists ( ) {
0 commit comments