Allow invoking git.bat as git on Windows (#5118)

In a Chromium build environment on Windows git is supplied by
depot_tools as git.bat. This was causing build errors on Windows that
are most easily reproduced with this command:

  gn gen out\default && gn clean out\default && ninja -C out\default spirv-as

The errors included:

[12:55:40][ERROR   ] Failed to run "['git', 'tag', '--sort=-v:refname']" in "C:\src\chromium\src\third_party\vulkan-deps\spirv-tools\src": [WinError 2] The system cannot find the file specified
[12:55:40][WARNING ] Could not deduce latest release version from history.

This is because 'git' does not resolve to git.bat unless shell=True is
passed to subprocess.Popen. This change passes shell=True but only on
Windows which resolves these errors.
This commit is contained in:
Bruce Dawson 2023-02-22 19:24:34 -08:00 committed by GitHub
parent 9017cfcf62
commit 2cf48e9534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,10 +71,13 @@ def command_output(cmd, directory):
Raises a RuntimeError if the command fails to launch or otherwise fails.
"""
try:
# Set shell=True on Windows so that Chromium's git.bat can be found when
# 'git' is invoked.
p = subprocess.Popen(cmd,
cwd=directory,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
shell=os.name == 'nt')
(stdout, stderr) = p.communicate()
if p.returncode != 0:
logging.error('Failed to run "{}" in "{}": {}'.format(cmd, directory, stderr.decode()))