Improve git lookup by using which() to search PATH if git is not installed in emsdk.
This commit is contained in:
28
emsdk
28
emsdk
@@ -297,6 +297,32 @@ def run_get_output(cmd, cwd=None):
|
|||||||
(stdout, stderr) = process.communicate()
|
(stdout, stderr) = process.communicate()
|
||||||
return (process.returncode, stdout, stderr)
|
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
|
warnonce_git_not_found = False
|
||||||
|
|
||||||
def GIT():
|
def GIT():
|
||||||
@@ -308,7 +334,7 @@ def GIT():
|
|||||||
return git
|
return git
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
git = 'git'
|
git = which('git')
|
||||||
try:
|
try:
|
||||||
(ret, stdout, stderr) = run_get_output([git, '--version'])
|
(ret, stdout, stderr) = run_get_output([git, '--version'])
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user