From f14328c22f25d01449055b6ed9120d6deac9e0ac Mon Sep 17 00:00:00 2001 From: James R T Date: Fri, 17 Mar 2023 14:37:25 +0800 Subject: [PATCH] bitbake: ConfHandler: Allow the '@' character in variable flag names This patch enables the usage of the '@' character in variable flag names. One use case of variable flags is to assign the network namespaces of some systemd services/targets to configure other parts of the build process of some system. The filenames of systemd services/targets might contain the '@' character if they are template unit files that can take in a single parameter/argument and be instanced multiple times, as indicated by systemd's official manual page. The '@' character is disallowed as the first character in a variable flag name. Imposing more restrictions on the first character is a compromise to make parsing easier and to allow for more options in the future to extend the syntax. This patch is successfully verified by creating a custom BitBake recipe that sets and unsets the value of a variable flag with the '@' character in its name and ensuring that no ParseError is being thrown. Regression tests have also been added to `bb.parse`. `bin/bitbake-selftest` has also been successfully executed and all tests passed. (Bitbake rev: 00f9ab2cacfbd2a63b6b4959cf5401babae7e32a) Signed-off-by: James Raphael Tiovalen Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- bitbake/lib/bb/parse/parse_py/ConfHandler.py | 4 ++-- bitbake/lib/bb/tests/parse.py | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index 3076067287..05c627ec8b 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py @@ -21,7 +21,7 @@ __config_regexp__ = re.compile( r""" ^ (?Pexport\s+)? (?P[a-zA-Z0-9\-_+.${}/~:]+?) - (\[(?P[a-zA-Z0-9\-_+.]+)\])? + (\[(?P[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\])? \s* ( (?P:=) | @@ -45,7 +45,7 @@ __include_regexp__ = re.compile( r"include\s+(.+)" ) __require_regexp__ = re.compile( r"require\s+(.+)" ) __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) -__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" ) +__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" ) __addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" ) def init(data): diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py index ee7f2534f1..d27c7c6f15 100644 --- a/bitbake/lib/bb/tests/parse.py +++ b/bitbake/lib/bb/tests/parse.py @@ -218,3 +218,24 @@ VAR = " \\ with self.assertRaises(bb.BBHandledException): d = bb.parse.handle(f.name, self.d)[''] + + at_sign_in_var_flag = """ +A[flag@.service] = "nonet" +B[flag@.target] = "ntb" + +unset A[flag@.service] +""" + def test_parse_at_sign_in_var_flag(self): + f = self.parsehelper(self.at_sign_in_var_flag) + d = bb.parse.handle(f.name, self.d)[''] + self.assertEqual(d.getVar("A"), None) + self.assertEqual(d.getVar("B"), None) + self.assertEqual(d.getVarFlag("A","flag@.service"), None) + self.assertEqual(d.getVarFlag("B","flag@.target"), "ntb") + + def test_parse_invalid_at_sign_in_var_flag(self): + invalid_at_sign = self.at_sign_in_var_flag.replace("B[f", "B[@f") + f = self.parsehelper(invalid_at_sign) + with self.assertRaises(bb.parse.ParseError): + d = bb.parse.handle(f.name, self.d)[''] +