From 7193d20b87ca8bea4895bd6650ed91f9dcaae399 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Sun, 3 Nov 2024 08:14:09 +0000 Subject: [PATCH] oelint.var.multiinclude: base rule on paths 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 --- .../rule_base/rule_vars_multiinclude.py | 19 ++++++++---- requirements.txt | 2 +- tests/test_class_oelint_var_multiinclude.py | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/oelint_adv/rule_base/rule_vars_multiinclude.py b/oelint_adv/rule_base/rule_vars_multiinclude.py index e0f7f7f9..35c90484 100644 --- a/oelint_adv/rule_base/rule_vars_multiinclude.py +++ b/oelint_adv/rule_base/rule_vars_multiinclude.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 44ee4ab3..1f0d5d07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ anytree ~= 2.12 argcomplete ~= 3.5 colorama ~= 0.4 -oelint-parser ~= 6.2 +oelint-parser ~= 6.3 urllib3 ~= 2.2 \ No newline at end of file diff --git a/tests/test_class_oelint_var_multiinclude.py b/tests/test_class_oelint_var_multiinclude.py index 7bce4dd7..d4307256 100644 --- a/tests/test_class_oelint_var_multiinclude.py +++ b/tests/test_class_oelint_var_multiinclude.py @@ -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): @@ -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):