diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 7b573e4e4..e0721145b 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.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(): diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 62f55543a..21a57b44f 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -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()}'] diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index a1d57b38c..35c7a682e 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -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 []