@@ -17,6 +17,7 @@ use std::path::{Path, PathBuf};
17
17
use std:: process:: Command ;
18
18
19
19
use crate :: builder:: { Builder , RunConfig , ShouldRun , Step } ;
20
+ use crate :: channel;
20
21
use crate :: config:: TargetSelection ;
21
22
use crate :: util:: get_clang_cl_resource_dir;
22
23
use crate :: util:: { self , exe, output, program_out_of_date, t, up_to_date} ;
@@ -115,32 +116,37 @@ pub fn prebuilt_llvm_config(
115
116
}
116
117
117
118
/// 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 == "" {
136
142
eprintln ! ( "error: could not find commit hash for downloading LLVM" ) ;
137
143
eprintln ! ( "help: maybe your repository history is too shallow?" ) ;
138
144
eprintln ! ( "help: consider disabling `download-ci-llvm`" ) ;
139
145
eprintln ! ( "help: or fetch enough history to include one upstream commit" ) ;
140
146
panic ! ( ) ;
141
147
}
142
148
143
- llvm_sha. to_owned ( )
149
+ llvm_sha
144
150
}
145
151
146
152
/// 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
194
200
}
195
201
196
202
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 ) ;
198
206
let head_sha = output ( config. git ( ) . arg ( "rev-parse" ) . arg ( "HEAD" ) ) ;
199
207
let head_sha = head_sha. trim ( ) ;
200
208
if llvm_sha == head_sha {
@@ -215,7 +223,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
215
223
}
216
224
let llvm_root = config. ci_llvm_root ( ) ;
217
225
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 ( ) ) ;
219
227
let key = format ! ( "{}{}" , llvm_sha, config. llvm_assertions) ;
220
228
if program_out_of_date ( & llvm_stamp, & key) && !config. dry_run {
221
229
download_ci_llvm ( builder, & llvm_sha) ;
@@ -260,7 +268,7 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
260
268
} else {
261
269
& builder. config . stage0_metadata . config . artifacts_server
262
270
} ;
263
- let channel = builder. config . artifact_channel ( llvm_sha) ;
271
+ let channel = builder. config . artifact_channel ( builder , llvm_sha) ;
264
272
let filename = format ! ( "rust-dev-{}-{}.tar.xz" , channel, builder. build. build. triple) ;
265
273
let tarball = rustc_cache. join ( & filename) ;
266
274
if !tarball. exists ( ) {
0 commit comments