From 8b74f2ca55a08454beee77141dcdfe51e343298a Mon Sep 17 00:00:00 2001 From: Christopher Larson Date: Thu, 17 Mar 2022 15:29:11 -0700 Subject: 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 Signed-off-by: Richard Purdie --- bitbake/lib/bb/data_smart.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bitbake/lib/bb/data_smart.py') 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. # # 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) -- cgit v1.2.3-54-g00ecf