diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-09 15:10:56 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-10 13:32:46 +0000 |
commit | 99184d7879723f73b67dccf3754263729662cbea (patch) | |
tree | 28d3bad497b2f402de5d26b16d9fc3a9d41e0cac /bitbake/lib/bb/parse/ast.py | |
parent | 6ba69b43831cf1e0968c64dc977056d860e70ba4 (diff) | |
download | poky-99184d7879723f73b67dccf3754263729662cbea.tar.gz |
bitbake: BBHandler/ast: Merge handMethod and handleMethodFlags
The functionality overlap between these two functions is significant and
its clearer to handle both things together since they are intimately
linked. There should be no behaviour change, just clearer code.
(Bitbake rev: 391aa4afc91be90d8d3ee47e1bf797d6ebe61a71)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/parse/ast.py')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index c676fc6bc8..5f55af5ef8 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -141,22 +141,33 @@ class DataNode(AstNode): | |||
141 | class MethodNode(AstNode): | 141 | class MethodNode(AstNode): |
142 | tr_tbl = string.maketrans('/.+-@%&', '_______') | 142 | tr_tbl = string.maketrans('/.+-@%&', '_______') |
143 | 143 | ||
144 | def __init__(self, filename, lineno, func_name, body): | 144 | def __init__(self, filename, lineno, func_name, body, python, fakeroot): |
145 | AstNode.__init__(self, filename, lineno) | 145 | AstNode.__init__(self, filename, lineno) |
146 | self.func_name = func_name | 146 | self.func_name = func_name |
147 | self.body = body | 147 | self.body = body |
148 | self.python = python | ||
149 | self.fakeroot = fakeroot | ||
148 | 150 | ||
149 | def eval(self, data): | 151 | def eval(self, data): |
150 | text = '\n'.join(self.body) | 152 | text = '\n'.join(self.body) |
151 | funcname = self.func_name | 153 | funcname = self.func_name |
152 | if self.func_name == "__anonymous": | 154 | if self.func_name == "__anonymous": |
153 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) | 155 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) |
156 | self.python = True | ||
154 | text = "def %s(d):\n" % (funcname) + text | 157 | text = "def %s(d):\n" % (funcname) + text |
155 | bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body)) | 158 | bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body)) |
156 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] | 159 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] |
157 | anonfuncs.append(funcname) | 160 | anonfuncs.append(funcname) |
158 | data.setVar('__BBANONFUNCS', anonfuncs) | 161 | data.setVar('__BBANONFUNCS', anonfuncs) |
159 | data.setVarFlag(funcname, "python", 1) | 162 | if data.getVar(funcname, False): |
163 | # clean up old version of this piece of metadata, as its | ||
164 | # flags could cause problems | ||
165 | data.delVarFlag(funcname, 'python') | ||
166 | data.delVarFlag(funcname, 'fakeroot') | ||
167 | if self.python: | ||
168 | data.setVarFlag(funcname, "python", "1") | ||
169 | if self.fakeroot: | ||
170 | data.setVarFlag(funcname, "fakeroot", "1") | ||
160 | data.setVarFlag(funcname, "func", 1) | 171 | data.setVarFlag(funcname, "func", 1) |
161 | data.setVar(funcname, text, parsing=True) | 172 | data.setVar(funcname, text, parsing=True) |
162 | data.setVarFlag(funcname, 'filename', self.filename) | 173 | data.setVarFlag(funcname, 'filename', self.filename) |
@@ -181,27 +192,6 @@ class PythonMethodNode(AstNode): | |||
181 | data.setVarFlag(self.function, 'filename', self.filename) | 192 | data.setVarFlag(self.function, 'filename', self.filename) |
182 | data.setVarFlag(self.function, 'lineno', str(self.lineno - len(self.body) - 1)) | 193 | data.setVarFlag(self.function, 'lineno', str(self.lineno - len(self.body) - 1)) |
183 | 194 | ||
184 | class MethodFlagsNode(AstNode): | ||
185 | def __init__(self, filename, lineno, key, m): | ||
186 | AstNode.__init__(self, filename, lineno) | ||
187 | self.key = key | ||
188 | self.m = m | ||
189 | |||
190 | def eval(self, data): | ||
191 | if data.getVar(self.key, False): | ||
192 | # clean up old version of this piece of metadata, as its | ||
193 | # flags could cause problems | ||
194 | data.setVarFlag(self.key, 'python', None) | ||
195 | data.setVarFlag(self.key, 'fakeroot', None) | ||
196 | if self.m.group("py") is not None: | ||
197 | data.setVarFlag(self.key, "python", "1") | ||
198 | else: | ||
199 | data.delVarFlag(self.key, "python") | ||
200 | if self.m.group("fr") is not None: | ||
201 | data.setVarFlag(self.key, "fakeroot", "1") | ||
202 | else: | ||
203 | data.delVarFlag(self.key, "fakeroot") | ||
204 | |||
205 | class ExportFuncsNode(AstNode): | 195 | class ExportFuncsNode(AstNode): |
206 | def __init__(self, filename, lineno, fns, classname): | 196 | def __init__(self, filename, lineno, fns, classname): |
207 | AstNode.__init__(self, filename, lineno) | 197 | AstNode.__init__(self, filename, lineno) |
@@ -284,15 +274,12 @@ def handleExport(statements, filename, lineno, m): | |||
284 | def handleData(statements, filename, lineno, groupd): | 274 | def handleData(statements, filename, lineno, groupd): |
285 | statements.append(DataNode(filename, lineno, groupd)) | 275 | statements.append(DataNode(filename, lineno, groupd)) |
286 | 276 | ||
287 | def handleMethod(statements, filename, lineno, func_name, body): | 277 | def handleMethod(statements, filename, lineno, func_name, body, python, fakeroot): |
288 | statements.append(MethodNode(filename, lineno, func_name, body)) | 278 | statements.append(MethodNode(filename, lineno, func_name, body, python, fakeroot)) |
289 | 279 | ||
290 | def handlePythonMethod(statements, filename, lineno, funcname, modulename, body): | 280 | def handlePythonMethod(statements, filename, lineno, funcname, modulename, body): |
291 | statements.append(PythonMethodNode(filename, lineno, funcname, modulename, body)) | 281 | statements.append(PythonMethodNode(filename, lineno, funcname, modulename, body)) |
292 | 282 | ||
293 | def handleMethodFlags(statements, filename, lineno, key, m): | ||
294 | statements.append(MethodFlagsNode(filename, lineno, key, m)) | ||
295 | |||
296 | def handleExportFuncs(statements, filename, lineno, m, classname): | 283 | def handleExportFuncs(statements, filename, lineno, m, classname): |
297 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classname)) | 284 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classname)) |
298 | 285 | ||