diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs index aa683161b6547..e42b073322e28 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -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"; @@ -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 diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 167455af1f2e6..2394ae7fb7913 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -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(), diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index d93b0f2e0d4b0..fde40b0d1b407 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -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 } } @@ -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); @@ -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 diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 35e0e24014633..23775a91e4ce0 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -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); }