Skip to content

Commit

Permalink
oelint.func.specific: rewrite rule
Browse files Browse the repository at this point in the history
to support testing more than selected overrides, but all

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Dec 20, 2024
1 parent da7e19c commit b524ee0
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions oelint_adv/rule_base/rule_func_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b524ee0

Please sign in to comment.