From e9d255de1580235fff96e110001ce4293006caaa Mon Sep 17 00:00:00 2001 From: Liza Chevalier Date: Mon, 27 Oct 2025 17:25:51 -0500 Subject: compilers/gnu: use version attributes for feature checks Replace the hardcoded version strings with class attributes to allow subclasses to override them. --- mesonbuild/compilers/mixins/gnu.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index bedee621a..239d7ef3a 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -547,13 +547,18 @@ class GnuCompiler(GnuLikeCompiler): """ id = 'gcc' + _COLOR_VERSION = '>=4.9.0' + _WPEDANTIC_VERSION = '>=4.8.0' + _LTO_AUTO_VERSION = '>=10.0' + _USE_MOLD_VERSION = '>=12.0.1' + def __init__(self, defines: T.Optional[T.Dict[str, str]]): 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') + self._has_color_support = mesonlib.version_compare(self.version, self._COLOR_VERSION) + self._has_wpedantic_support = mesonlib.version_compare(self.version, self._WPEDANTIC_VERSION) + self._has_lto_auto_support = mesonlib.version_compare(self.version, self._LTO_AUTO_VERSION) def get_colorout_args(self, colortype: str) -> T.List[str]: if self._has_color_support: @@ -627,7 +632,7 @@ class GnuCompiler(GnuLikeCompiler): @classmethod def use_linker_args(cls, linker: str, version: str) -> T.List[str]: - if linker == 'mold' and mesonlib.version_compare(version, '>=12.0.1'): + if linker == 'mold' and mesonlib.version_compare(version, cls._USE_MOLD_VERSION): return ['-fuse-ld=mold'] return super().use_linker_args(linker, version) -- cgit v1.2.3