Windows: search PATH for patch utility (#40513)

Previously, we only searched for `patch` inside of whatever Git
installation was available because the most common installation of Git
available on Windows had `patch`. That's not true for all possible
installations of Git though, so this updates the search to also check
PATH.
This commit is contained in:
John W. Parent 2023-10-24 19:37:26 -04:00 committed by GitHub
parent 2d203df075
commit e1da9339d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@
import inspect
import os
import os.path
import pathlib
import sys
import llnl.util.filesystem
@ -36,10 +37,12 @@ def apply_patch(stage, patch_path, level=1, working_dir="."):
"""
git_utils_path = os.environ.get("PATH", "")
if sys.platform == "win32":
git = which_string("git", required=True)
git_root = git.split("\\")[:-2]
git_root.extend(["usr", "bin"])
git_utils_path = os.sep.join(git_root)
git = which_string("git")
if git:
git = pathlib.Path(git)
git_root = git.parent.parent
git_root = git_root / "usr" / "bin"
git_utils_path = os.pathsep.join([str(git_root), git_utils_path])
# TODO: Decouple Spack's patch support on Windows from Git
# for Windows, and instead have Spack directly fetch, install, and