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 /mesonbuild/interpreterbase/decorators.py | |
| parent | d87d912e5d2345f3c2f73fffb36820040cc997fe (diff) | |
| download | meson-d558291abe9d851584e74f0154be819bc4baf207.tar.gz | |
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.
Diffstat (limited to 'mesonbuild/interpreterbase/decorators.py')
| -rw-r--r-- | mesonbuild/interpreterbase/decorators.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 3ffa67aad..214080d49 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): |
