Skip to content

Commit

Permalink
parser: allow / in variable flags
Browse files Browse the repository at this point in the history
also add support for @ and underline characters,
that was missing in before

Closes #276

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Nov 23, 2024
1 parent f9619bd commit c64c77c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oelint_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
r"^(\s*|\t*)addtask\s+(?P<func>[\w\-]+)\s*((before\s*(?P<before>(([^#\n]*(?=after))|([^#\n]*))))|(after\s*(?P<after>(([^#\n]*(?=before))|([^#\n]*)))))*(?P<comment>#.*|.*?)")
__regex_deltask = regex.compile(r"^(\s*|\t*)deltask\s+(?P<func>[\w\-]+)\s*(?P<comment>#.*)*")
__regex_flagass = regex.compile(
r"^(\s*|\t*)(?P<name>([A-Z0-9a-z_.-]|\$|\{|\}|:)+?)\[(?P<ident>(\w|-|\.)+)\](?P<varop>(\s|\t)*(\+|\?|\:|\.)*=(\+|\.)*(\s|\t)*)(?P<varval>.*)")
r"^(\s*|\t*)(?P<name>([A-Z0-9a-z_.-]|\$|\{|\}|:)+?)\[(?P<ident>(\w|-|\.|/|@|_)+)\](?P<varop>(\s|\t)*(\+|\?|\:|\.)*=(\+|\.)*(\s|\t)*)(?P<varval>.*)")
__regex_export_func = regex.compile(r"^EXPORT_FUNCTIONS\s+(?P<func>.*)")
__regex_addpylib = regex.compile(r"^(\s+|\t*)addpylib(\s+|\t+)(?P<path>\$\{LAYERDIR\}/.+)(\s+|\t+)(?P<namespace>.*)")
__regex_unset = regex.compile(r"^(\s+|\t+)*unset(\s+|\t+)+(?P<varname>.+?)(\[*(?P<flag>.+)\])*")
Expand Down
4 changes: 4 additions & 0 deletions tests/test-recipe-new_1.0.bb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
42 changes: 42 additions & 0 deletions tests/test_parser_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit c64c77c

Please sign in to comment.