compilers: avoid one or more version_compare per target

version_compare can take a few milliseconds.  If you have a thousand object files
or a multiple thereof, it adds up.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
pull/12190/merge
Paolo Bonzini 3 weeks ago committed by Eli Schwartz
parent 8400083418
commit 1b15bd0343
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 5
      mesonbuild/backend/ninjabackend.py
  2. 9
      mesonbuild/compilers/mixins/gnu.py
  3. 3
      mesonbuild/compilers/vala.py

@ -623,6 +623,7 @@ class NinjaBackend(backends.Backend):
if ninja is None:
raise MesonException('Could not detect Ninja v1.8.2 or newer')
(self.ninja_command, self.ninja_version) = ninja
self.ninja_has_dyndeps = mesonlib.version_compare(self.ninja_version, '>=1.10.0')
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
tempfilename = outfilename + '~'
with open(tempfilename, 'w', encoding='utf-8') as outfile:
@ -1089,7 +1090,7 @@ class NinjaBackend(backends.Backend):
self.add_build(elem)
def should_use_dyndeps_for_target(self, target: 'build.BuildTarget') -> bool:
if mesonlib.version_compare(self.ninja_version, '<1.10.0'):
if not self.ninja_has_dyndeps:
return False
if 'fortran' in target.compilers:
return True
@ -2451,7 +2452,7 @@ class NinjaBackend(backends.Backend):
'''Use the new Ninja feature for scanning dependencies during build,
rather than up front. Remove this and all old scanning code once Ninja
minimum version is bumped to 1.10.'''
return mesonlib.version_compare(self.ninja_version, '>=1.10.0')
return self.ninja_has_dyndeps
def generate_fortran_dep_hack(self, crstr: str) -> None:
if self.use_dyndeps_for_fortran():

@ -550,16 +550,19 @@ class GnuCompiler(GnuLikeCompiler):
super().__init__()
self.defines = defines or {}
self.base_options.update({OptionKey('b_colorout'), OptionKey('b_lto_threads')})
self._has_color_support = mesonlib.version_compare(self.version, '>=4.9.0')
self._has_wpedantic_support = mesonlib.version_compare(self.version, '>=4.8.0')
self._has_lto_auto_support = mesonlib.version_compare(self.version, '>=10.0')
def get_colorout_args(self, colortype: str) -> T.List[str]:
if mesonlib.version_compare(self.version, '>=4.9.0'):
if self._has_color_support:
return gnu_color_args[colortype][:]
return []
def get_warn_args(self, level: str) -> T.List[str]:
# Mypy doesn't understand cooperative inheritance
args = super().get_warn_args(level)
if mesonlib.version_compare(self.version, '<4.8.0') and '-Wpedantic' in args:
if not self._has_wpedantic_support and '-Wpedantic' in args:
# -Wpedantic was added in 4.8.0
# https://gcc.gnu.org/gcc-4.8/changes.html
args[args.index('-Wpedantic')] = '-pedantic'
@ -612,7 +615,7 @@ class GnuCompiler(GnuLikeCompiler):
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
if threads == 0:
if mesonlib.version_compare(self.version, '>= 10.0'):
if self._has_lto_auto_support:
return ['-flto=auto']
# This matches clang's behavior of using the number of cpus
return [f'-flto={multiprocessing.cpu_count()}']

@ -31,6 +31,7 @@ class ValaCompiler(Compiler):
self.version = version
self.base_options = {OptionKey('b_colorout')}
self.force_link = False
self._has_color_support = version_compare(self.version, '>=0.37.1')
def needs_static_linker(self) -> bool:
return False # Because compiles into C.
@ -80,7 +81,7 @@ class ValaCompiler(Compiler):
return ['--fatal-warnings']
def get_colorout_args(self, colortype: str) -> T.List[str]:
if version_compare(self.version, '>=0.37.1'):
if self._has_color_support:
return ['--color=' + colortype]
return []

Loading…
Cancel
Save