Fix dawn_version_generator.py on Windows when not using depot_tools

Find git using shutil.which() so extensions are resolved according to PATHEXT.

Remove the "print(e)" that is breaking the expected output.

Bug: dawn:1383
Change-Id: If299b744add0797036598129e08ba7d8c64002e1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87481
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Aleksi Sapon 2022-04-21 21:35:26 +00:00 committed by Dawn LUCI CQ
parent aacad7c65e
commit 4e1c65d030
1 changed files with 10 additions and 8 deletions

View File

@ -13,13 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os, subprocess, sys
import os, subprocess, sys, shutil
from generator_lib import Generator, run_generator, FileRender
def get_git():
return "git.bat" if sys.platform == "win32" else "git"
# Will find git, git.exe, git.bat...
git_exec = shutil.which("git")
if not git_exec:
raise Exception("No git executable found")
return git_exec
def get_gitHash(dawnDir):
@ -61,10 +65,9 @@ def get_gitResolvedHead(dawnDir):
result = subprocess.run(
[get_git(), "rev-parse", "--symbolic-full-name", "HEAD"],
stdout=subprocess.PIPE,
cwd=dawnDir,
)
cwd=dawnDir)
if result.returncode != 0:
raise Exception("Failed to execute git rev-parse to resolve git head.")
raise Exception("Failed to execute git rev-parse to resolve git head:", result.stdout)
resolved = os.path.join(dawnDir, ".git",
result.stdout.decode("utf-8").strip())
@ -102,8 +105,7 @@ class DawnVersionGenerator(Generator):
if gitExists(dawnDir):
try:
return [get_gitHead(dawnDir)] + get_gitResolvedHead(dawnDir)
except Exception as e:
print(e)
except Exception:
return []
return []