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: