diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-19 00:10:51 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-14 22:53:50 -0400 |
commit | d558291abe9d851584e74f0154be819bc4baf207 (patch) | |
tree | de8eebae0071fe076bec2b40ffc56a988faa477c | |
parent | d87d912e5d2345f3c2f73fffb36820040cc997fe (diff) | |
download | meson-d558291abe9d851584e74f0154be819bc4baf207.zip meson-d558291abe9d851584e74f0154be819bc4baf207.tar.gz meson-d558291abe9d851584e74f0154be819bc4baf207.tar.bz2 |
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.
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 3 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/__init__.py | 2 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/decorators.py | 37 |
3 files changed, 40 insertions, 2 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index e97e670..19fc6ae 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.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() diff --git a/mesonbuild/interpreterbase/__init__.py b/mesonbuild/interpreterbase/__init__.py index 53dca49..f0c2002 100644 --- a/mesonbuild/interpreterbase/__init__.py +++ b/mesonbuild/interpreterbase/__init__.py @@ -53,6 +53,7 @@ __all__ = [ 'FeatureCheckBase', 'FeatureNew', 'FeatureDeprecated', + 'FeatureBroken', 'FeatureNewKwargs', 'FeatureDeprecatedKwargs', @@ -118,6 +119,7 @@ from .decorators import ( FeatureCheckBase, FeatureNew, FeatureDeprecated, + FeatureBroken, FeatureNewKwargs, FeatureDeprecatedKwargs, ) diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 3ffa67a..214080d 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -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): |