CCompiler: Cache result of get_library_dirs().
It is repeatedly used by e.g. guess_external_link_dependencies.
@@ -44,6 +44,8 @@ from .compilers import (
class CCompiler(Compiler):
+ library_dirs_cache = {}
+
def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
# If a child ObjC or CPP class has already set it, don't set it ourselves
if not hasattr(self, 'language'):
@@ -157,7 +159,7 @@ class CCompiler(Compiler):
def get_std_shared_lib_link_args(self):
return ['-shared']
- def get_library_dirs(self):
+ def get_library_dirs_real(self):
env = os.environ.copy()
env['LC_ALL'] = 'C'
stdo = Popen_safe(self.exelist + ['--print-search-dirs'], env=env)[1]
@@ -167,6 +169,12 @@ class CCompiler(Compiler):
return libstr.split(':')
return []
+ def get_library_dirs(self):
+ key = tuple(self.exelist)
+ if key not in self.library_dirs_cache:
+ self.library_dirs_cache[key] = self.get_library_dirs_real()
+ return self.library_dirs_cache[key][:]
+
def get_pic_args(self):
return ['-fPIC']
