From 584d14db3c2a9744b8b9a02c722d056f439c4fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Mon, 28 Jul 2014 20:22:48 +0300 Subject: [PATCH] Improve git lookup by using which() to search PATH if git is not installed in emsdk. --- emsdk | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/emsdk b/emsdk index 8291909..7386b0f 100755 --- a/emsdk +++ b/emsdk @@ -297,6 +297,32 @@ def run_get_output(cmd, cwd=None): (stdout, stderr) = process.communicate() return (process.returncode, stdout, stderr) +# Finds the given executable 'program' in PATH. Operates like the Unix tool 'which'. +def which(program): + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + if WINDOWS and not '.' in fname: + if is_exe(exe_file + '.exe'): + return exe_file + '.exe' + if is_exe(exe_file + '.cmd'): + return exe_file + '.cmd' + if is_exe(exe_file + '.bat'): + return exe_file + '.bat' + + return None + warnonce_git_not_found = False def GIT(): @@ -308,7 +334,7 @@ def GIT(): return git except: pass - git = 'git' + git = which('git') try: (ret, stdout, stderr) = run_get_output([git, '--version']) if ret == 0: