diff options
| author | Chris Laplante via bitbake-devel <bitbake-devel@lists.openembedded.org> | 2020-01-17 14:39:54 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-19 13:31:05 +0000 |
| commit | d5b3b76a71e69297dd4697d6a420f79752da5e5a (patch) | |
| tree | 138e04124f720403d4b6230133a387aa333fe6dc /bitbake/lib/bb/utils.py | |
| parent | fa5524890e86d353ee7d2194ccdd6c84e9bd2d31 (diff) | |
| download | poky-d5b3b76a71e69297dd4697d6a420f79752da5e5a.tar.gz | |
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>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
| -rw-r--r-- | bitbake/lib/bb/utils.py | 37 |
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 | |||
| 1029 | def 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 | |||
| 1028 | def cpu_count(): | 1065 | def cpu_count(): |
| 1029 | return multiprocessing.cpu_count() | 1066 | return multiprocessing.cpu_count() |
| 1030 | 1067 | ||
