Skip to content

Use the existing LLVM GitInfo for checking rebuilds #59566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/bootstrap/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::process::Command;
use build_helper::output;

use crate::Build;
use crate::config::Config;

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

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

// Make sure git commands work
let out = Command::new("git")
.arg("rev-parse")
.current_dir(dir)
.output()
.expect("failed to spawn git");
if !out.status.success() {
return GitInfo { inner: None }
match Command::new("git")
.arg("rev-parse")
.current_dir(dir)
.output()
{
Ok(ref out) if out.status.success() => {}
_ => return GitInfo { inner: None },
}

// Ok, let's scrape some info
Expand Down
20 changes: 12 additions & 8 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,18 @@ impl Build {
}
None => false,
};
let rust_info = channel::GitInfo::new(&config, &src);
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
let clippy_info = channel::GitInfo::new(&config, &src.join("src/tools/clippy"));
let miri_info = channel::GitInfo::new(&config, &src.join("src/tools/miri"));
let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));
let in_tree_llvm_info = channel::GitInfo::new(&config, &src.join("src/llvm-project"));
let emscripten_llvm_info = channel::GitInfo::new(&config, &src.join("src/llvm-emscripten"));

let ignore_git = config.ignore_git;
let rust_info = channel::GitInfo::new(ignore_git, &src);
let cargo_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/cargo"));
let rls_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rls"));
let clippy_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/clippy"));
let miri_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/miri"));
let rustfmt_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rustfmt"));

// we always try to use git for LLVM builds
let in_tree_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-project"));
let emscripten_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-emscripten"));

let mut build = Build {
initial_rustc: config.initial_rustc.clone(),
Expand Down
36 changes: 12 additions & 24 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,45 +67,38 @@ impl Step for Llvm {
}
}

let (submodule, root, out_dir, llvm_config_ret_dir) = if emscripten {
let (llvm_info, root, out_dir, llvm_config_ret_dir) = if emscripten {
let info = &builder.emscripten_llvm_info;
let dir = builder.emscripten_llvm_out(target);
let config_dir = dir.join("bin");
("src/llvm-emscripten", "src/llvm-emscripten", dir, config_dir)
(info, "src/llvm-emscripten", dir, config_dir)
} else {
let info = &builder.in_tree_llvm_info;
let mut dir = builder.llvm_out(builder.config.build);
if !builder.config.build.contains("msvc") || builder.config.ninja {
dir.push("build");
}
("src/llvm-project", "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
(info, "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
};

let git_output = t!(Command::new("git")
.args(&["rev-parse", "--verify", &format!("@:./{}", submodule)])
.current_dir(&builder.src)
.output());

let llvm_commit = if git_output.status.success() {
Some(git_output.stdout)
} else {
if !llvm_info.is_git() {
println!(
"git could not determine the LLVM submodule commit hash ({}). \
"git could not determine the LLVM submodule commit hash. \
Assuming that an LLVM build is necessary.",
String::from_utf8_lossy(&git_output.stderr),
);
None
};
}

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

if let Some(llvm_commit) = &llvm_commit {
if let Some(llvm_commit) = llvm_info.sha() {
if done_stamp.exists() {
let done_contents = t!(fs::read(&done_stamp));

// If LLVM was already built previously and the submodule's commit didn't change
// from the previous build, then no action is required.
if done_contents == llvm_commit.as_slice() {
if done_contents == llvm_commit.as_bytes() {
return build_llvm_config
}
}
Expand Down Expand Up @@ -258,11 +251,6 @@ impl Step for Llvm {
channel::CFG_RELEASE_NUM,
builder.config.channel,
);
let llvm_info = if self.emscripten {
&builder.emscripten_llvm_info
} else {
&builder.in_tree_llvm_info
};
if let Some(sha) = llvm_info.sha_short() {
default_suffix.push_str("-");
default_suffix.push_str(sha);
Expand Down Expand Up @@ -295,8 +283,8 @@ impl Step for Llvm {

cfg.build();

if let Some(llvm_commit) = llvm_commit {
t!(fs::write(&done_stamp, &llvm_commit));
if let Some(llvm_commit) = llvm_info.sha() {
t!(fs::write(&done_stamp, llvm_commit));
}

build_llvm_config
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub fn prepare_tool_cargo(
cargo.env("CFG_VERSION", builder.rust_version());
cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);

let info = GitInfo::new(&builder.config, &dir);
let info = GitInfo::new(builder.config.ignore_git, &dir);
if let Some(sha) = info.sha() {
cargo.env("CFG_COMMIT_HASH", sha);
}
Expand Down