summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/utils.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 06c8819d26..68ca4ef25a 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1025,6 +1025,43 @@ def filter(variable, checkvalues, d):
1025 checkvalues = set(checkvalues) 1025 checkvalues = set(checkvalues)
1026 return ' '.join(sorted(checkvalues & val)) 1026 return ' '.join(sorted(checkvalues & val))
1027 1027
1028
1029def get_referenced_vars(start_expr, d):
1030 """
1031 :return: names of vars referenced in start_expr (recursively), in quasi-BFS order (variables within the same level
1032 are ordered arbitrarily)
1033 """
1034
1035 seen = set()
1036 ret = []
1037
1038 # The first entry in the queue is the unexpanded start expression
1039 queue = collections.deque([start_expr])
1040 # Subsequent entries will be variable names, so we need to track whether or not entry requires getVar
1041 is_first = True
1042
1043 empty_data = bb.data.init()
1044 while queue:
1045 entry = queue.popleft()
1046 if is_first:
1047 # Entry is the start expression - no expansion needed
1048 is_first = False
1049 expression = entry
1050 else:
1051 # This is a variable name - need to get the value
1052 expression = d.getVar(entry, False)
1053 ret.append(entry)
1054
1055 # expandWithRefs is how we actually get the referenced variables in the expression. We call it using an empty
1056 # data store because we only want the variables directly used in the expression. It returns a set, which is what
1057 # dooms us to only ever be "quasi-BFS" rather than full BFS.
1058 new_vars = empty_data.expandWithRefs(expression, None).references - set(seen)
1059
1060 queue.extend(new_vars)
1061 seen.update(new_vars)
1062 return ret
1063
1064
1028def cpu_count(): 1065def cpu_count():
1029 return multiprocessing.cpu_count() 1066 return multiprocessing.cpu_count()
1030 1067