diff options
author | Chris Larson <chris_larson@mentor.com> | 2011-01-04 13:34:08 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-01-10 13:24:03 +0000 |
commit | b127874ee6f7b8801575a10f4b7df02783aafdeb (patch) | |
tree | d16a7aeb08cb5e41996b3d5ce68bee24a75911ba /bitbake | |
parent | f305e95840a887bbd97e9003e7a0f9135df77fcb (diff) | |
download | poky-b127874ee6f7b8801575a10f4b7df02783aafdeb.tar.gz |
parse: pass filename, lineno into the ast
We will be needing this information to improve the tracebacks of python code
from the metadata, as well as to give the user information about where
variables were defined, so they know how it ended up the way it is.
(Bitbake rev: 9615c538b894f71a2d1a0ba6b3f260db91e75786)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 105 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 15 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 8 |
3 files changed, 68 insertions, 60 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index e34f1fe894..8fffe1e8f0 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -40,13 +40,14 @@ class StatementGroup(list): | |||
40 | statement.eval(data) | 40 | statement.eval(data) |
41 | 41 | ||
42 | class AstNode(object): | 42 | class AstNode(object): |
43 | pass | 43 | def __init__(self, filename, lineno): |
44 | self.filename = filename | ||
45 | self.lineno = lineno | ||
44 | 46 | ||
45 | class IncludeNode(AstNode): | 47 | class IncludeNode(AstNode): |
46 | def __init__(self, what_file, fn, lineno, force): | 48 | def __init__(self, filename, lineno, what_file, force): |
49 | AstNode.__init__(self, filename, lineno) | ||
47 | self.what_file = what_file | 50 | self.what_file = what_file |
48 | self.from_fn = fn | ||
49 | self.from_lineno = lineno | ||
50 | self.force = force | 51 | self.force = force |
51 | 52 | ||
52 | def eval(self, data): | 53 | def eval(self, data): |
@@ -54,16 +55,17 @@ class IncludeNode(AstNode): | |||
54 | Include the file and evaluate the statements | 55 | Include the file and evaluate the statements |
55 | """ | 56 | """ |
56 | s = bb.data.expand(self.what_file, data) | 57 | s = bb.data.expand(self.what_file, data) |
57 | logger.debug(2, "CONF %s:%s: including %s", self.from_fn, self.from_lineno, s) | 58 | logger.debug(2, "CONF %s:%s: including %s", self.filename, self.lineno, s) |
58 | 59 | ||
59 | # TODO: Cache those includes... maybe not here though | 60 | # TODO: Cache those includes... maybe not here though |
60 | if self.force: | 61 | if self.force: |
61 | bb.parse.ConfHandler.include(self.from_fn, s, data, "include required") | 62 | bb.parse.ConfHandler.include(self.filename, s, data, "include required") |
62 | else: | 63 | else: |
63 | bb.parse.ConfHandler.include(self.from_fn, s, data, False) | 64 | bb.parse.ConfHandler.include(self.filename, s, data, False) |
64 | 65 | ||
65 | class ExportNode(AstNode): | 66 | class ExportNode(AstNode): |
66 | def __init__(self, var): | 67 | def __init__(self, filename, lineno, var): |
68 | AstNode.__init__(self, filename, lineno) | ||
67 | self.var = var | 69 | self.var = var |
68 | 70 | ||
69 | def eval(self, data): | 71 | def eval(self, data): |
@@ -76,7 +78,8 @@ class DataNode(AstNode): | |||
76 | this need to be re-evaluated... we might be able to do | 78 | this need to be re-evaluated... we might be able to do |
77 | that faster with multiple classes. | 79 | that faster with multiple classes. |
78 | """ | 80 | """ |
79 | def __init__(self, groupd): | 81 | def __init__(self, filename, lineno, groupd): |
82 | AstNode.__init__(self, filename, lineno) | ||
80 | self.groupd = groupd | 83 | self.groupd = groupd |
81 | 84 | ||
82 | def getFunc(self, key, data): | 85 | def getFunc(self, key, data): |
@@ -119,19 +122,18 @@ class DataNode(AstNode): | |||
119 | else: | 122 | else: |
120 | bb.data.setVar(key, val, data) | 123 | bb.data.setVar(key, val, data) |
121 | 124 | ||
122 | class MethodNode: | 125 | class MethodNode(AstNode): |
123 | def __init__(self, func_name, body, lineno, fn): | 126 | def __init__(self, filename, lineno, func_name, body): |
127 | AstNode.__init__(self, filename, lineno) | ||
124 | self.func_name = func_name | 128 | self.func_name = func_name |
125 | self.body = body | 129 | self.body = body |
126 | self.fn = fn | ||
127 | self.lineno = lineno | ||
128 | 130 | ||
129 | def eval(self, data): | 131 | def eval(self, data): |
130 | if self.func_name == "__anonymous": | 132 | if self.func_name == "__anonymous": |
131 | funcname = ("__anon_%s_%s" % (self.lineno, self.fn.translate(string.maketrans('/.+-', '____')))) | 133 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(string.maketrans('/.+-', '____')))) |
132 | if not funcname in bb.methodpool._parsed_fns: | 134 | if not funcname in bb.methodpool._parsed_fns: |
133 | text = "def %s(d):\n" % (funcname) + '\n'.join(self.body) | 135 | text = "def %s(d):\n" % (funcname) + '\n'.join(self.body) |
134 | bb.methodpool.insert_method(funcname, text, self.fn) | 136 | bb.methodpool.insert_method(funcname, text, self.filename) |
135 | anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or [] | 137 | anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or [] |
136 | anonfuncs.append(funcname) | 138 | anonfuncs.append(funcname) |
137 | bb.data.setVar('__BBANONFUNCS', anonfuncs, data) | 139 | bb.data.setVar('__BBANONFUNCS', anonfuncs, data) |
@@ -140,25 +142,26 @@ class MethodNode: | |||
140 | bb.data.setVar(self.func_name, '\n'.join(self.body), data) | 142 | bb.data.setVar(self.func_name, '\n'.join(self.body), data) |
141 | 143 | ||
142 | class PythonMethodNode(AstNode): | 144 | class PythonMethodNode(AstNode): |
143 | def __init__(self, funcname, root, body, fn): | 145 | def __init__(self, filename, lineno, function, define, body): |
144 | self.func_name = funcname | 146 | AstNode.__init__(self, filename, lineno) |
145 | self.root = root | 147 | self.function = function |
148 | self.define = define | ||
146 | self.body = body | 149 | self.body = body |
147 | self.fn = fn | ||
148 | 150 | ||
149 | def eval(self, data): | 151 | def eval(self, data): |
150 | # Note we will add root to parsedmethods after having parse | 152 | # Note we will add root to parsedmethods after having parse |
151 | # 'this' file. This means we will not parse methods from | 153 | # 'this' file. This means we will not parse methods from |
152 | # bb classes twice | 154 | # bb classes twice |
153 | text = '\n'.join(self.body) | 155 | text = '\n'.join(self.body) |
154 | if not bb.methodpool.parsed_module(self.root): | 156 | if not bb.methodpool.parsed_module(self.define): |
155 | bb.methodpool.insert_method(self.root, text, self.fn) | 157 | bb.methodpool.insert_method(self.define, text, self.filename) |
156 | bb.data.setVarFlag(self.func_name, "func", 1, data) | 158 | bb.data.setVarFlag(self.function, "func", 1, data) |
157 | bb.data.setVarFlag(self.func_name, "python", 1, data) | 159 | bb.data.setVarFlag(self.function, "python", 1, data) |
158 | bb.data.setVar(self.func_name, text, data) | 160 | bb.data.setVar(self.function, text, data) |
159 | 161 | ||
160 | class MethodFlagsNode(AstNode): | 162 | class MethodFlagsNode(AstNode): |
161 | def __init__(self, key, m): | 163 | def __init__(self, filename, lineno, key, m): |
164 | AstNode.__init__(self, filename, lineno) | ||
162 | self.key = key | 165 | self.key = key |
163 | self.m = m | 166 | self.m = m |
164 | 167 | ||
@@ -178,7 +181,8 @@ class MethodFlagsNode(AstNode): | |||
178 | bb.data.delVarFlag(self.key, "fakeroot", data) | 181 | bb.data.delVarFlag(self.key, "fakeroot", data) |
179 | 182 | ||
180 | class ExportFuncsNode(AstNode): | 183 | class ExportFuncsNode(AstNode): |
181 | def __init__(self, fns, classes): | 184 | def __init__(self, filename, lineno, fns, classes): |
185 | AstNode.__init__(self, filename, lineno) | ||
182 | self.n = fns.split() | 186 | self.n = fns.split() |
183 | self.classes = classes | 187 | self.classes = classes |
184 | 188 | ||
@@ -217,7 +221,8 @@ class ExportFuncsNode(AstNode): | |||
217 | bb.data.setVarFlag(var, 'export_func', '1', data) | 221 | bb.data.setVarFlag(var, 'export_func', '1', data) |
218 | 222 | ||
219 | class AddTaskNode(AstNode): | 223 | class AddTaskNode(AstNode): |
220 | def __init__(self, func, before, after): | 224 | def __init__(self, filename, lineno, func, before, after): |
225 | AstNode.__init__(self, filename, lineno) | ||
221 | self.func = func | 226 | self.func = func |
222 | self.before = before | 227 | self.before = before |
223 | self.after = after | 228 | self.after = after |
@@ -248,7 +253,8 @@ class AddTaskNode(AstNode): | |||
248 | bb.data.setVarFlag(entry, "deps", [var] + existing, data) | 253 | bb.data.setVarFlag(entry, "deps", [var] + existing, data) |
249 | 254 | ||
250 | class BBHandlerNode(AstNode): | 255 | class BBHandlerNode(AstNode): |
251 | def __init__(self, fns): | 256 | def __init__(self, filename, lineno, fns): |
257 | AstNode.__init__(self, filename, lineno) | ||
252 | self.hs = fns.split() | 258 | self.hs = fns.split() |
253 | 259 | ||
254 | def eval(self, data): | 260 | def eval(self, data): |
@@ -259,48 +265,49 @@ class BBHandlerNode(AstNode): | |||
259 | bb.data.setVar('__BBHANDLERS', bbhands, data) | 265 | bb.data.setVar('__BBHANDLERS', bbhands, data) |
260 | 266 | ||
261 | class InheritNode(AstNode): | 267 | class InheritNode(AstNode): |
262 | def __init__(self, classes): | 268 | def __init__(self, filename, lineno, classes): |
269 | AstNode.__init__(self, filename, lineno) | ||
263 | self.classes = classes | 270 | self.classes = classes |
264 | 271 | ||
265 | def eval(self, data): | 272 | def eval(self, data): |
266 | bb.parse.BBHandler.inherit(self.classes, data) | 273 | bb.parse.BBHandler.inherit(self.classes, data) |
267 | 274 | ||
268 | def handleInclude(statements, m, fn, lineno, force): | 275 | def handleInclude(statements, filename, lineno, m, force): |
269 | statements.append(IncludeNode(m.group(1), fn, lineno, force)) | 276 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) |
270 | 277 | ||
271 | def handleExport(statements, m): | 278 | def handleExport(statements, filename, lineno, m): |
272 | statements.append(ExportNode(m.group(1))) | 279 | statements.append(ExportNode(filename, lineno, m.group(1))) |
273 | 280 | ||
274 | def handleData(statements, groupd): | 281 | def handleData(statements, filename, lineno, groupd): |
275 | statements.append(DataNode(groupd)) | 282 | statements.append(DataNode(filename, lineno, groupd)) |
276 | 283 | ||
277 | def handleMethod(statements, func_name, lineno, fn, body): | 284 | def handleMethod(statements, filename, lineno, func_name, body): |
278 | statements.append(MethodNode(func_name, body, lineno, fn)) | 285 | statements.append(MethodNode(filename, lineno, func_name, body)) |
279 | 286 | ||
280 | def handlePythonMethod(statements, funcname, root, body, fn): | 287 | def handlePythonMethod(statements, filename, lineno, funcname, root, body): |
281 | statements.append(PythonMethodNode(funcname, root, body, fn)) | 288 | statements.append(PythonMethodNode(filename, lineno, funcname, root, body)) |
282 | 289 | ||
283 | def handleMethodFlags(statements, key, m): | 290 | def handleMethodFlags(statements, filename, lineno, key, m): |
284 | statements.append(MethodFlagsNode(key, m)) | 291 | statements.append(MethodFlagsNode(filename, lineno, key, m)) |
285 | 292 | ||
286 | def handleExportFuncs(statements, m, classes): | 293 | def handleExportFuncs(statements, filename, lineno, m, classes): |
287 | statements.append(ExportFuncsNode(m.group(1), classes)) | 294 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classes)) |
288 | 295 | ||
289 | def handleAddTask(statements, m): | 296 | def handleAddTask(statements, filename, lineno, m): |
290 | func = m.group("func") | 297 | func = m.group("func") |
291 | before = m.group("before") | 298 | before = m.group("before") |
292 | after = m.group("after") | 299 | after = m.group("after") |
293 | if func is None: | 300 | if func is None: |
294 | return | 301 | return |
295 | 302 | ||
296 | statements.append(AddTaskNode(func, before, after)) | 303 | statements.append(AddTaskNode(filename, lineno, func, before, after)) |
297 | 304 | ||
298 | def handleBBHandlers(statements, m): | 305 | def handleBBHandlers(statements, filename, lineno, m): |
299 | statements.append(BBHandlerNode(m.group(1))) | 306 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) |
300 | 307 | ||
301 | def handleInherit(statements, m): | 308 | def handleInherit(statements, filename, lineno, m): |
302 | classes = m.group(1) | 309 | classes = m.group(1) |
303 | statements.append(InheritNode(classes.split())) | 310 | statements.append(InheritNode(filename, lineno, classes.split())) |
304 | 311 | ||
305 | def finalize(fn, d, variant = None): | 312 | def finalize(fn, d, variant = None): |
306 | for lazykey in bb.data.getVar("__lazy_assigned", d) or (): | 313 | for lazykey in bb.data.getVar("__lazy_assigned", d) or (): |
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index 81554b9435..4a938b911c 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -172,7 +172,7 @@ def feeder(lineno, s, fn, root, statements): | |||
172 | if __infunc__: | 172 | if __infunc__: |
173 | if s == '}': | 173 | if s == '}': |
174 | __body__.append('') | 174 | __body__.append('') |
175 | ast.handleMethod(statements, __infunc__, lineno, fn, __body__) | 175 | ast.handleMethod(statements, fn, lineno, __infunc__, __body__) |
176 | __infunc__ = "" | 176 | __infunc__ = "" |
177 | __body__ = [] | 177 | __body__ = [] |
178 | else: | 178 | else: |
@@ -185,7 +185,8 @@ def feeder(lineno, s, fn, root, statements): | |||
185 | __body__.append(s) | 185 | __body__.append(s) |
186 | return | 186 | return |
187 | else: | 187 | else: |
188 | ast.handlePythonMethod(statements, __inpython__, root, __body__, fn) | 188 | ast.handlePythonMethod(statements, fn, lineno, __inpython__, |
189 | root, __body__) | ||
189 | __body__ = [] | 190 | __body__ = [] |
190 | __inpython__ = False | 191 | __inpython__ = False |
191 | 192 | ||
@@ -206,7 +207,7 @@ def feeder(lineno, s, fn, root, statements): | |||
206 | m = __func_start_regexp__.match(s) | 207 | m = __func_start_regexp__.match(s) |
207 | if m: | 208 | if m: |
208 | __infunc__ = m.group("func") or "__anonymous" | 209 | __infunc__ = m.group("func") or "__anonymous" |
209 | ast.handleMethodFlags(statements, __infunc__, m) | 210 | ast.handleMethodFlags(statements, fn, lineno, __infunc__, m) |
210 | return | 211 | return |
211 | 212 | ||
212 | m = __def_regexp__.match(s) | 213 | m = __def_regexp__.match(s) |
@@ -218,22 +219,22 @@ def feeder(lineno, s, fn, root, statements): | |||
218 | 219 | ||
219 | m = __export_func_regexp__.match(s) | 220 | m = __export_func_regexp__.match(s) |
220 | if m: | 221 | if m: |
221 | ast.handleExportFuncs(statements, m, classes) | 222 | ast.handleExportFuncs(statements, fn, lineno, m, classes) |
222 | return | 223 | return |
223 | 224 | ||
224 | m = __addtask_regexp__.match(s) | 225 | m = __addtask_regexp__.match(s) |
225 | if m: | 226 | if m: |
226 | ast.handleAddTask(statements, m) | 227 | ast.handleAddTask(statements, fn, lineno, m) |
227 | return | 228 | return |
228 | 229 | ||
229 | m = __addhandler_regexp__.match(s) | 230 | m = __addhandler_regexp__.match(s) |
230 | if m: | 231 | if m: |
231 | ast.handleBBHandlers(statements, m) | 232 | ast.handleBBHandlers(statements, fn, lineno, m) |
232 | return | 233 | return |
233 | 234 | ||
234 | m = __inherit_regexp__.match(s) | 235 | m = __inherit_regexp__.match(s) |
235 | if m: | 236 | if m: |
236 | ast.handleInherit(statements, m) | 237 | ast.handleInherit(statements, fn, lineno, m) |
237 | return | 238 | return |
238 | 239 | ||
239 | return ConfHandler.feeder(lineno, s, fn, statements) | 240 | return ConfHandler.feeder(lineno, s, fn, statements) |
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index d90f5d868e..fc239a3540 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py | |||
@@ -113,22 +113,22 @@ def feeder(lineno, s, fn, statements): | |||
113 | m = __config_regexp__.match(s) | 113 | m = __config_regexp__.match(s) |
114 | if m: | 114 | if m: |
115 | groupd = m.groupdict() | 115 | groupd = m.groupdict() |
116 | ast.handleData(statements, groupd) | 116 | ast.handleData(statements, fn, lineno, groupd) |
117 | return | 117 | return |
118 | 118 | ||
119 | m = __include_regexp__.match(s) | 119 | m = __include_regexp__.match(s) |
120 | if m: | 120 | if m: |
121 | ast.handleInclude(statements, m, fn, lineno, False) | 121 | ast.handleInclude(statements, fn, lineno, m, False) |
122 | return | 122 | return |
123 | 123 | ||
124 | m = __require_regexp__.match(s) | 124 | m = __require_regexp__.match(s) |
125 | if m: | 125 | if m: |
126 | ast.handleInclude(statements, m, fn, lineno, True) | 126 | ast.handleInclude(statements, fn, lineno, m, True) |
127 | return | 127 | return |
128 | 128 | ||
129 | m = __export_regexp__.match(s) | 129 | m = __export_regexp__.match(s) |
130 | if m: | 130 | if m: |
131 | ast.handleExport(statements, m) | 131 | ast.handleExport(statements, fn, lineno, m) |
132 | return | 132 | return |
133 | 133 | ||
134 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); | 134 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); |