move git command to new execution context
This commit is contained in:
parent
81ee86b23b
commit
def44885ee
4 changed files with 39 additions and 19 deletions
|
|
@ -23,7 +23,6 @@ use crate::core::builder::{
|
|||
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, cargo_profile_var,
|
||||
};
|
||||
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
|
||||
use crate::utils::channel::GitInfo;
|
||||
use crate::utils::exec::{BootstrapCommand, command};
|
||||
use crate::utils::helpers::{add_dylib_path, exe, t};
|
||||
use crate::{Compiler, FileType, Kind, Mode, gha};
|
||||
|
|
@ -278,7 +277,7 @@ pub fn prepare_tool_cargo(
|
|||
cargo.env("CFG_VER_DESCRIPTION", description);
|
||||
}
|
||||
|
||||
let info = GitInfo::new(builder.config.omit_git_hash, &dir);
|
||||
let info = builder.config.git_info(builder.config.omit_git_hash, &dir);
|
||||
if let Some(sha) = info.sha() {
|
||||
cargo.env("CFG_COMMIT_HASH", sha);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,7 +547,7 @@ impl Config {
|
|||
build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
|
||||
}
|
||||
|
||||
if GitInfo::new(false, &config.src).is_from_tarball() && toml.profile.is_none() {
|
||||
if config.git_info(false, &config.src).is_from_tarball() && toml.profile.is_none() {
|
||||
toml.profile = Some("dist".into());
|
||||
}
|
||||
|
||||
|
|
@ -850,19 +850,21 @@ impl Config {
|
|||
let default = config.channel == "dev";
|
||||
config.omit_git_hash = toml.rust.as_ref().and_then(|r| r.omit_git_hash).unwrap_or(default);
|
||||
|
||||
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);
|
||||
config.cargo_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/cargo"));
|
||||
config.rust_info = config.git_info(config.omit_git_hash, &config.src);
|
||||
config.cargo_info =
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/cargo"));
|
||||
config.rust_analyzer_info =
|
||||
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
|
||||
config.clippy_info =
|
||||
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/clippy"));
|
||||
config.miri_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/miri"));
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/clippy"));
|
||||
config.miri_info =
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/miri"));
|
||||
config.rustfmt_info =
|
||||
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
|
||||
config.enzyme_info =
|
||||
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
|
||||
config.in_tree_llvm_info = GitInfo::new(false, &config.src.join("src/llvm-project"));
|
||||
config.in_tree_gcc_info = GitInfo::new(false, &config.src.join("src/gcc"));
|
||||
config.git_info(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
|
||||
config.in_tree_llvm_info = config.git_info(false, &config.src.join("src/llvm-project"));
|
||||
config.in_tree_gcc_info = config.git_info(false, &config.src.join("src/gcc"));
|
||||
|
||||
config.vendor = vendor.unwrap_or(
|
||||
config.rust_info.is_from_tarball()
|
||||
|
|
@ -1329,7 +1331,7 @@ impl Config {
|
|||
|
||||
// NOTE: The check for the empty directory is here because when running x.py the first time,
|
||||
// the submodule won't be checked out. Check it out now so we can build it.
|
||||
if !GitInfo::new(false, &absolute_path).is_managed_git_subrepository()
|
||||
if !self.git_info(false, &absolute_path).is_managed_git_subrepository()
|
||||
&& !helpers::dir_is_empty(&absolute_path)
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ use cc::Tool;
|
|||
use termcolor::{ColorChoice, StandardStream, WriteColor};
|
||||
use utils::build_stamp::BuildStamp;
|
||||
use utils::channel::GitInfo;
|
||||
use utils::execution_context::ExecutionContext;
|
||||
|
||||
use crate::core::builder;
|
||||
use crate::core::builder::Kind;
|
||||
|
|
@ -616,7 +617,7 @@ impl Build {
|
|||
return;
|
||||
}
|
||||
|
||||
if GitInfo::new(false, Path::new(submodule)).is_managed_git_subrepository() {
|
||||
if config.git_info(false, Path::new(submodule)).is_managed_git_subrepository() {
|
||||
config.update_submodule(submodule);
|
||||
}
|
||||
}
|
||||
|
|
@ -2015,6 +2016,16 @@ to download LLVM rather than building it.
|
|||
stream.reset().unwrap();
|
||||
result
|
||||
}
|
||||
|
||||
pub fn exec_ctx(&self) -> &ExecutionContext {
|
||||
&self.config.exec_ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<ExecutionContext> for Build {
|
||||
fn as_ref(&self) -> &ExecutionContext {
|
||||
&self.config.exec_ctx
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use super::execution_context::ExecutionContext;
|
||||
use super::helpers;
|
||||
use crate::Build;
|
||||
use crate::utils::helpers::{start_process, t};
|
||||
|
|
@ -34,7 +35,7 @@ pub struct Info {
|
|||
}
|
||||
|
||||
impl GitInfo {
|
||||
pub fn new(omit_git_hash: bool, dir: &Path) -> GitInfo {
|
||||
pub fn new(omit_git_hash: bool, dir: &Path, exec_ctx: impl AsRef<ExecutionContext>) -> GitInfo {
|
||||
// See if this even begins to look like a git dir
|
||||
if !dir.join(".git").exists() {
|
||||
match read_commit_info_file(dir) {
|
||||
|
|
@ -43,11 +44,18 @@ impl GitInfo {
|
|||
}
|
||||
}
|
||||
|
||||
// Make sure git commands work
|
||||
match helpers::git(Some(dir)).arg("rev-parse").as_command_mut().output() {
|
||||
Ok(ref out) if out.status.success() => {}
|
||||
_ => return GitInfo::Absent,
|
||||
let mut git_command = helpers::git(Some(dir));
|
||||
git_command.arg("rev-parse");
|
||||
let output = git_command.allow_failure().run_capture_stdout_exec_ctx(exec_ctx);
|
||||
|
||||
if output.is_failure() {
|
||||
return GitInfo::Absent;
|
||||
}
|
||||
// Make sure git commands work
|
||||
// match helpers::git(Some(dir)).arg("rev-parse").as_command_mut().output() {
|
||||
// Ok(ref out) if out.status.success() => {}
|
||||
// _ => return GitInfo::Absent,
|
||||
// }
|
||||
|
||||
// If we're ignoring the git info, we don't actually need to collect it, just make sure this
|
||||
// was a git repo in the first place.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue