mirror of
https://git.yoctoproject.org/poky
synced 2026-04-18 21:32:12 +02:00
bitbake: bb.utils: add get_referenced_vars
Given a start expression, bb.utils.get_referenced_vars returns the
referenced variable names in a quasi-BFS order (variables within the
same level are ordered aribitrarily).
For example, given an empty data store:
bb.utils.get_referenced_vars("${A} ${B} ${d.getVar('C')}", d)
returns either ["A", "B", "C"], ["A", "C", "B"], or another
permutation.
If we then set A = "${F} ${G}", then the same call will return a
permutation of [A, B, C] concatenated with a permutation of [F, G].
This method is like a version of d.expandWithRefs().references that
gives some insight into the depth of variable references.
(Bitbake rev: 076eb5453ca35b8b75b8270efb989d5208095b27)
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
fa5524890e
commit
d5b3b76a71
@@ -1025,6 +1025,43 @@ def filter(variable, checkvalues, d):
|
||||
checkvalues = set(checkvalues)
|
||||
return ' '.join(sorted(checkvalues & val))
|
||||
|
||||
|
||||
def get_referenced_vars(start_expr, d):
|
||||
"""
|
||||
:return: names of vars referenced in start_expr (recursively), in quasi-BFS order (variables within the same level
|
||||
are ordered arbitrarily)
|
||||
"""
|
||||
|
||||
seen = set()
|
||||
ret = []
|
||||
|
||||
# The first entry in the queue is the unexpanded start expression
|
||||
queue = collections.deque([start_expr])
|
||||
# Subsequent entries will be variable names, so we need to track whether or not entry requires getVar
|
||||
is_first = True
|
||||
|
||||
empty_data = bb.data.init()
|
||||
while queue:
|
||||
entry = queue.popleft()
|
||||
if is_first:
|
||||
# Entry is the start expression - no expansion needed
|
||||
is_first = False
|
||||
expression = entry
|
||||
else:
|
||||
# This is a variable name - need to get the value
|
||||
expression = d.getVar(entry, False)
|
||||
ret.append(entry)
|
||||
|
||||
# expandWithRefs is how we actually get the referenced variables in the expression. We call it using an empty
|
||||
# data store because we only want the variables directly used in the expression. It returns a set, which is what
|
||||
# dooms us to only ever be "quasi-BFS" rather than full BFS.
|
||||
new_vars = empty_data.expandWithRefs(expression, None).references - set(seen)
|
||||
|
||||
queue.extend(new_vars)
|
||||
seen.update(new_vars)
|
||||
return ret
|
||||
|
||||
|
||||
def cpu_count():
|
||||
return multiprocessing.cpu_count()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user