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>
This commit is contained in:
parent
28ca6cc34b
commit
2b26745c70
|
@ -155,8 +155,7 @@ class PythonParser():
|
||||||
expands = ("d.expand", "bb.data.expand", "data.expand")
|
expands = ("d.expand", "bb.data.expand", "data.expand")
|
||||||
execfuncs = ("bb.build.exec_func", "bb.build.exec_task")
|
execfuncs = ("bb.build.exec_func", "bb.build.exec_task")
|
||||||
|
|
||||||
@classmethod
|
def warn(self, func, arg):
|
||||||
def warn(cls, func, arg):
|
|
||||||
"""Warn about calls of bitbake APIs which pass a non-literal
|
"""Warn about calls of bitbake APIs which pass a non-literal
|
||||||
argument for the variable name, as we're not able to track such
|
argument for the variable name, as we're not able to track such
|
||||||
a reference.
|
a reference.
|
||||||
|
@ -168,8 +167,7 @@ class PythonParser():
|
||||||
except TypeError:
|
except TypeError:
|
||||||
logger.debug(2, 'Failed to convert function and argument to source form')
|
logger.debug(2, 'Failed to convert function and argument to source form')
|
||||||
else:
|
else:
|
||||||
logger.debug(1, "Warning: in call to '%s', argument '%s' is "
|
logger.debug(1, self.unhandled_message % (funcstr, argstr))
|
||||||
"not a literal", funcstr, argstr)
|
|
||||||
|
|
||||||
def visit_Call(self, node):
|
def visit_Call(self, node):
|
||||||
name = self.called_node_name(node.func)
|
name = self.called_node_name(node.func)
|
||||||
|
@ -208,13 +206,16 @@ class PythonParser():
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name):
|
||||||
self.var_references = set()
|
self.var_references = set()
|
||||||
self.var_execs = set()
|
self.var_execs = set()
|
||||||
self.execs = set()
|
self.execs = set()
|
||||||
self.var_expands = set()
|
self.var_expands = set()
|
||||||
self.references = set()
|
self.references = set()
|
||||||
|
|
||||||
|
self.unhandled_message = "in call of %s, argument '%s' is not a string literal"
|
||||||
|
self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message)
|
||||||
|
|
||||||
def parse_python(self, node):
|
def parse_python(self, node):
|
||||||
h = hash(str(node))
|
h = hash(str(node))
|
||||||
|
|
||||||
|
@ -238,10 +239,12 @@ class PythonParser():
|
||||||
pythonparsecache[h]["execs"] = self.execs
|
pythonparsecache[h]["execs"] = self.execs
|
||||||
|
|
||||||
class ShellParser():
|
class ShellParser():
|
||||||
def __init__(self):
|
def __init__(self, name):
|
||||||
self.funcdefs = set()
|
self.funcdefs = set()
|
||||||
self.allexecs = set()
|
self.allexecs = set()
|
||||||
self.execs = set()
|
self.execs = set()
|
||||||
|
self.unhandled_template = "unable to handle non-literal command '%s'"
|
||||||
|
self.unhandled_template = "while parsing %s, %s" % (name, self.unhandled_template)
|
||||||
|
|
||||||
def parse_shell(self, value):
|
def parse_shell(self, value):
|
||||||
"""Parse the supplied shell code in a string, returning the external
|
"""Parse the supplied shell code in a string, returning the external
|
||||||
|
@ -356,8 +359,7 @@ class ShellParser():
|
||||||
|
|
||||||
cmd = word[1]
|
cmd = word[1]
|
||||||
if cmd.startswith("$"):
|
if cmd.startswith("$"):
|
||||||
logger.debug(1, "Warning: execution of non-literal "
|
logger.debug(1, self.unhandled_template % cmd)
|
||||||
"command '%s'", cmd)
|
|
||||||
elif cmd == "eval":
|
elif cmd == "eval":
|
||||||
command = " ".join(word for _, word in words[1:])
|
command = " ".join(word for _, word in words[1:])
|
||||||
self.parse_shell(command)
|
self.parse_shell(command)
|
||||||
|
|
|
@ -258,7 +258,7 @@ def emit_func(func, o=sys.__stdout__, d = init()):
|
||||||
emit_var(key, o, d, False) and o.write('\n')
|
emit_var(key, o, d, False) and o.write('\n')
|
||||||
|
|
||||||
emit_var(func, o, d, False) and o.write('\n')
|
emit_var(func, o, d, False) and o.write('\n')
|
||||||
newdeps = bb.codeparser.ShellParser().parse_shell(d.getVar(func, True))
|
newdeps = bb.codeparser.ShellParser(func).parse_shell(d.getVar(func, True))
|
||||||
seen = set()
|
seen = set()
|
||||||
while newdeps:
|
while newdeps:
|
||||||
deps = newdeps
|
deps = newdeps
|
||||||
|
@ -267,7 +267,7 @@ def emit_func(func, o=sys.__stdout__, d = init()):
|
||||||
for dep in deps:
|
for dep in deps:
|
||||||
if bb.data.getVarFlag(dep, "func", d):
|
if bb.data.getVarFlag(dep, "func", d):
|
||||||
emit_var(dep, o, d, False) and o.write('\n')
|
emit_var(dep, o, d, False) and o.write('\n')
|
||||||
newdeps |= bb.codeparser.ShellParser().parse_shell(d.getVar(dep, True))
|
newdeps |= bb.codeparser.ShellParser(dep).parse_shell(d.getVar(dep, True))
|
||||||
newdeps -= seen
|
newdeps -= seen
|
||||||
|
|
||||||
def update_data(d):
|
def update_data(d):
|
||||||
|
|
|
@ -68,7 +68,7 @@ class VariableParse:
|
||||||
code = match.group()[3:-1]
|
code = match.group()[3:-1]
|
||||||
codeobj = compile(code.strip(), self.varname or "<expansion>", "eval")
|
codeobj = compile(code.strip(), self.varname or "<expansion>", "eval")
|
||||||
|
|
||||||
parser = bb.codeparser.PythonParser()
|
parser = bb.codeparser.PythonParser(self.varname)
|
||||||
parser.parse_python(code)
|
parser.parse_python(code)
|
||||||
self.references |= parser.references
|
self.references |= parser.references
|
||||||
self.execs |= parser.execs
|
self.execs |= parser.execs
|
||||||
|
|
Loading…
Reference in New Issue