Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cee58fd

Browse files
committedMar 31, 2019
Auto merge of #59566 - cuviper:llvm-rebuild-sha, r=Mark-Simulacrum
Use the existing LLVM GitInfo for checking rebuilds Fixes #59565
2 parents b0fcfa7 + 49b65e6 commit cee58fd

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed
 

‎src/bootstrap/channel.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::process::Command;
1111
use build_helper::output;
1212

1313
use crate::Build;
14-
use crate::config::Config;
1514

1615
// The version number
1716
pub const CFG_RELEASE_NUM: &str = "1.35.0";
@@ -27,20 +26,20 @@ struct Info {
2726
}
2827

2928
impl GitInfo {
30-
pub fn new(config: &Config, dir: &Path) -> GitInfo {
29+
pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
3130
// See if this even begins to look like a git dir
32-
if config.ignore_git || !dir.join(".git").exists() {
31+
if ignore_git || !dir.join(".git").exists() {
3332
return GitInfo { inner: None }
3433
}
3534

3635
// Make sure git commands work
37-
let out = Command::new("git")
38-
.arg("rev-parse")
39-
.current_dir(dir)
40-
.output()
41-
.expect("failed to spawn git");
42-
if !out.status.success() {
43-
return GitInfo { inner: None }
36+
match Command::new("git")
37+
.arg("rev-parse")
38+
.current_dir(dir)
39+
.output()
40+
{
41+
Ok(ref out) if out.status.success() => {}
42+
_ => return GitInfo { inner: None },
4443
}
4544

4645
// Ok, let's scrape some info

‎src/bootstrap/lib.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,18 @@ impl Build {
360360
}
361361
None => false,
362362
};
363-
let rust_info = channel::GitInfo::new(&config, &src);
364-
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
365-
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
366-
let clippy_info = channel::GitInfo::new(&config, &src.join("src/tools/clippy"));
367-
let miri_info = channel::GitInfo::new(&config, &src.join("src/tools/miri"));
368-
let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));
369-
let in_tree_llvm_info = channel::GitInfo::new(&config, &src.join("src/llvm-project"));
370-
let emscripten_llvm_info = channel::GitInfo::new(&config, &src.join("src/llvm-emscripten"));
363+
364+
let ignore_git = config.ignore_git;
365+
let rust_info = channel::GitInfo::new(ignore_git, &src);
366+
let cargo_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/cargo"));
367+
let rls_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rls"));
368+
let clippy_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/clippy"));
369+
let miri_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/miri"));
370+
let rustfmt_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rustfmt"));
371+
372+
// we always try to use git for LLVM builds
373+
let in_tree_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-project"));
374+
let emscripten_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-emscripten"));
371375

372376
let mut build = Build {
373377
initial_rustc: config.initial_rustc.clone(),

‎src/bootstrap/native.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,38 @@ impl Step for Llvm {
6767
}
6868
}
6969

70-
let (submodule, root, out_dir, llvm_config_ret_dir) = if emscripten {
70+
let (llvm_info, root, out_dir, llvm_config_ret_dir) = if emscripten {
71+
let info = &builder.emscripten_llvm_info;
7172
let dir = builder.emscripten_llvm_out(target);
7273
let config_dir = dir.join("bin");
73-
("src/llvm-emscripten", "src/llvm-emscripten", dir, config_dir)
74+
(info, "src/llvm-emscripten", dir, config_dir)
7475
} else {
76+
let info = &builder.in_tree_llvm_info;
7577
let mut dir = builder.llvm_out(builder.config.build);
7678
if !builder.config.build.contains("msvc") || builder.config.ninja {
7779
dir.push("build");
7880
}
79-
("src/llvm-project", "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
81+
(info, "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
8082
};
8183

82-
let git_output = t!(Command::new("git")
83-
.args(&["rev-parse", "--verify", &format!("@:./{}", submodule)])
84-
.current_dir(&builder.src)
85-
.output());
86-
87-
let llvm_commit = if git_output.status.success() {
88-
Some(git_output.stdout)
89-
} else {
84+
if !llvm_info.is_git() {
9085
println!(
91-
"git could not determine the LLVM submodule commit hash ({}). \
86+
"git could not determine the LLVM submodule commit hash. \
9287
Assuming that an LLVM build is necessary.",
93-
String::from_utf8_lossy(&git_output.stderr),
9488
);
95-
None
96-
};
89+
}
9790

9891
let build_llvm_config = llvm_config_ret_dir
9992
.join(exe("llvm-config", &*builder.config.build));
10093
let done_stamp = out_dir.join("llvm-finished-building");
10194

102-
if let Some(llvm_commit) = &llvm_commit {
95+
if let Some(llvm_commit) = llvm_info.sha() {
10396
if done_stamp.exists() {
10497
let done_contents = t!(fs::read(&done_stamp));
10598

10699
// If LLVM was already built previously and the submodule's commit didn't change
107100
// from the previous build, then no action is required.
108-
if done_contents == llvm_commit.as_slice() {
101+
if done_contents == llvm_commit.as_bytes() {
109102
return build_llvm_config
110103
}
111104
}
@@ -258,11 +251,6 @@ impl Step for Llvm {
258251
channel::CFG_RELEASE_NUM,
259252
builder.config.channel,
260253
);
261-
let llvm_info = if self.emscripten {
262-
&builder.emscripten_llvm_info
263-
} else {
264-
&builder.in_tree_llvm_info
265-
};
266254
if let Some(sha) = llvm_info.sha_short() {
267255
default_suffix.push_str("-");
268256
default_suffix.push_str(sha);
@@ -295,8 +283,8 @@ impl Step for Llvm {
295283

296284
cfg.build();
297285

298-
if let Some(llvm_commit) = llvm_commit {
299-
t!(fs::write(&done_stamp, &llvm_commit));
286+
if let Some(llvm_commit) = llvm_info.sha() {
287+
t!(fs::write(&done_stamp, llvm_commit));
300288
}
301289

302290
build_llvm_config

‎src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn prepare_tool_cargo(
235235
cargo.env("CFG_VERSION", builder.rust_version());
236236
cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
237237

238-
let info = GitInfo::new(&builder.config, &dir);
238+
let info = GitInfo::new(builder.config.ignore_git, &dir);
239239
if let Some(sha) = info.sha() {
240240
cargo.env("CFG_COMMIT_HASH", sha);
241241
}

0 commit comments

Comments
 (0)
Failed to load comments.