bitbake: codeparser: Add function decorators for vardeps

Adds bb.parse.vardeps bb.parse.excludevardeps function decorators that
can be used to explicitly add or exclude variables from a python
function parsed by bitbake

(Bitbake rev: 030fb3dee067640a3a50f24a53d200bdb5048376)

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Watt 2025-04-07 15:52:44 -06:00 committed by Richard Purdie
parent af91ed1691
commit 820824f5fe
2 changed files with 44 additions and 3 deletions

View File

@ -69,7 +69,7 @@ def add_module_functions(fn, functions, namespace):
name = "%s.%s" % (namespace, f)
parser = PythonParser(name, logger)
try:
parser.parse_python(None, filename=fn, lineno=1, fixedhash=fixedhash+f)
parser.parse_python(None, filename=fn, lineno=1, fixedhash=fixedhash+f, func=functions[f])
#bb.warn("Cached %s" % f)
except KeyError:
try:
@ -87,7 +87,7 @@ def add_module_functions(fn, functions, namespace):
# Builtin
continue
src = "".join(lines)
parser.parse_python(src, filename=fn, lineno=lineno, fixedhash=fixedhash+f)
parser.parse_python(src, filename=fn, lineno=lineno, fixedhash=fixedhash+f, func=functions[f])
#bb.warn("Not cached %s" % f)
execs = parser.execs.copy()
# Expand internal module exec references
@ -348,7 +348,7 @@ class PythonParser():
# For the python module code it is expensive to have the function text so it is
# uses a different fixedhash to cache against. We can take the hit on obtaining the
# text if it isn't in the cache.
def parse_python(self, node, lineno=0, filename="<string>", fixedhash=None):
def parse_python(self, node, lineno=0, filename="<string>", fixedhash=None, func=None):
if not fixedhash and (not node or not node.strip()):
return
@ -390,6 +390,10 @@ class PythonParser():
if n.__class__.__name__ == "Call":
self.visit_Call(n)
if func is not None:
self.references |= getattr(func, "bb_vardeps", set())
self.references -= getattr(func, "bb_vardepsexclude", set())
self.execs.update(self.var_execs)
self.extra = None
if fixedhash:

View File

@ -176,4 +176,41 @@ def get_file_depends(d):
dep_files.append(os.path.abspath(fn))
return " ".join(dep_files)
def vardeps(*varnames):
"""
Function decorator that can be used to instruct the bitbake dependency
parsing to add a dependency on the specified variables names
Example:
@bb.parse.vardeps("FOO", "BAR")
def my_function():
...
"""
def inner(f):
if not hasattr(f, "bb_vardeps"):
f.bb_vardeps = set()
f.bb_vardeps |= set(varnames)
return f
return inner
def vardepsexclude(*varnames):
"""
Function decorator that can be used to instruct the bitbake dependency
parsing to ignore dependencies on the specified variable names in the code
Example:
@bb.parse.vardepsexclude("FOO", "BAR")
def my_function():
...
"""
def inner(f):
if not hasattr(f, "bb_vardepsexclude"):
f.bb_vardepsexclude = set()
f.bb_vardepsexclude |= set(varnames)
return f
return inner
from bb.parse.parse_py import __version__, ConfHandler, BBHandler