diff options
author | Christopher Larson <chris_larson@mentor.com> | 2011-10-28 21:32:26 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-11-10 11:44:29 +0000 |
commit | ae96ac11897c1017aea359a8e3325291bc198293 (patch) | |
tree | 60ea01a4a0b04ee64c5eda99f5f1759f115dd4a6 | |
parent | 48d7f5251bd5f3a44f713edfc297851258c57120 (diff) | |
download | poky-ae96ac11897c1017aea359a8e3325291bc198293.tar.gz |
codeparser: accept a name for better messages
- If a name is passed to the parser, prepend the messages with "while
parsing <name>:". This gives a bit more context.
- Tweak the warning messages slightly (they had to be altered anyway to
inject the variable being parsed).
Before:
DEBUG: Warning: in call to 'bb.data.getVar': argument ''%s' % var' is \
not a literal
After:
DEBUG: while parsing emit_pkgdata, in call of bb.data.getVar, argument \
''%s' % var' is not a string literal
(Bitbake rev: 1060193ae4d54e667735dbff5d1d2be49a3f95c9)
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/codeparser.py | 18 | ||||
-rw-r--r-- | bitbake/lib/bb/data.py | 8 | ||||
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 2 |
3 files changed, 15 insertions, 13 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 77156136f8..9a692a0c8e 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py | |||
@@ -155,8 +155,7 @@ class PythonParser(): | |||
155 | expands = ("d.expand", "bb.data.expand", "data.expand") | 155 | expands = ("d.expand", "bb.data.expand", "data.expand") |
156 | execfuncs = ("bb.build.exec_func", "bb.build.exec_task") | 156 | execfuncs = ("bb.build.exec_func", "bb.build.exec_task") |
157 | 157 | ||
158 | @classmethod | 158 | def warn(self, func, arg): |
159 | def warn(cls, func, arg): | ||
160 | """Warn about calls of bitbake APIs which pass a non-literal | 159 | """Warn about calls of bitbake APIs which pass a non-literal |
161 | argument for the variable name, as we're not able to track such | 160 | argument for the variable name, as we're not able to track such |
162 | a reference. | 161 | a reference. |
@@ -168,8 +167,7 @@ class PythonParser(): | |||
168 | except TypeError: | 167 | except TypeError: |
169 | logger.debug(2, 'Failed to convert function and argument to source form') | 168 | logger.debug(2, 'Failed to convert function and argument to source form') |
170 | else: | 169 | else: |
171 | logger.debug(1, "Warning: in call to '%s', argument '%s' is " | 170 | logger.debug(1, self.unhandled_message % (funcstr, argstr)) |
172 | "not a literal", funcstr, argstr) | ||
173 | 171 | ||
174 | def visit_Call(self, node): | 172 | def visit_Call(self, node): |
175 | name = self.called_node_name(node.func) | 173 | name = self.called_node_name(node.func) |
@@ -208,13 +206,16 @@ class PythonParser(): | |||
208 | else: | 206 | else: |
209 | break | 207 | break |
210 | 208 | ||
211 | def __init__(self): | 209 | def __init__(self, name): |
212 | self.var_references = set() | 210 | self.var_references = set() |
213 | self.var_execs = set() | 211 | self.var_execs = set() |
214 | self.execs = set() | 212 | self.execs = set() |
215 | self.var_expands = set() | 213 | self.var_expands = set() |
216 | self.references = set() | 214 | self.references = set() |
217 | 215 | ||
216 | self.unhandled_message = "in call of %s, argument '%s' is not a string literal" | ||
217 | self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message) | ||
218 | |||
218 | def parse_python(self, node): | 219 | def parse_python(self, node): |
219 | h = hash(str(node)) | 220 | h = hash(str(node)) |
220 | 221 | ||
@@ -238,10 +239,12 @@ class PythonParser(): | |||
238 | pythonparsecache[h]["execs"] = self.execs | 239 | pythonparsecache[h]["execs"] = self.execs |
239 | 240 | ||
240 | class ShellParser(): | 241 | class ShellParser(): |
241 | def __init__(self): | 242 | def __init__(self, name): |
242 | self.funcdefs = set() | 243 | self.funcdefs = set() |
243 | self.allexecs = set() | 244 | self.allexecs = set() |
244 | self.execs = set() | 245 | self.execs = set() |
246 | self.unhandled_template = "unable to handle non-literal command '%s'" | ||
247 | self.unhandled_template = "while parsing %s, %s" % (name, self.unhandled_template) | ||
245 | 248 | ||
246 | def parse_shell(self, value): | 249 | def parse_shell(self, value): |
247 | """Parse the supplied shell code in a string, returning the external | 250 | """Parse the supplied shell code in a string, returning the external |
@@ -356,8 +359,7 @@ class ShellParser(): | |||
356 | 359 | ||
357 | cmd = word[1] | 360 | cmd = word[1] |
358 | if cmd.startswith("$"): | 361 | if cmd.startswith("$"): |
359 | logger.debug(1, "Warning: execution of non-literal " | 362 | logger.debug(1, self.unhandled_template % cmd) |
360 | "command '%s'", cmd) | ||
361 | elif cmd == "eval": | 363 | elif cmd == "eval": |
362 | command = " ".join(word for _, word in words[1:]) | 364 | command = " ".join(word for _, word in words[1:]) |
363 | self.parse_shell(command) | 365 | self.parse_shell(command) |
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index ac0d8809cc..bcb8b055b8 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -258,7 +258,7 @@ def emit_func(func, o=sys.__stdout__, d = init()): | |||
258 | emit_var(key, o, d, False) and o.write('\n') | 258 | emit_var(key, o, d, False) and o.write('\n') |
259 | 259 | ||
260 | emit_var(func, o, d, False) and o.write('\n') | 260 | emit_var(func, o, d, False) and o.write('\n') |
261 | newdeps = bb.codeparser.ShellParser().parse_shell(d.getVar(func, True)) | 261 | newdeps = bb.codeparser.ShellParser(func).parse_shell(d.getVar(func, True)) |
262 | seen = set() | 262 | seen = set() |
263 | while newdeps: | 263 | while newdeps: |
264 | deps = newdeps | 264 | deps = newdeps |
@@ -267,7 +267,7 @@ def emit_func(func, o=sys.__stdout__, d = init()): | |||
267 | for dep in deps: | 267 | for dep in deps: |
268 | if bb.data.getVarFlag(dep, "func", d): | 268 | if bb.data.getVarFlag(dep, "func", d): |
269 | emit_var(dep, o, d, False) and o.write('\n') | 269 | emit_var(dep, o, d, False) and o.write('\n') |
270 | newdeps |= bb.codeparser.ShellParser().parse_shell(d.getVar(dep, True)) | 270 | newdeps |= bb.codeparser.ShellParser(dep).parse_shell(d.getVar(dep, True)) |
271 | newdeps -= seen | 271 | newdeps -= seen |
272 | 272 | ||
273 | def update_data(d): | 273 | def update_data(d): |
@@ -280,12 +280,12 @@ def build_dependencies(key, keys, shelldeps, d): | |||
280 | if d.getVarFlag(key, "func"): | 280 | if d.getVarFlag(key, "func"): |
281 | if d.getVarFlag(key, "python"): | 281 | if d.getVarFlag(key, "python"): |
282 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) | 282 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) |
283 | parser = bb.codeparser.PythonParser() | 283 | parser = bb.codeparser.PythonParser(key) |
284 | parser.parse_python(parsedvar.value) | 284 | parser.parse_python(parsedvar.value) |
285 | deps = deps | parser.references | 285 | deps = deps | parser.references |
286 | else: | 286 | else: |
287 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) | 287 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) |
288 | parser = bb.codeparser.ShellParser() | 288 | parser = bb.codeparser.ShellParser(key) |
289 | parser.parse_shell(parsedvar.value) | 289 | parser.parse_shell(parsedvar.value) |
290 | deps = deps | shelldeps | 290 | deps = deps | shelldeps |
291 | deps = deps | parsedvar.references | 291 | deps = deps | parsedvar.references |
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index d8ba24ffd7..44369ed82d 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -68,7 +68,7 @@ class VariableParse: | |||
68 | code = match.group()[3:-1] | 68 | code = match.group()[3:-1] |
69 | codeobj = compile(code.strip(), self.varname or "<expansion>", "eval") | 69 | codeobj = compile(code.strip(), self.varname or "<expansion>", "eval") |
70 | 70 | ||
71 | parser = bb.codeparser.PythonParser() | 71 | parser = bb.codeparser.PythonParser(self.varname) |
72 | parser.parse_python(code) | 72 | parser.parse_python(code) |
73 | self.references |= parser.references | 73 | self.references |= parser.references |
74 | self.execs |= parser.execs | 74 | self.execs |= parser.execs |