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:36:44 +0100 |
commit | 9976ae50677b333d646ca0fd395468bd2301d03f (patch) | |
tree | 4709a2de5a21d5032d6a2c64a5f05df9699b1222 /lib/bb/data_smart.py | |
parent | ee22d3d51c60db2da97422b2be1e42239b7a2324 (diff) | |
download | bitbake-9976ae50677b333d646ca0fd395468bd2301d03f.tar.gz |
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.
Signed-off-by: Christopher Larson <kergoth@gmail.com>
Diffstat (limited to 'lib/bb/data_smart.py')
-rw-r--r-- | lib/bb/data_smart.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py index c597dbade..fe0bacd13 100644 --- a/lib/bb/data_smart.py +++ b/lib/bb/data_smart.py @@ -16,7 +16,10 @@ BitBake build tools. # # Based on functions from the base bb module, Copyright 2003 Holger Schurig -import copy, re, sys, traceback +import builtins +import copy +import re +import sys from collections.abc import MutableMapping import logging import hashlib @@ -150,17 +153,18 @@ class VariableParse: value = utils.better_eval(codeobj, DataContext(self.d), {'d' : self.d}) return str(value) - class DataContext(dict): + excluded = set([i for i in dir(builtins) if not i.startswith('_')] + ['bb', 'os', 'oe']) + def __init__(self, metadata, **kwargs): self.metadata = metadata dict.__init__(self, **kwargs) self['d'] = metadata def __missing__(self, key): - # Skip commonly accessed invalid variables - if key in ['bb', 'oe', 'int', 'bool', 'time', 'str', 'os']: + if key in self.excluded: raise KeyError(key) + value = self.metadata.getVar(key) if value is None or self.metadata.getVarFlag(key, 'func', False): raise KeyError(key) |