Skip to content
Open
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
36 changes: 33 additions & 3 deletions boring-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn get_boringssl_source_path(config: &Config) -> &Path {
println!("cargo:warning=fetching boringssl git submodule");

run_command(
Command::new("git")
git_command()
.args(["submodule", "update", "--init", "--recursive"])
.arg(&submodule_path),
)
Expand Down Expand Up @@ -497,7 +497,7 @@ fn ensure_patches_applied(config: &Config) -> io::Result<()> {

// NOTE: init git in the copied files, so we can apply patches
if !has_git {
run_command(Command::new("git").arg("init").current_dir(src_path))?;
run_command(git_command().arg("init").current_dir(src_path))?;
}

if config.features.allow_crl_extensions_bad_version {
Expand Down Expand Up @@ -549,7 +549,7 @@ fn apply_patch(config: &Config, patch_name: &str) -> io::Result<()> {
}

run_command(
Command::new("git")
git_command()
.args(&args)
.arg(cmd_path)
.current_dir(src_path),
Expand All @@ -558,6 +558,36 @@ fn apply_patch(config: &Config, patch_name: &str) -> io::Result<()> {
Ok(())
}

/// Repository-local variables, as listed by `git rev-parse --local-env-vars`.
///
/// Git sets these when it runs hooks, so a build started from a hook would
/// otherwise run `git` against the caller's repository instead of the BoringSSL sources.
const GIT_LOCAL_ENV_VARS: &[&str] = &[
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_CONFIG",
"GIT_CONFIG_PARAMETERS",
"GIT_CONFIG_COUNT",
"GIT_OBJECT_DIRECTORY",
"GIT_DIR",
"GIT_WORK_TREE",
"GIT_IMPLICIT_WORK_TREE",
"GIT_GRAFT_FILE",
"GIT_INDEX_FILE",
"GIT_NO_REPLACE_OBJECTS",
"GIT_REPLACE_REF_BASE",
"GIT_PREFIX",
"GIT_SHALLOW_FILE",
"GIT_COMMON_DIR",
];

fn git_command() -> Command {
let mut command = Command::new("git");
for var in GIT_LOCAL_ENV_VARS {
command.env_remove(var);
}
command
}

fn run_command(command: &mut Command) -> io::Result<Output> {
let out = command.output().map_err(|e| {
io::Error::new(
Expand Down