summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-09 15:10:56 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-10 13:32:46 +0000
commit99184d7879723f73b67dccf3754263729662cbea (patch)
tree28d3bad497b2f402de5d26b16d9fc3a9d41e0cac /bitbake
parent6ba69b43831cf1e0968c64dc977056d860e70ba4 (diff)
downloadpoky-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')
-rw-r--r--bitbake/lib/bb/parse/ast.py43
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py5
2 files changed, 17 insertions, 31 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):
141class MethodNode(AstNode): 141class 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
184class 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
205class ExportFuncsNode(AstNode): 195class 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):
284def handleData(statements, filename, lineno, groupd): 274def handleData(statements, filename, lineno, groupd):
285 statements.append(DataNode(filename, lineno, groupd)) 275 statements.append(DataNode(filename, lineno, groupd))
286 276
287def handleMethod(statements, filename, lineno, func_name, body): 277def 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
290def handlePythonMethod(statements, filename, lineno, funcname, modulename, body): 280def 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
293def handleMethodFlags(statements, filename, lineno, key, m):
294 statements.append(MethodFlagsNode(filename, lineno, key, m))
295
296def handleExportFuncs(statements, filename, lineno, m, classname): 283def 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
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 97a9ee8dac..ef72c3700f 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -166,7 +166,7 @@ def feeder(lineno, s, fn, root, statements, eof=False):
166 if __infunc__: 166 if __infunc__:
167 if s == '}': 167 if s == '}':
168 __body__.append('') 168 __body__.append('')
169 ast.handleMethod(statements, fn, lineno, __infunc__[0], __body__) 169 ast.handleMethod(statements, fn, lineno, __infunc__[0], __body__, __infunc__[3], __infunc__[4])
170 __infunc__ = [] 170 __infunc__ = []
171 __body__ = [] 171 __body__ = []
172 else: 172 else:
@@ -211,8 +211,7 @@ def feeder(lineno, s, fn, root, statements, eof=False):
211 211
212 m = __func_start_regexp__.match(s) 212 m = __func_start_regexp__.match(s)
213 if m: 213 if m:
214 __infunc__ = [m.group("func") or "__anonymous", fn, lineno] 214 __infunc__ = [m.group("func") or "__anonymous", fn, lineno, m.group("py") is not None, m.group("fr") is not None]
215 ast.handleMethodFlags(statements, fn, lineno, __infunc__[0], m)
216 return 215 return
217 216
218 m = __def_regexp__.match(s) 217 m = __def_regexp__.match(s)