add new FeatureBroken check class for annotating features that are really broken

This is useful for totally terrible stuff that we really dislike, but
for some reason we are afraid to just use `mlog.deprecation()` and
unconditionally tell people so.

Apparently this is because it is totally absolutely vital that, when
telling people something is so broken they should never ever ever use it
no matter what, ever... we can't actually tell them that unless they
bump the minimum version of Meson, because that's our standard way of
introducing a **version number** to tell them when we first started
warning about this.

Sigh. We really want to warn people if they are doing totally broken
stuff no matter what version of Meson they support, because it's not
like fixing the thing that never worked is going to suddenly break old
versions of meson.

So. Here's some new functionality that always warns you, but also tells
you when we started warning.
pull/11879/head
Eli Schwartz 2 years ago
parent d87d912e5d
commit d558291abe
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 3
      mesonbuild/interpreter/interpreter.py
  2. 2
      mesonbuild/interpreterbase/__init__.py
  3. 37
      mesonbuild/interpreterbase/decorators.py

@ -33,7 +33,7 @@ from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typ
from ..interpreterbase import noPosargs, noKwargs, permittedKwargs, noArgsFlattening, noSecondLevelHolderResolving, unholder_return
from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
from ..interpreterbase import Disabler, disablerIfNotFound
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureBroken, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import ObjectHolder, ContextManagerObject
from ..modules import ExtensionModule, ModuleObject, MutableModuleObject, NewExtensionModule, NotFoundExtensionModule
from ..cmake import CMakeInterpreter
@ -2978,6 +2978,7 @@ class Interpreter(InterpreterBase, HoldableObject):
mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets))))
FeatureNew.report(self.subproject)
FeatureDeprecated.report(self.subproject)
FeatureBroken.report(self.subproject)
if not self.is_subproject():
self.print_extra_warnings()
self._print_summary()

@ -53,6 +53,7 @@ __all__ = [
'FeatureCheckBase',
'FeatureNew',
'FeatureDeprecated',
'FeatureBroken',
'FeatureNewKwargs',
'FeatureDeprecatedKwargs',
@ -118,6 +119,7 @@ from .decorators import (
FeatureCheckBase,
FeatureNew,
FeatureDeprecated,
FeatureBroken,
FeatureNewKwargs,
FeatureDeprecatedKwargs,
)

@ -604,6 +604,7 @@ class FeatureCheckBase(metaclass=abc.ABCMeta):
feature_registry: T.ClassVar[T.Dict[str, T.Dict[str, T.Set[T.Tuple[str, T.Optional['mparser.BaseNode']]]]]]
emit_notice = False
unconditional = False
def __init__(self, feature_name: str, feature_version: str, extra_message: str = ''):
self.feature_name = feature_name # type: str
@ -625,7 +626,7 @@ class FeatureCheckBase(metaclass=abc.ABCMeta):
def use(self, subproject: 'SubProject', location: T.Optional['mparser.BaseNode'] = None) -> None:
tv = self.get_target_version(subproject)
# No target version
if tv == '':
if tv == '' and not self.unconditional:
return
# Target version is new enough, don't warn
if self.check_version(tv, self.feature_version) and not self.emit_notice:
@ -761,6 +762,40 @@ class FeatureDeprecated(FeatureCheckBase):
mlog.warning(*args, location=location)
class FeatureBroken(FeatureCheckBase):
"""Checks for broken features"""
# Class variable, shared across all instances
#
# Format: {subproject: {feature_version: set(feature_names)}}
feature_registry = {}
unconditional = True
@staticmethod
def check_version(target_version: str, feature_version: str) -> bool:
# always warn for broken stuff
return False
@staticmethod
def get_warning_str_prefix(tv: str) -> str:
return 'Broken features used:'
@staticmethod
def get_notice_str_prefix(tv: str) -> str:
return ''
def log_usage_warning(self, tv: str, location: T.Optional['mparser.BaseNode']) -> None:
args = [
'Project uses feature that was always broken,',
'and is now deprecated since',
f"'{self.feature_version}':",
f'{self.feature_name}.',
]
if self.extra_message:
args.append(self.extra_message)
mlog.deprecation(*args, location=location)
# This cannot be a dataclass due to https://github.com/python/mypy/issues/5374
class FeatureCheckKwargsBase(metaclass=abc.ABCMeta):

Loading…
Cancel
Save