summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2025-04-07 15:52:44 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-04-10 11:07:38 +0100
commit820824f5fe33f2a3bb84f46a33056cf1c995af32 (patch)
tree3e9688f24a15584e9b27e773208169a9a5f516a1 /bitbake/lib/bb
parentaf91ed1691bfa5b0cdaa680a60042faaf0022aef (diff)
downloadpoky-820824f5fe33f2a3bb84f46a33056cf1c995af32.tar.gz
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>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/codeparser.py10
-rw-r--r--bitbake/lib/bb/parse/__init__.py37
2 files changed, 44 insertions, 3 deletions
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):
69 name = "%s.%s" % (namespace, f) 69 name = "%s.%s" % (namespace, f)
70 parser = PythonParser(name, logger) 70 parser = PythonParser(name, logger)
71 try: 71 try:
72 parser.parse_python(None, filename=fn, lineno=1, fixedhash=fixedhash+f) 72 parser.parse_python(None, filename=fn, lineno=1, fixedhash=fixedhash+f, func=functions[f])
73 #bb.warn("Cached %s" % f) 73 #bb.warn("Cached %s" % f)
74 except KeyError: 74 except KeyError:
75 try: 75 try:
@@ -87,7 +87,7 @@ def add_module_functions(fn, functions, namespace):
87 # Builtin 87 # Builtin
88 continue 88 continue
89 src = "".join(lines) 89 src = "".join(lines)
90 parser.parse_python(src, filename=fn, lineno=lineno, fixedhash=fixedhash+f) 90 parser.parse_python(src, filename=fn, lineno=lineno, fixedhash=fixedhash+f, func=functions[f])
91 #bb.warn("Not cached %s" % f) 91 #bb.warn("Not cached %s" % f)
92 execs = parser.execs.copy() 92 execs = parser.execs.copy()
93 # Expand internal module exec references 93 # Expand internal module exec references
@@ -348,7 +348,7 @@ class PythonParser():
348 # For the python module code it is expensive to have the function text so it is 348 # For the python module code it is expensive to have the function text so it is
349 # uses a different fixedhash to cache against. We can take the hit on obtaining the 349 # uses a different fixedhash to cache against. We can take the hit on obtaining the
350 # text if it isn't in the cache. 350 # text if it isn't in the cache.
351 def parse_python(self, node, lineno=0, filename="<string>", fixedhash=None): 351 def parse_python(self, node, lineno=0, filename="<string>", fixedhash=None, func=None):
352 if not fixedhash and (not node or not node.strip()): 352 if not fixedhash and (not node or not node.strip()):
353 return 353 return
354 354
@@ -390,6 +390,10 @@ class PythonParser():
390 if n.__class__.__name__ == "Call": 390 if n.__class__.__name__ == "Call":
391 self.visit_Call(n) 391 self.visit_Call(n)
392 392
393 if func is not None:
394 self.references |= getattr(func, "bb_vardeps", set())
395 self.references -= getattr(func, "bb_vardepsexclude", set())
396
393 self.execs.update(self.var_execs) 397 self.execs.update(self.var_execs)
394 self.extra = None 398 self.extra = None
395 if fixedhash: 399 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):
176 dep_files.append(os.path.abspath(fn)) 176 dep_files.append(os.path.abspath(fn))
177 return " ".join(dep_files) 177 return " ".join(dep_files)
178 178
179def vardeps(*varnames):
180 """
181 Function decorator that can be used to instruct the bitbake dependency
182 parsing to add a dependency on the specified variables names
183
184 Example:
185
186 @bb.parse.vardeps("FOO", "BAR")
187 def my_function():
188 ...
189
190 """
191 def inner(f):
192 if not hasattr(f, "bb_vardeps"):
193 f.bb_vardeps = set()
194 f.bb_vardeps |= set(varnames)
195 return f
196 return inner
197
198def vardepsexclude(*varnames):
199 """
200 Function decorator that can be used to instruct the bitbake dependency
201 parsing to ignore dependencies on the specified variable names in the code
202
203 Example:
204
205 @bb.parse.vardepsexclude("FOO", "BAR")
206 def my_function():
207 ...
208 """
209 def inner(f):
210 if not hasattr(f, "bb_vardepsexclude"):
211 f.bb_vardepsexclude = set()
212 f.bb_vardepsexclude |= set(varnames)
213 return f
214 return inner
215
179from bb.parse.parse_py import __version__, ConfHandler, BBHandler 216from bb.parse.parse_py import __version__, ConfHandler, BBHandler