From c64c77cf130016d41c0e42567886bd7a30fb4353 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Sat, 23 Nov 2024 08:46:55 +0000 Subject: [PATCH] parser: allow / in variable flags also add support for @ and underline characters, that was missing in before Closes #276 Signed-off-by: Konrad Weihmann --- oelint_parser/parser.py | 2 +- tests/test-recipe-new_1.0.bb | 4 ++++ tests/test_parser_new.py | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/oelint_parser/parser.py b/oelint_parser/parser.py index 7aeae85..0554f23 100644 --- a/oelint_parser/parser.py +++ b/oelint_parser/parser.py @@ -40,7 +40,7 @@ r"^(\s*|\t*)addtask\s+(?P[\w\-]+)\s*((before\s*(?P(([^#\n]*(?=after))|([^#\n]*))))|(after\s*(?P(([^#\n]*(?=before))|([^#\n]*)))))*(?P#.*|.*?)") __regex_deltask = regex.compile(r"^(\s*|\t*)deltask\s+(?P[\w\-]+)\s*(?P#.*)*") __regex_flagass = regex.compile( - r"^(\s*|\t*)(?P([A-Z0-9a-z_.-]|\$|\{|\}|:)+?)\[(?P(\w|-|\.)+)\](?P(\s|\t)*(\+|\?|\:|\.)*=(\+|\.)*(\s|\t)*)(?P.*)") + r"^(\s*|\t*)(?P([A-Z0-9a-z_.-]|\$|\{|\}|:)+?)\[(?P(\w|-|\.|/|@|_)+)\](?P(\s|\t)*(\+|\?|\:|\.)*=(\+|\.)*(\s|\t)*)(?P.*)") __regex_export_func = regex.compile(r"^EXPORT_FUNCTIONS\s+(?P.*)") __regex_addpylib = regex.compile(r"^(\s+|\t*)addpylib(\s+|\t+)(?P\$\{LAYERDIR\}/.+)(\s+|\t+)(?P.*)") __regex_unset = regex.compile(r"^(\s+|\t+)*unset(\s+|\t+)+(?P.+?)(\[*(?P.+)\])*") diff --git a/tests/test-recipe-new_1.0.bb b/tests/test-recipe-new_1.0.bb index 0da309c..765305f 100644 --- a/tests/test-recipe-new_1.0.bb +++ b/tests/test-recipe-new_1.0.bb @@ -16,3 +16,7 @@ Y = "${P}" SRCREV_foo = "abcd" C += "1" + +VAR_FLAG_WITH_SLASH[abc/def] = "abcd" +VAR_FLAG_WITH_AT[abc@def] = "abcd" +VAR_FLAG_WITH_UNDERLINE[abc_def] = "abcd" diff --git a/tests/test_parser_new.py b/tests/test_parser_new.py index a91ca33..074ddc0 100644 --- a/tests/test_parser_new.py +++ b/tests/test_parser_new.py @@ -206,6 +206,48 @@ def test_var_isappend(self): self.assertEqual(x.IsAppend(), True) self.assertIn(' += ', x.AppendOperation()) + def test_var_flag_slash(self): + from oelint_parser.cls_item import FlagAssignment + from oelint_parser.cls_stash import Stash + + self.__stash = Stash() + self.__stash.AddFile(OelintParserTestNew.RECIPE) + + _stash = self.__stash.GetItemsFor(classifier=FlagAssignment.CLASSIFIER, + attribute=FlagAssignment.ATTR_NAME, + attributeValue="VAR_FLAG_WITH_SLASH") + self.assertTrue(_stash, msg="Stash has items") + for x in _stash: + self.assertEqual(x.Flag, 'abc/def') + + def test_var_flag_at(self): + from oelint_parser.cls_item import FlagAssignment + from oelint_parser.cls_stash import Stash + + self.__stash = Stash() + self.__stash.AddFile(OelintParserTestNew.RECIPE) + + _stash = self.__stash.GetItemsFor(classifier=FlagAssignment.CLASSIFIER, + attribute=FlagAssignment.ATTR_NAME, + attributeValue="VAR_FLAG_WITH_AT") + self.assertTrue(_stash, msg="Stash has items") + for x in _stash: + self.assertEqual(x.Flag, 'abc@def') + + def test_var_flag_underline(self): + from oelint_parser.cls_item import FlagAssignment + from oelint_parser.cls_stash import Stash + + self.__stash = Stash() + self.__stash.AddFile(OelintParserTestNew.RECIPE) + + _stash = self.__stash.GetItemsFor(classifier=FlagAssignment.CLASSIFIER, + attribute=FlagAssignment.ATTR_NAME, + attributeValue="VAR_FLAG_WITH_UNDERLINE") + self.assertTrue(_stash, msg="Stash has items") + for x in _stash: + self.assertEqual(x.Flag, 'abc_def') + if __name__ == "__main__": unittest.main()