From e517dd9b9bb949e175f743e61f153437814ca9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Tolm=C3=A1cs?= Date: Tue, 28 Jun 2022 18:30:46 +0200 Subject: [PATCH] Use git exec candidate list on all platforms for build (flutter/engine#34294) * Use git exec candidate list on all platforms for build build/git_revision.py now uses a git executable name search list on all platforms, avoiding issues with some Windows installations. * Moving python import to top to satisfy linter * Fixing format error and removing unneeded check * Adding git candidate search to githooks setup.py * Adding missing COM initialization to flutter_tester executable on Windows * Revert "Adding missing COM initialization to" Reason: Added to incorrect branch This reverts commit 1b0da56ffd9af41d457f5a609022d4b0387cd935. * Format fix for setup.py --- engine/src/flutter/build/git_revision.py | 15 +++++++-------- engine/src/flutter/tools/githooks/setup.py | 15 ++++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/engine/src/flutter/build/git_revision.py b/engine/src/flutter/build/git_revision.py index d84886d8b8..0b0653f3ad 100755 --- a/engine/src/flutter/build/git_revision.py +++ b/engine/src/flutter/build/git_revision.py @@ -10,11 +10,7 @@ import sys import subprocess import os import argparse - - -def is_windows(): - os_id = sys.platform - return os_id.startswith('win32') or os_id.startswith('cygwin') +from shutil import which # Natively supported since python 3.3 def get_repository_version(repository): @@ -22,9 +18,12 @@ def get_repository_version(repository): if not os.path.exists(repository): raise IOError('path does not exist') - git = 'git' - if is_windows(): - git = 'git.bat' + git_candidates = ['git', 'git.sh', 'git.bat'] + git = next(filter(which, git_candidates), None) + if git is None: + candidates = "', '".join(git_candidates) + raise IOError(f"Looks like GIT is not on the path. Tried '{candidates}'") + version = subprocess.check_output([ git, '-C', diff --git a/engine/src/flutter/tools/githooks/setup.py b/engine/src/flutter/tools/githooks/setup.py index ea8edf467a..9e677e96b9 100755 --- a/engine/src/flutter/tools/githooks/setup.py +++ b/engine/src/flutter/tools/githooks/setup.py @@ -10,6 +10,7 @@ Sets up githooks. import os import subprocess import sys +from shutil import which # Natively supported since python 3.3 SRC_ROOT = os.path.dirname( os.path.dirname( @@ -19,17 +20,13 @@ SRC_ROOT = os.path.dirname( FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter') -def IsWindows(): - os_id = sys.platform - return os_id.startswith('win32') or os_id.startswith('cygwin') - - def Main(argv): - git = 'git' githooks = os.path.join(FLUTTER_DIR, 'tools', 'githooks') - if IsWindows(): - git = 'git.bat' - githooks = os.path.join(githooks, 'windows') + git_candidates = ['git', 'git.sh', 'git.bat'] + git = next(filter(which, git_candidates), None) + if git is None: + candidates = "', '".join(git_candidates) + raise IOError(f"Looks like GIT is not on the path. Tried '{candidates}'") result = subprocess.run([ git, 'config',