mirror of
https://github.com/facebook/proxygen.git
synced 2025-08-07 07:02:53 +03:00
cache results of path_search()
Summary: getdeps currently ends up calling `path_search()` repeatedly searching for various C/C++ compilers in $PATH. It ends up doing this multiple times for each dependency as it computes the project hashes. This updates the `path_search()` function to cache its results so that we don't keep performing the same searches on the file system over and over again. Reviewed By: chadaustin Differential Revision: D16354625 fbshipit-source-id: 116293bd2f636632517d26436b2332e6c10624f1
This commit is contained in:
committed by
Facebook Github Bot
parent
7e7064784d
commit
1c878fcda0
@@ -150,6 +150,10 @@ def add_flag(env, name, flag, append=True):
|
||||
env.set(name, " ".join(val))
|
||||
|
||||
|
||||
_path_search_cache = {}
|
||||
_not_found = object()
|
||||
|
||||
|
||||
def path_search(env, exename, defval=None):
|
||||
""" Search for exename in the PATH specified in env.
|
||||
exename is eg: `ninja` and this function knows to append a .exe
|
||||
@@ -161,6 +165,18 @@ def path_search(env, exename, defval=None):
|
||||
if path is None:
|
||||
return defval
|
||||
|
||||
# The project hash computation code searches for C++ compilers (g++, clang, etc)
|
||||
# repeatedly. Cache the result so we don't end up searching for these over and over
|
||||
# again.
|
||||
cache_key = (path, exename)
|
||||
result = _path_search_cache.get(cache_key, _not_found)
|
||||
if result is _not_found:
|
||||
result = _perform_path_search(path, exename)
|
||||
_path_search_cache[cache_key] = result
|
||||
return result
|
||||
|
||||
|
||||
def _perform_path_search(path, exename):
|
||||
is_win = sys.platform.startswith("win")
|
||||
if is_win:
|
||||
exename = "%s.exe" % exename
|
||||
|
Reference in New Issue
Block a user