Commit 4c4d3911 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

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
parent 9b2c712d
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment