summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-09 22:33:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-13 12:16:10 +0100
commitf2e5d884617d22d8bb473db6848e3dcc68813b9d (patch)
tree419448f3a38d1aa11676a8f3a51422fe7298927c /bitbake/lib
parenta1a0ce1a0064e29159555011ebd667192132e0ce (diff)
downloadpoky-f2e5d884617d22d8bb473db6848e3dcc68813b9d.tar.gz
bitbake: data_smart/utils: Add 'd' to the context used for better_eval in python expansion
If a line like: foo=${@' '.join([d.getVar('D', True) + x for x in (' '.join([d.getVar('FILES_bash-' + p, True) or '' for p in ['lib', 'dev', 'staticdev', 'doc', 'locale', 'ptest']])).split()])} is added to a function like do_install, it fails with Exception name 'd' is not defined. This is due to a change of behaviour in python 3 compared to python 2. Generator expressions, dict comprehensions and set comprehensions are executed in a new scope but list comprehensions in python 2.x are not. In python 3 they all use a new scope. To allow these kinds of expressions to work, the easiest approach is to add 'd' to the global context. To do this, an extra optional parameter is added to better_eval and we use that to add 'd'. (Bitbake rev: 8f74881037bb01013d3d439dc0c269909a198c1c) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/data_smart.py2
-rw-r--r--bitbake/lib/bb/utils.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 25c412c1ad..f100446dcc 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -135,7 +135,7 @@ class VariableParse:
135 self.contains[k] = parser.contains[k].copy() 135 self.contains[k] = parser.contains[k].copy()
136 else: 136 else:
137 self.contains[k].update(parser.contains[k]) 137 self.contains[k].update(parser.contains[k])
138 value = utils.better_eval(codeobj, DataContext(self.d)) 138 value = utils.better_eval(codeobj, DataContext(self.d), {'d' : self.d})
139 return str(value) 139 return str(value)
140 140
141 141
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 8f75871c18..0a1bf6880a 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -37,6 +37,7 @@ import errno
37import signal 37import signal
38import ast 38import ast
39import collections 39import collections
40import copy
40from subprocess import getstatusoutput 41from subprocess import getstatusoutput
41from contextlib import contextmanager 42from contextlib import contextmanager
42from ctypes import cdll 43from ctypes import cdll
@@ -407,8 +408,13 @@ def better_exec(code, context, text = None, realfile = "<code>", pythonexception
407def simple_exec(code, context): 408def simple_exec(code, context):
408 exec(code, get_context(), context) 409 exec(code, get_context(), context)
409 410
410def better_eval(source, locals): 411def better_eval(source, locals, extraglobals = None):
411 return eval(source, get_context(), locals) 412 ctx = get_context()
413 if extraglobals:
414 ctx = copy.copy(ctx)
415 for g in extraglobals:
416 ctx[g] = extraglobals[g]
417 return eval(source, ctx, locals)
412 418
413@contextmanager 419@contextmanager
414def fileslocked(files): 420def fileslocked(files):