data_smart: simple matching of curly brackets inside Python expressions
cover data_smart: simple matching of curly brackets inside Python expressions
This patchset aims at making the parsing of Python expressions in variable definitions a bit more reliable by adding simple matching of curly brackets.
[YOCTO #8849]
Markus Lehtonen (2):
data_smart: simple bracket matching inside python expressions
data_smart: handle '\x7d' in python parsing
lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.1.4
PATCH 1/2 data_smart: simple bracket matching inside python expressions
This expands the python expansion regex by matching curly brackets inside python expressions. In its simplicity it is limited: e.g. it does not correctly handle nested curly brackets or open curly brackets (i.e. '{' without a matching '}') inside python expressions. Making python parsing inside data_smart fully error-free would require significantly more work, basically using/implementing python parser to correctly handle python strings etc.
[YOCTO #8849]
--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/data_smart.py +1 -1
@@ -41,7 +41,7 @@ logger = logging.getLogger("BitBake.Data") __setvar_keyword__ = ["_append", "_prepend", "_remove"] __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend|_remove)(_(?P<add>.*))?$') __expand_var_regexp__ = re.compile(r"\${[^{}@\n\t ]+}") -__expand_python_regexp__ = re.compile(r"\${@.+?}") +__expand_python_regexp__ = re.compile(r"\${@(({[^{]*?})|.)+?}") def infer_caller_details(loginfo, parent = False, varval = True): """Save the caller the trouble of specifying everything."""
Signature · 1 line
2.1.4
Re: [PATCH 1/2] data_smart: simple bracket matching inside python expressions
Quoted 8 lines · Markus Lehtonen
This expands the python expansion regex by matching curly brackets inside python expressions. In its simplicity it is limited: e.g. it does not correctly handle nested curly brackets or open curly brackets (i.e. '{' without a matching '}') inside python expressions. Making python parsing inside
data_smartfully error-free would require significantly more work, basically using/implementing python parser to correctly handle python strings etc.
Quoted 4 lines
[YOCTO #8849]
Signed-off-by Markus Lehtonen <[email protected]>
Will this cause problems with regular variable expansion nested inside of inline python, which is allowed? I.e. ${@ ... '${FOO}'}
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Re: [PATCH 1/2] data_smart: simple bracket matching inside python expressions
Hi Christopher,
On 03/02/16 17:56, "Christopher Larson" <[email protected] on behalf of [email protected]> wrote:
On Wed, Feb 3, 2016 at 3:33 AM, Markus Lehtonen <[email protected]> wrote:
This expands the python expansion regex by matching curly brackets
inside python expressions. In its simplicity it is limited: e.g. it does not correctly handle nested curly brackets or open curly brackets (i.e. '{' without a matching '}') inside python expressions. Making python parsing inside data_smart fully error-free would require significantly more work, basically using/implementing python parser to correctly
handle python strings etc.
[YOCTO #8849]
Will this cause problems with regular variable expansion nested inside of inline python, which is allowed? I.e. ${@ ... '${FOO}'}
No, it wont affect that. First of all because the variable expansion is done before python expansion – ${FOO} would be expanded before the Python regexp is evaluated. Second, the limitation about nested brackets is only about nested brackets inside the python expression (i.e. something like '${FOO${BAR}}').
Thanks,
Markus
PATCH 2/2 data_smart: handle '\x7d' in python parsing
In reply to Markus LehtonenAt least ncurses recipe uses a workaround (for former bitbake python parser) where closing curly bracket inside a python string was replaced by '\x7d' ascii code. The previous "curly bracket matching" patch broke parsing of constructs like this as bitbake wouldn't correctly find the closing bracket. This patch fixes this by accepting '\x7d' as a closing bracket.
Hopefully, this patch could be reverted (and the python regexp thus simplified) in the future after making sure that no recipes use the '\x7d' workaround, anymore.
[YOCTO #8849]
--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/data_smart.py +1 -1
@@ -41,7 +41,7 @@ logger = logging.getLogger("BitBake.Data") __setvar_keyword__ = ["_append", "_prepend", "_remove"] __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend|_remove)(_(?P<add>.*))?$') __expand_var_regexp__ = re.compile(r"\${[^{}@\n\t ]+}") -__expand_python_regexp__ = re.compile(r"\${@(({[^{]*?})|.)+?}") +__expand_python_regexp__ = re.compile(r"\${@(({[^{]*?(}|\\x7d))|.)+?}") def infer_caller_details(loginfo, parent = False, varval = True): """Save the caller the trouble of specifying everything."""
Signature · 1 line
2.1.4
Re: [PATCH 2/2] data_smart: handle '\x7d' in python parsing
Quoted 15 lines · Markus Lehtonen
At least ncurses recipe uses a workaround (for former bitbake python parser) where closing curly bracket inside a python string was replaced
by '\x7d' ascii code. The previous "curly bracket matching" patch broke
parsing of constructs like this as bitbake wouldn't correctly find the
closing bracket. This patch fixes this by accepting '\x7d' as a closing
bracket.Hopefully, this patch could be reverted (and the python regexp thus simplified) in the future after making sure that no recipes use the '\x7d' workaround, anymore.
Quoted 6 lines
[YOCTO #8849]
Signed-off-by Markus Lehtonen <[email protected]>--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
To be honest, the number of recipes which do this is hopefully very very small and we should just go and fix them now?
I'm not sure we want to go ahead and support this.
Cheers,
Richard
Re: [PATCH 2/2] data_smart: handle '\x7d' in python parsing
Hi Richard,
Quoted 18 lines · Richard Purdie
Quoted 17 lines · Markus Lehtonen
At least ncurses recipe uses a workaround (for former bitbake python parser) where closing curly bracket inside a python string was replaced
by '\x7d' ascii code. The previous "curly bracket matching" patch broke
parsing of constructs like this as bitbake wouldn't correctly find the
closing bracket. This patch fixes this by accepting '\x7d' as a closing
bracket.Hopefully, this patch could be reverted (and the python regexp thus simplified) in the future after making sure that no recipes use the '\x7d' workaround, anymore.
[YOCTO #8849]
Quoted 7 lines
Quoted 4 lines
Signed-off-by Markus Lehtonen <[email protected]>--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)To be honest, the number of recipes which do this is hopefully very very small and we should just go and fix them now?
I was pondering this, too, but tried to make sure not to break anything. I can e.g. grep through the layers in git.openembedded.org and git.yoctoproject.org and see if there are any other recipes like this and submit patches to change those.
Quoted 1 line
I'm not sure we want to go ahead and support this.
Me neither ;)
Thanks,
Markus
Re: [PATCH 2/2] data_smart: handle '\x7d' in python parsing
Quoted 30 lines · Markus Lehtonen
Quoted 27 lines · Richard Purdie
Quoted 25 lines · Markus Lehtonen
At least ncurses recipe uses a workaround (for former bitbake python
parser) where closing curly bracket inside a python string was replaced
by '\x7d' ascii code. The previous "curly bracket matching" patch broke
parsing of constructs like this as bitbake wouldn't correctly find
the
closing bracket. This patch fixes this by accepting '\x7d' as a closing
bracket.Hopefully, this patch could be reverted (and the python regexp thus
simplified) in the future after making sure that no recipes use the
'\x7d' workaround, anymore.[YOCTO #8849]
Signed-off-by Markus Lehtonen <[email protected]>--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 2 lines
To be honest, the number of recipes which do this is hopefully very very small and we should just go and fix them now?
I was pondering this, too, but tried to make sure not to break anything. I can e.g. grep through the layers in git.openembedded.org and git.yoctoproject.org and see if there are any other recipes like this and submit patches to change those.
I think that might be the better option, thanks!
Richard
Re: [PATCH 2/2] data_smart: handle '\x7d' in python parsing
Quoted 34 lines · Richard Purdie
Quoted 33 lines · Markus Lehtonen
Quoted 29 lines · Richard Purdie
Quoted 19 lines · Markus Lehtonen
At least ncurses recipe uses a workaround (for former bitbake python
parser) where closing curly bracket inside a python string was replaced
by '\x7d' ascii code. The previous "curly bracket matching" patch broke
parsing of constructs like this as bitbake wouldn't correctly find
the
closing bracket. This patch fixes this by accepting '\x7d' as a closing
bracket.Hopefully, this patch could be reverted (and the python regexp thus
simplified) in the future after making sure that no recipes use the
'\x7d' workaround, anymore.Quoted 6 lines
[YOCTO #8849]
Signed-off-by Markus Lehtonen <[email protected]>--- lib/bb/data_smart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)To be honest, the number of recipes which do this is hopefully very very small and we should just go and fix them now?
Quoted 6 lines
Quoted 4 lines
I was pondering this, too, but tried to make sure not to break anything. I can e.g. grep through the layers in git.openembedded.org and git.yoctoproject.org and see if there are any other recipes like this and submit patches to change those.
I think that might be the better option, thanks!
You were right. At least I didn’t find any other problematic recipes than ncurses. I sent patch for review:
http://lists.openembedded.org/pipermail/openembedded-core/2016-February/116904.html
That should be merged at the same time as the [1/2] bitbake patch in order to avoid build failure.
Cheers,
Markus