Skip to contentSkip to conversation

Substitute '~' when naming anonymous functions

PATCH In review Paul Barker 1 participant 3 messages Jul 20, 2021

lore
Share & tools
lore
#0 lore raw

cover Substitute '~' when naming anonymous functions

When looking at meta-linux-mainline in the layer index I realised that the recipe version shown were out-of-date. The most recent update log [1] showed that the layer had failed to parse. Looking at the log it was obvious that this was due to the path in which the layer had been cloned, not due to any issue in the layer itself. As git repositories on sourcehut use '~' as a prefix to the username in the URL, this character ended up in the local path to the layer. When bitbake parsed the recipes in this layer, the '~' character ended up in the function name generated for an anonymous Python function. Since '~' isn't a valid character in a Python function name we got a pile of errors.

We already have a translation table to handle characters which aren't valid in Python function names, we just need to add '~' to the table.

Paul Barker (1):
parse/ast: Substitute '~' when naming anonymous functions

 lib/bb/parse/ast.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 parse/ast: Substitute '~' when naming anonymous functions

When parsing an anonymous python function, bitbake generates a name for the function based on the full path to the file in which it was found. As not all characters which are valid in file paths are valid in Python function names we have a translation table. However, this translation table was missing an entry for '~'.

---
 lib/bb/parse/ast.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/parse/ast.py +1 -1
index 50a88f7da7..743ea0dfc0 100644
@@ -145,7 +145,7 @@ class DataNode(AstNode):
             data.setVar(key, val, parsing=True, **loginfo)
 
 class MethodNode(AstNode):
-    tr_tbl = str.maketrans('/.+-@%&', '_______')
+    tr_tbl = str.maketrans('/.+-@%&~', '________')
 
     def __init__(self, filename, lineno, func_name, body, python, fakeroot):
         AstNode.__init__(self, filename, lineno)
Signature · 1 line
2.26.2
#2 lore raw
In reply to Paul Barker
Quoted 10 lines · On Tue, 20 Jul 2021 18:16:27 +0100 "Paul Barker" <[email protected]> wrote:

When looking at meta-linux-mainline in the layer index I realised that the recipe version shown were out-of-date. The most recent update log [1] showed that the layer had failed to parse. Looking at the log it was obvious that this was due to the path in which the layer had been cloned, not due to any issue in the layer itself. As git repositories on sourcehut use '~' as a prefix to the username in the URL, this character ended up in the local path to the layer. When bitbake parsed the recipes in this layer, the '~' character ended up in the function name generated for an anonymous Python function. Since '~' isn't a valid character in a Python function name we got a pile of errors.

Quoted 9 lines

We already have a translation table to handle characters which aren't valid in Python function names, we just need to add '~' to the table.

Paul Barker (1):
parse/ast: Substitute '~' when naming anonymous functions

 lib/bb/parse/ast.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

It helps if I include the URL rather than just leaving a dead reference...

[1]: https://layers.openembedded.org/layerindex/layerupdate/9144821/

Thanks,

Signature · 2 lines
Paul Barker
https://pbarker.dev/