diff options
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index b9fb37c5fa..e4a7a4d857 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -116,6 +116,40 @@ class DataNode: | |||
116 | else: | 116 | else: |
117 | bb.data.setVar(key, val, data) | 117 | bb.data.setVar(key, val, data) |
118 | 118 | ||
119 | class MethodNode: | ||
120 | def __init__(self, func_name, body, lineno, fn): | ||
121 | self.func_name = func_name | ||
122 | self.body = body | ||
123 | self.fn = fn | ||
124 | self.lineno = lineno | ||
125 | |||
126 | def eval(self, data): | ||
127 | if self.func_name == "__anonymous": | ||
128 | funcname = ("__anon_%s_%s" % (self.lineno, self.fn.translate(string.maketrans('/.+-', '____')))) | ||
129 | if not funcname in bb.methodpool._parsed_fns: | ||
130 | text = "def %s(d):\n" % (funcname) + '\n'.join(self.body) | ||
131 | bb.methodpool.insert_method(funcname, text, fn) | ||
132 | anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or [] | ||
133 | anonfuncs.append(funcname) | ||
134 | bb.data.setVar('__BBANONFUNCS', anonfuncs, data) | ||
135 | else: | ||
136 | bb.data.setVarFlag(self.func_name, "func", 1, data) | ||
137 | bb.data.setVar(self.func_name, '\n'.join(self.body), data) | ||
138 | |||
139 | class PythonMethodNode: | ||
140 | def __init__(self, root, body, fn): | ||
141 | self.root = root | ||
142 | self.body = body | ||
143 | self.fn = fn | ||
144 | |||
145 | def eval(self, data): | ||
146 | # Note we will add root to parsedmethods after having parse | ||
147 | # 'this' file. This means we will not parse methods from | ||
148 | # bb classes twice | ||
149 | if not self.root in __parsed_methods__: | ||
150 | text = '\n'.join(self.body) | ||
151 | bb.methodpool.insert_method(self.root, text, self.fn) | ||
152 | |||
119 | 153 | ||
120 | def handleInclude(statements, m, fn, lineno, data, force): | 154 | def handleInclude(statements, m, fn, lineno, data, force): |
121 | # AST handling | 155 | # AST handling |
@@ -133,25 +167,14 @@ def handleData(statements, groupd, data): | |||
133 | statements[-1].eval(data) | 167 | statements[-1].eval(data) |
134 | 168 | ||
135 | def handleMethod(statements, func_name, lineno, fn, body, d): | 169 | def handleMethod(statements, func_name, lineno, fn, body, d): |
136 | if func_name == "__anonymous": | 170 | # AST handling |
137 | funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____')))) | 171 | statements.append(MethodNode(func_name, body, lineno, fn)) |
138 | if not funcname in bb.methodpool._parsed_fns: | 172 | statements[-1].eval(d) |
139 | text = "def %s(d):\n" % (funcname) + '\n'.join(body) | ||
140 | bb.methodpool.insert_method(funcname, text, fn) | ||
141 | anonfuncs = bb.data.getVar('__BBANONFUNCS', d) or [] | ||
142 | anonfuncs.append(funcname) | ||
143 | bb.data.setVar('__BBANONFUNCS', anonfuncs, d) | ||
144 | else: | ||
145 | bb.data.setVarFlag(func_name, "func", 1, d) | ||
146 | bb.data.setVar(func_name, '\n'.join(body), d) | ||
147 | 173 | ||
148 | def handlePythonMethod(statements, root, body, fn): | 174 | def handlePythonMethod(statements, root, body, fn): |
149 | # Note we will add root to parsedmethods after having parse | 175 | # AST handling |
150 | # 'this' file. This means we will not parse methods from | 176 | statements.append(PythonMethodNode(root, body, fn)) |
151 | # bb classes twice | 177 | statements[-1].eval(None) |
152 | if not root in __parsed_methods__: | ||
153 | text = '\n'.join(body) | ||
154 | bb.methodpool.insert_method(root, text, fn) | ||
155 | 178 | ||
156 | def handleMethodFlags(statements, key, m, d): | 179 | def handleMethodFlags(statements, key, m, d): |
157 | if bb.data.getVar(key, d): | 180 | if bb.data.getVar(key, d): |