From b524ee0458cd9dd175cd01d9c1e5e183703a16f8 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Fri, 20 Dec 2024 12:52:34 +0100 Subject: [PATCH] oelint.func.specific: rewrite rule to support testing more than selected overrides, but all Signed-off-by: Konrad Weihmann --- oelint_adv/rule_base/rule_func_spec.py | 49 ++++++++++++-------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/oelint_adv/rule_base/rule_func_spec.py b/oelint_adv/rule_base/rule_func_spec.py index b60e4915..33eb8e78 100644 --- a/oelint_adv/rule_base/rule_func_spec.py +++ b/oelint_adv/rule_base/rule_func_spec.py @@ -3,7 +3,6 @@ from oelint_parser.cls_item import Function, Variable from oelint_parser.cls_stash import Stash from oelint_parser.constants import CONSTANTS -from oelint_parser.parser import INLINE_BLOCK from oelint_parser.rpl_regex import RegexRpl from oelint_adv.cls_rule import Rule @@ -13,36 +12,34 @@ class VarPnBpnUsage(Rule): def __init__(self) -> None: super().__init__(id='oelint.func.specific', severity='error', - message='\'{func}\' is set specific to [\'{machine}\'] or [\'{distro}\'], but isn\'t known from PACKAGES, MACHINE, DISTRO, or resources') + message='\'{func}\' is set specific to [\'{b}\'], but isn\'t known from PACKAGES, MACHINE, DISTRO') def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]: res = [] items = stash.GetItemsFor(filename=_file, classifier=Function.CLASSIFIER, attribute=Function.ATTR_FUNCNAME) - _comp = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER, - attribute=Variable.ATTR_VAR, - attributeValue='COMPATIBLE_MACHINE') + _comp = ''.join(x.VarValueStripped for x in stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER, + attribute=Variable.ATTR_VAR, + attributeValue='COMPATIBLE_MACHINE')) _packages = stash.GetValidPackageNames(_file) - _valid_funcs = ['pkg_preinst', - 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'] - for b in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']: - _valid_funcs += ['{a}-{b}'.format(a=b, b=p) - for p in _packages if p.strip() and p != INLINE_BLOCK] + _machines = CONSTANTS.MachinesKnown + _distros = CONSTANTS.DistrosKnown + _builtin_funcs = ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm', 'ptest'] + _operations = ['append', 'prepend', 'remove'] for i in items: - _distro = i.GetDistroEntry() - if _distro in CONSTANTS.DistrosKnown: - continue - - _machine = i.GetMachineEntry() - if not _machine or _machine in CONSTANTS.MachinesKnown: - continue - if i.FuncName in _valid_funcs: - continue - if _machine in ['ptest']: - # known exceptions - continue - if _comp and RegexRpl.match(''.join(x.VarValueStripped for x in _comp), _machine): - continue - res += self.finding(i.Origin, i.InFileLine, - override_msg=self.Msg.format(func=i.FuncName, machine=_machine, distro=_distro)) + for sub in i.SubItems: + if sub in _operations: + continue + if sub in _distros: + continue + if sub in _packages: + continue + if sub in _machines: + continue + if sub in _builtin_funcs: + continue + if _comp and RegexRpl.match(_comp, sub): + continue + res += self.finding(i.Origin, i.InFileLine, + override_msg=self.Msg.format(func=i.FuncName, b=sub)) return res