Skip to content

Commit

Permalink
oelint.var.multiinclude: base rule on paths
Browse files Browse the repository at this point in the history
and do not just look at the include name, but
at the actual file included, as they could point
to very much different files.
Fix includes a bump of the parser lib to 6.3

Closes #640

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Nov 3, 2024
1 parent bc84c3e commit 04f531d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
19 changes: 13 additions & 6 deletions oelint_adv/rule_base/rule_vars_multiinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ def __init__(self) -> None:
def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
res = []
items: List[Include] = stash.GetItemsFor(filename=_file, classifier=Include.CLASSIFIER)
keys = []
_map = {}
for i in items:
keys += [x.strip() for x in RegexRpl.split(r'\s|,', i.IncName) if x]
for key in list(set(keys)):
_i = [x for x in items if x.IncName.find(key) != -1]
if len(_i) > 1:
res += self.finding(_i[-1].Origin, _i[-1].InFileLine, self.Msg.replace('{INC}', key))
for incname in RegexRpl.split(r'\s|,', i.IncName):
if not incname or not incname.strip():
continue # pragma: no cover
key = i.FileIncluded if i.FileIncluded else incname.strip()
if key not in _map:
_map[key] = {'key': incname.strip(), 'value': 0, 'origin': i}
_map[key]['value'] += 1
for _, value in _map.items():
if value.get('value', 0) > 1:
res += self.finding(value.get('origin').Origin,
value.get('origin').InFileLine,
self.Msg.replace('{INC}', value.get('key')))
return res
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
anytree ~= 2.12
argcomplete ~= 3.5
colorama ~= 0.4
oelint-parser ~= 6.2
oelint-parser ~= 6.3
urllib3 ~= 2.2
30 changes: 30 additions & 0 deletions tests/test_class_oelint_var_multiinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ class TestClassOelintVarMultiInclude(TestBaseClass):
include abc.inc
''',
},
{
'oelint_adv_test.bb':
'''
require abc.inc
B = "2"
include abc.inc
''',
'abc.inc':
'''
A = "1"
''',
},
],
)
def test_bad(self, input_, id_, occurrence):
Expand All @@ -42,6 +54,24 @@ def test_bad(self, input_, id_, occurrence):
include abc2.inc
''',
},
{
'oelint_adv_test.bb':
'''
include abc.inc
''',
'abc.inc':
'''
A = "1"
''',
'dynamic-layers/test/oelint_adv_test.bb':
'''
include abc.inc
''',
'dynamic-layers/test/abc.inc':
'''
A = "1"
''',
},
],
)
def test_good(self, input_, id_, occurrence):
Expand Down

0 comments on commit 04f531d

Please sign in to comment.