diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 4bc6adbe45..4f70cf7fe7 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py @@ -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="", fixedhash=None): + def parse_python(self, node, lineno=0, filename="", 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: diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py index 7ffdaa6fd7..d428d8a4b4 100644 --- a/bitbake/lib/bb/parse/__init__.py +++ b/bitbake/lib/bb/parse/__init__.py @@ -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