Blob Blame History Raw
From 32dfddd1d42bd64d63b0a8b116e1419e053e7297 Mon Sep 17 00:00:00 2001
From: Martin Hostettler <textshell@uchuujin.de>
Date: Thu, 26 Apr 2018 21:11:52 +0200
Subject: [PATCH 02/16] CCompiler: Cache result of get_library_dirs().

It is repeatedly used by e.g. guess_external_link_dependencies.
---
 mesonbuild/compilers/c.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 91c9a166..88571a3c 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -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']
 
-- 
2.17.0