Cache compile results in coredata

pull/4952/head
Daniel Mensinger 6 years ago
parent cbdf9d0647
commit c9bd84fd25
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 4
      mesonbuild/compilers/c.py
  2. 21
      mesonbuild/compilers/compilers.py
  3. 2
      mesonbuild/compilers/d.py
  4. 2
      mesonbuild/compilers/vala.py
  5. 1
      mesonbuild/coredata.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,

@ -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

@ -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):

@ -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.

@ -247,6 +247,7 @@ class CoreData:
self.compilers = OrderedDict()
self.cross_compilers = OrderedDict()
self.deps = OrderedDict()
self.compiler_check_cache = OrderedDict()
# Only to print a warning if it changes between Meson invocations.
self.config_files = self.__load_config_files(options.native_file, 'native')
self.libdir_cross_fixup()

Loading…
Cancel
Save