Skip to content

Commit

Permalink
mandatoryvar: skip SRC_URI for pypi and gnomebase
Browse files Browse the repository at this point in the history
as those are known to set SRC_URI as part of the class code

Closes #538

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Mar 19, 2024
1 parent 07344f0 commit dac4221
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion oelint_adv/rule_base/rule_vars_mandatory_exists.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Tuple

from oelint_parser.cls_item import Variable
from oelint_parser.cls_item import Inherit, Variable
from oelint_parser.cls_stash import Stash
from oelint_parser.constants import CONSTANTS

Expand Down Expand Up @@ -28,6 +28,10 @@ def __init__(self) -> None:
'SRC_URI',
]

SRC_URI_EXLCUDES = [
'SRC_URI',
]

def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
res = []
_is_pkg_group = stash.IsPackageGroup(_file)
Expand All @@ -36,11 +40,17 @@ def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
classifier=Variable.CLASSIFIER,
attribute=Variable.ATTR_VAR,
attributeValue=CONSTANTS.VariablesMandatory)
inherits: List[Inherit] = stash.GetItemsFor(filename=_file,
classifier=Inherit.CLASSIFIER)
# pypi and gnomebase base set SRC_URI on their own, do not warn here
src_setting_inherits = any(True for x in inherits if 'pypi' in x.get_items() or 'gnomebase' in x.get_items())
for var_ in CONSTANTS.VariablesMandatory:
if _is_pkg_group and var_ in VarMandatoryExists.PACKAGEGRP_EXCLUDES:
continue
if _is_image and var_ in VarMandatoryExists.IMAGE_EXCLUDES:
continue
if src_setting_inherits and var_ in VarMandatoryExists.SRC_URI_EXLCUDES:
continue
filtered = stash.Reduce(items, attribute=Variable.ATTR_VAR, attributeValue=var_)
if not any(filtered):
res += self.finding(_file, 0,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_class_oelint_var_mandatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ def test_bad_image(self, id_, occurrence, var, extra):
DESCRIPTION = "foo"
''',
},
{
'oelint_adv_test.bb':
'''
SUMMARY = "foo"
DESCRIPTION = "foo"
HOMEPAGE = "foo"
LICENSE = "foo"
inherit pypi
''',
},
{
'oelint_adv_test.bb':
'''
SUMMARY = "foo"
DESCRIPTION = "foo"
HOMEPAGE = "foo"
LICENSE = "foo"
inherit gnomebase
''',
},
],
)
def test_good(self, input_, id_, occurrence):
Expand Down

0 comments on commit dac4221

Please sign in to comment.