Improve git lookup by using which() to search PATH if git is not installed in emsdk.

This commit is contained in:
Jukka Jylänki
2014-07-28 20:22:48 +03:00
parent 210400cd9e
commit 584d14db3c

28
emsdk
View File

@@ -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: