diff options
author | Christopher Larson <kergoth@gmail.com> | 2022-03-17 15:29:11 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-08-04 11:37:55 +0100 |
commit | 8b74f2ca55a08454beee77141dcdfe51e343298a (patch) | |
tree | b1fbbbca798be98e2c9caaa7daadfe03c84b6ea6 | |
parent | a9d2012f50b0c50c985c6dae184c8c19ace3b965 (diff) | |
download | poky-8b74f2ca55a08454beee77141dcdfe51e343298a.tar.gz |
bitbake: data_smart: check for python builtins directly for context lookup
This avoids the need to hardcode a list of python builtins. This also slightly changes behavior, in a case like `${@eval("3")}`, this will ensure we always call the builtin, even if the metadata has an 'eval' variable defined.
(Bitbake rev: 9976ae50677b333d646ca0fd395468bd2301d03f)
Signed-off-by: Christopher Larson <kergoth@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index c597dbade8..fe0bacd13b 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -16,7 +16,10 @@ BitBake build tools. | |||
16 | # | 16 | # |
17 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | 17 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig |
18 | 18 | ||
19 | import copy, re, sys, traceback | 19 | import builtins |
20 | import copy | ||
21 | import re | ||
22 | import sys | ||
20 | from collections.abc import MutableMapping | 23 | from collections.abc import MutableMapping |
21 | import logging | 24 | import logging |
22 | import hashlib | 25 | import hashlib |
@@ -150,17 +153,18 @@ class VariableParse: | |||
150 | value = utils.better_eval(codeobj, DataContext(self.d), {'d' : self.d}) | 153 | value = utils.better_eval(codeobj, DataContext(self.d), {'d' : self.d}) |
151 | return str(value) | 154 | return str(value) |
152 | 155 | ||
153 | |||
154 | class DataContext(dict): | 156 | class DataContext(dict): |
157 | excluded = set([i for i in dir(builtins) if not i.startswith('_')] + ['bb', 'os', 'oe']) | ||
158 | |||
155 | def __init__(self, metadata, **kwargs): | 159 | def __init__(self, metadata, **kwargs): |
156 | self.metadata = metadata | 160 | self.metadata = metadata |
157 | dict.__init__(self, **kwargs) | 161 | dict.__init__(self, **kwargs) |
158 | self['d'] = metadata | 162 | self['d'] = metadata |
159 | 163 | ||
160 | def __missing__(self, key): | 164 | def __missing__(self, key): |
161 | # Skip commonly accessed invalid variables | 165 | if key in self.excluded: |
162 | if key in ['bb', 'oe', 'int', 'bool', 'time', 'str', 'os']: | ||
163 | raise KeyError(key) | 166 | raise KeyError(key) |
167 | |||
164 | value = self.metadata.getVar(key) | 168 | value = self.metadata.getVar(key) |
165 | if value is None or self.metadata.getVarFlag(key, 'func', False): | 169 | if value is None or self.metadata.getVarFlag(key, 'func', False): |
166 | raise KeyError(key) | 170 | raise KeyError(key) |