Blame 0002-CCompiler-Cache-result-of-get_library_dirs.patch

Igor Gnatenko ef6081
From 32dfddd1d42bd64d63b0a8b116e1419e053e7297 Mon Sep 17 00:00:00 2001
Igor Gnatenko ef6081
From: Martin Hostettler <textshell@uchuujin.de>
Igor Gnatenko ef6081
Date: Thu, 26 Apr 2018 21:11:52 +0200
Igor Gnatenko ef6081
Subject: [PATCH 02/16] CCompiler: Cache result of get_library_dirs().
Igor Gnatenko ef6081
Igor Gnatenko ef6081
It is repeatedly used by e.g. guess_external_link_dependencies.
Igor Gnatenko ef6081
---
Igor Gnatenko ef6081
 mesonbuild/compilers/c.py | 10 +++++++++-
Igor Gnatenko ef6081
 1 file changed, 9 insertions(+), 1 deletion(-)
Igor Gnatenko ef6081
Igor Gnatenko ef6081
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
Igor Gnatenko ef6081
index 91c9a166..88571a3c 100644
Igor Gnatenko ef6081
--- a/mesonbuild/compilers/c.py
Igor Gnatenko ef6081
+++ b/mesonbuild/compilers/c.py
Igor Gnatenko ef6081
@@ -44,6 +44,8 @@ from .compilers import (
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
 class CCompiler(Compiler):
Igor Gnatenko ef6081
+    library_dirs_cache = {}
Igor Gnatenko ef6081
+
Igor Gnatenko ef6081
     def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
Igor Gnatenko ef6081
         # If a child ObjC or CPP class has already set it, don't set it ourselves
Igor Gnatenko ef6081
         if not hasattr(self, 'language'):
Igor Gnatenko ef6081
@@ -157,7 +159,7 @@ class CCompiler(Compiler):
Igor Gnatenko ef6081
     def get_std_shared_lib_link_args(self):
Igor Gnatenko ef6081
         return ['-shared']
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
-    def get_library_dirs(self):
Igor Gnatenko ef6081
+    def get_library_dirs_real(self):
Igor Gnatenko ef6081
         env = os.environ.copy()
Igor Gnatenko ef6081
         env['LC_ALL'] = 'C'
Igor Gnatenko ef6081
         stdo = Popen_safe(self.exelist + ['--print-search-dirs'], env=env)[1]
Igor Gnatenko ef6081
@@ -167,6 +169,12 @@ class CCompiler(Compiler):
Igor Gnatenko ef6081
                 return libstr.split(':')
Igor Gnatenko ef6081
         return []
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
+    def get_library_dirs(self):
Igor Gnatenko ef6081
+        key = tuple(self.exelist)
Igor Gnatenko ef6081
+        if key not in self.library_dirs_cache:
Igor Gnatenko ef6081
+            self.library_dirs_cache[key] = self.get_library_dirs_real()
Igor Gnatenko ef6081
+        return self.library_dirs_cache[key][:]
Igor Gnatenko ef6081
+
Igor Gnatenko ef6081
     def get_pic_args(self):
Igor Gnatenko ef6081
         return ['-fPIC']
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
-- 
Igor Gnatenko ef6081
2.17.0
Igor Gnatenko ef6081