summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2025-01-28 16:02:25 -0500
committerEli Schwartz <eschwartz93@gmail.com>2025-03-09 15:29:42 -0400
commit88fbd177c45ed4c92ffb7c8a0eab8204476d5c92 (patch)
tree3d7f67bb3a07137232272eddf4fb6f306e999c6a
parenta25e3e58aae434ce0788b947fcbe7ddbbff9f0e2 (diff)
downloadmeson-88fbd177c45ed4c92ffb7c8a0eab8204476d5c92.tar.gz
Add cache to coredata.get_external_link_args
-rw-r--r--mesonbuild/coredata.py2
-rw-r--r--unittests/allplatformstests.py3
2 files changed, 5 insertions, 0 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index cf3262146..1097d69ec 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -9,6 +9,7 @@ import copy
from . import mlog, options
import pickle, os, uuid
import sys
+from functools import lru_cache
from itertools import chain
from collections import OrderedDict
import textwrap
@@ -511,6 +512,7 @@ class CoreData:
key = OptionKey(f'{lang}_args', machine=for_machine)
return T.cast('T.List[str]', self.optstore.get_value(key))
+ @lru_cache(maxsize=None)
def get_external_link_args(self, for_machine: MachineChoice, lang: str) -> T.List[str]:
# mypy cannot analyze type of OptionKey
linkkey = OptionKey(f'{lang}_link_args', machine=for_machine)
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 1c5b7c588..7f4e1e788 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -4484,12 +4484,15 @@ class AllPlatformTests(BasePlatformTests):
# The compiler either invokes the linker or doesn't. Act accordingly.
with mock.patch.object(cc_type, 'INVOKES_LINKER', True):
+ env.coredata.get_external_link_args.cache_clear()
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto']))
+
## And one that doesn't
#with mock.patch.object(cc_type, 'INVOKES_LINKER', False):
+ # env.coredata.get_external_link_args.cache_clear()
# cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
# link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
# self.assertEqual(sorted(link_args), sorted(['-flto']))