From 9498542d957fdbe53f7e8d94c6d22ba1e78b6fb3 Mon Sep 17 00:00:00 2001 From: juj Date: Wed, 13 Apr 2022 02:08:02 +0300 Subject: [PATCH] Cache git executable search into a variable. (#1021) * Cache git executable search into a variable. This helps reduce noise in the verbose debug logging output messages when EMSDK_VERBOSE=1 is enabled. * Flake * Mark cached_git_executable global --- emsdk.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/emsdk.py b/emsdk.py index e618e37..90b4c55 100644 --- a/emsdk.py +++ b/emsdk.py @@ -735,11 +735,17 @@ def run_get_output(cmd, cwd=None): return (process.returncode, stdout, stderr) +cached_git_executable = None + + # must_succeed: If false, the search is performed silently without printing out # errors if not found. Empty string is returned if git is not found. # If true, the search is required to succeed, and the execution # will terminate with sys.exit(1) if not found. def GIT(must_succeed=True): + global cached_git_executable + if cached_git_executable is not None: + return cached_git_executable # The order in the following is important, and specifies the preferred order # of using the git tools. Primarily use git from emsdk if installed. If not, # use system git. @@ -748,6 +754,7 @@ def GIT(must_succeed=True): try: ret, stdout, stderr = run_get_output([git, '--version']) if ret == 0: + cached_git_executable = git return git except: pass