Skip to content

Commit def4488

Browse files
committed
move git command to new execution context
1 parent 81ee86b commit def4488

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::core::builder::{
2323
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, cargo_profile_var,
2424
};
2525
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
26-
use crate::utils::channel::GitInfo;
2726
use crate::utils::exec::{BootstrapCommand, command};
2827
use crate::utils::helpers::{add_dylib_path, exe, t};
2928
use crate::{Compiler, FileType, Kind, Mode, gha};
@@ -278,7 +277,7 @@ pub fn prepare_tool_cargo(
278277
cargo.env("CFG_VER_DESCRIPTION", description);
279278
}
280279

281-
let info = GitInfo::new(builder.config.omit_git_hash, &dir);
280+
let info = builder.config.git_info(builder.config.omit_git_hash, &dir);
282281
if let Some(sha) = info.sha() {
283282
cargo.env("CFG_COMMIT_HASH", sha);
284283
}

src/bootstrap/src/core/config/config.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl Config {
547547
build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
548548
}
549549

550-
if GitInfo::new(false, &config.src).is_from_tarball() && toml.profile.is_none() {
550+
if config.git_info(false, &config.src).is_from_tarball() && toml.profile.is_none() {
551551
toml.profile = Some("dist".into());
552552
}
553553

@@ -850,19 +850,21 @@ impl Config {
850850
let default = config.channel == "dev";
851851
config.omit_git_hash = toml.rust.as_ref().and_then(|r| r.omit_git_hash).unwrap_or(default);
852852

853-
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);
854-
config.cargo_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/cargo"));
853+
config.rust_info = config.git_info(config.omit_git_hash, &config.src);
854+
config.cargo_info =
855+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/cargo"));
855856
config.rust_analyzer_info =
856-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
857+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
857858
config.clippy_info =
858-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/clippy"));
859-
config.miri_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/miri"));
859+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/clippy"));
860+
config.miri_info =
861+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/miri"));
860862
config.rustfmt_info =
861-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
863+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
862864
config.enzyme_info =
863-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
864-
config.in_tree_llvm_info = GitInfo::new(false, &config.src.join("src/llvm-project"));
865-
config.in_tree_gcc_info = GitInfo::new(false, &config.src.join("src/gcc"));
865+
config.git_info(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
866+
config.in_tree_llvm_info = config.git_info(false, &config.src.join("src/llvm-project"));
867+
config.in_tree_gcc_info = config.git_info(false, &config.src.join("src/gcc"));
866868

867869
config.vendor = vendor.unwrap_or(
868870
config.rust_info.is_from_tarball()
@@ -1329,7 +1331,7 @@ impl Config {
13291331

13301332
// NOTE: The check for the empty directory is here because when running x.py the first time,
13311333
// the submodule won't be checked out. Check it out now so we can build it.
1332-
if !GitInfo::new(false, &absolute_path).is_managed_git_subrepository()
1334+
if !self.git_info(false, &absolute_path).is_managed_git_subrepository()
13331335
&& !helpers::dir_is_empty(&absolute_path)
13341336
{
13351337
return;

src/bootstrap/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use cc::Tool;
3232
use termcolor::{ColorChoice, StandardStream, WriteColor};
3333
use utils::build_stamp::BuildStamp;
3434
use utils::channel::GitInfo;
35+
use utils::execution_context::ExecutionContext;
3536

3637
use crate::core::builder;
3738
use crate::core::builder::Kind;
@@ -616,7 +617,7 @@ impl Build {
616617
return;
617618
}
618619

619-
if GitInfo::new(false, Path::new(submodule)).is_managed_git_subrepository() {
620+
if config.git_info(false, Path::new(submodule)).is_managed_git_subrepository() {
620621
config.update_submodule(submodule);
621622
}
622623
}
@@ -2015,6 +2016,16 @@ to download LLVM rather than building it.
20152016
stream.reset().unwrap();
20162017
result
20172018
}
2019+
2020+
pub fn exec_ctx(&self) -> &ExecutionContext {
2021+
&self.config.exec_ctx
2022+
}
2023+
}
2024+
2025+
impl AsRef<ExecutionContext> for Build {
2026+
fn as_ref(&self) -> &ExecutionContext {
2027+
&self.config.exec_ctx
2028+
}
20182029
}
20192030

20202031
#[cfg(unix)]

src/bootstrap/src/utils/channel.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use std::fs;
99
use std::path::Path;
1010

11+
use super::execution_context::ExecutionContext;
1112
use super::helpers;
1213
use crate::Build;
1314
use crate::utils::helpers::{start_process, t};
@@ -34,7 +35,7 @@ pub struct Info {
3435
}
3536

3637
impl GitInfo {
37-
pub fn new(omit_git_hash: bool, dir: &Path) -> GitInfo {
38+
pub fn new(omit_git_hash: bool, dir: &Path, exec_ctx: impl AsRef<ExecutionContext>) -> GitInfo {
3839
// See if this even begins to look like a git dir
3940
if !dir.join(".git").exists() {
4041
match read_commit_info_file(dir) {
@@ -43,11 +44,18 @@ impl GitInfo {
4344
}
4445
}
4546

46-
// Make sure git commands work
47-
match helpers::git(Some(dir)).arg("rev-parse").as_command_mut().output() {
48-
Ok(ref out) if out.status.success() => {}
49-
_ => return GitInfo::Absent,
47+
let mut git_command = helpers::git(Some(dir));
48+
git_command.arg("rev-parse");
49+
let output = git_command.allow_failure().run_capture_stdout_exec_ctx(exec_ctx);
50+
51+
if output.is_failure() {
52+
return GitInfo::Absent;
5053
}
54+
// Make sure git commands work
55+
// match helpers::git(Some(dir)).arg("rev-parse").as_command_mut().output() {
56+
// Ok(ref out) if out.status.success() => {}
57+
// _ => return GitInfo::Absent,
58+
// }
5159

5260
// If we're ignoring the git info, we don't actually need to collect it, just make sure this
5361
// was a git repo in the first place.

0 commit comments

Comments
 (0)