aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2019-02-19 19:34:20 +0100
committerDaniel Mensinger <daniel@mensinger-ka.de>2019-04-28 14:31:49 +0200
commitc9bd84fd25dd24999ac2d20b616e91efb9038905 (patch)
tree75adff6c68e678cbf5ffb459dedafd2bfd8605c0 /mesonbuild/compilers
parentcbdf9d06471ed9b682e94f5d9f4084ee35358778 (diff)
downloadmeson-c9bd84fd25dd24999ac2d20b616e91efb9038905.zip
meson-c9bd84fd25dd24999ac2d20b616e91efb9038905.tar.gz
meson-c9bd84fd25dd24999ac2d20b616e91efb9038905.tar.bz2
Cache compile results in coredata
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py4
-rw-r--r--mesonbuild/compilers/compilers.py21
-rw-r--r--mesonbuild/compilers/d.py2
-rw-r--r--mesonbuild/compilers/vala.py2
4 files changed, 17 insertions, 12 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 94ef336..f0dc201 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -450,7 +450,7 @@ class CCompiler(Compiler):
def _build_wrapper(self, code, env, extra_args, dependencies=None, mode='compile', want_output=False):
args = self._get_compiler_check_args(env, extra_args, dependencies, mode)
- return self.compile(code, args, mode, want_output=want_output)
+ return self.compile(code, args, mode, want_output=want_output, cdata=env.coredata)
def links(self, code, env, *, extra_args=None, dependencies=None):
return self.compiles(code, env, extra_args=extra_args,
@@ -652,7 +652,7 @@ class CCompiler(Compiler):
{delim}\n{define}'''
args = self._get_compiler_check_args(env, extra_args, dependencies,
mode='preprocess').to_native()
- with self.compile(code.format(**fargs), args, 'preprocess') as p:
+ with self.compile(code.format(**fargs), args, 'preprocess', cdata=env.coredata) as p:
if p.returncode != 0:
raise EnvironmentException('Could not get define {!r}'.format(dname))
# Get the preprocessed value after the delimiter,
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 87a83e5..169a973 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -875,8 +875,6 @@ class Compiler:
# Libraries that are internal compiler implementations, and must not be
# manually searched.
internal_libs = ()
- # Cache for the result of compiler checks which can be cached
- compiler_check_cache = {}
def __init__(self, exelist, version, **kwargs):
if isinstance(exelist, str):
@@ -1148,16 +1146,16 @@ class Compiler:
return os.path.join(dirname, 'output.' + suffix)
@contextlib.contextmanager
- def compile(self, code, extra_args=None, mode='link', want_output=False):
+ def compile(self, code, extra_args=None, mode='link', want_output=False, cdata: coredata.CoreData = None):
if extra_args is None:
textra_args = None
extra_args = []
else:
textra_args = tuple(extra_args)
- key = (code, textra_args, mode)
+ key = (tuple(self.exelist), self.version, code, textra_args, mode)
if not want_output:
- if key in self.compiler_check_cache:
- p = self.compiler_check_cache[key]
+ if cdata is not None and key in cdata.compiler_check_cache:
+ p = cdata.compiler_check_cache[key]
mlog.debug('Using cached compile:')
mlog.debug('Cached command line: ', ' '.join(p.commands), '\n')
mlog.debug('Code:\n', code)
@@ -1206,8 +1204,15 @@ class Compiler:
p.input_name = srcname
if want_output:
p.output_name = output
- else:
- self.compiler_check_cache[key] = p
+ elif cdata is not None:
+ # Remove all attributes except the following
+ # This way the object can be serialized
+ tokeep = ['args', 'commands', 'input_name', 'output_name',
+ 'pid', 'returncode', 'stdo', 'stde', 'text_mode']
+ todel = [x for x in vars(p).keys() if x not in tokeep]
+ for i in todel:
+ delattr(p, i)
+ cdata.compiler_check_cache[key] = p
yield p
except (PermissionError, OSError):
# On Windows antivirus programs and the like hold on to files so
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 529919b..e8257d3 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -326,7 +326,7 @@ class DCompiler(Compiler):
def compiles(self, code, env, *, extra_args=None, dependencies=None, mode='compile'):
args = self._get_compiler_check_args(env, extra_args, dependencies, mode)
- with self.compile(code, args, mode) as p:
+ with self.compile(code, args, mode, cdata=env.coredata) as p:
return p.returncode == 0
def has_multi_arguments(self, args, env):
diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py
index 98b8b42..789e00b 100644
--- a/mesonbuild/compilers/vala.py
+++ b/mesonbuild/compilers/vala.py
@@ -121,7 +121,7 @@ class ValaCompiler(Compiler):
args = env.coredata.get_external_args(for_machine, self.language)
vapi_args = ['--pkg', libname]
args += vapi_args
- with self.compile(code, args, 'compile') as p:
+ with self.compile(code, args, 'compile', cdata=env.coredata) as p:
if p.returncode == 0:
return vapi_args
# Not found? Try to find the vapi file itself.