Patchwork [bitbake-devel,v2] ast: Fix support for anonymous methods in wildcard .bbappend files

login
register
mail settings
Submitter Jacob Kroon
Date Feb. 22, 2014, 4:52 p.m.
Message ID <1393087949-6183-1-git-send-email-jacob.kroon@mikrodidakt.se>
Download mbox | patch
Permalink /patch/67161/
State New
Headers show

Comments

Jacob Kroon - Feb. 22, 2014, 4:52 p.m.
When using wildcard .bbappend files with anonymous methods in them,
bitbake/python fails to parse the generated code since the '%' is encoded
in the generated method name.

Fix this by including '%' in the convert-to-underscore list during
method name mangling.

While we're at it, move the method name mangling translation table
to a class variable, as suggested by Chris Larson.

[YOCTO #5864]

Signed-off-by: Jacob Kroon <jacob.kroon@mikrodidakt.se>
---
 lib/bb/parse/ast.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Khem Raj - Feb. 22, 2014, 6:12 p.m.
On Sat, Feb 22, 2014 at 8:52 AM, Jacob Kroon <jacob.kroon@mikrodidakt.se> wrote:
> +    tr_tbl = string.maketrans('/.+-@%', '______')
> +

why is this moved out
Jacob Kroon - Feb. 22, 2014, 6:24 p.m.
On Sat, Feb 22, 2014 at 7:12 PM, Khem Raj <raj.khem@gmail.com> wrote:

> On Sat, Feb 22, 2014 at 8:52 AM, Jacob Kroon <jacob.kroon@mikrodidakt.se>
> wrote:
> > +    tr_tbl = string.maketrans('/.+-@%', '______')
> > +
>
> why is this moved out
>

The translation table never changes, so instead of creating one on-the-fly
in each invocation, the idea was to keep and reuse the table in a class
variable.

Patch

diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index a202053..d8c141b 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -139,6 +139,8 @@  class DataNode(AstNode):
             data.setVar(key, val, **loginfo)
 
 class MethodNode(AstNode):
+    tr_tbl = string.maketrans('/.+-@%', '______')
+
     def __init__(self, filename, lineno, func_name, body):
         AstNode.__init__(self, filename, lineno)
         self.func_name = func_name
@@ -147,7 +149,7 @@  class MethodNode(AstNode):
     def eval(self, data):
         text = '\n'.join(self.body)
         if self.func_name == "__anonymous":
-            funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(string.maketrans('/.+-@', '_____'))))
+            funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl)))
             text = "def %s(d):\n" % (funcname) + text
             bb.methodpool.insert_method(funcname, text, self.filename)
             anonfuncs = data.getVar('__BBANONFUNCS') or []