From ea346917910734b6a9e537f83bd26b18cd3bf4f0 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 23 May 2013 10:49:57 +0100 Subject: bitbake: cooker/cookerdata/utils: Improve context management The current execution context management for bitbake is ugly and the use of a global variable is nasty. Fixing that is hard, however we can improve things to start to establish an API for accessing and changing that context. This patch also adds in an explicit reset of the context when we reparse the configuration data which starts to improve the lifecycle of the data in setups like hob. (Bitbake rev: 6c3281a140125337fc75783973485e16785d05a1) Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'bitbake/lib/bb/utils.py') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 1ecc44a01a..7db6e3862f 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -36,12 +36,22 @@ from contextlib import contextmanager logger = logging.getLogger("BitBake.Util") +def clean_context(): + return { + "os": os, + "bb": bb, + "time": time, + } + +def get_context(): + return _context + + +def set_context(ctx): + _context = ctx + # Context used in better_exec, eval -_context = { - "os": os, - "bb": bb, - "time": time, -} +_context = clean_context() def explode_version(s): r = [] @@ -343,7 +353,7 @@ def better_exec(code, context, text = None, realfile = ""): if not hasattr(code, "co_filename"): code = better_compile(code, realfile, realfile) try: - exec(code, _context, context) + exec(code, get_context(), context) except Exception as e: (t, value, tb) = sys.exc_info() @@ -358,10 +368,10 @@ def better_exec(code, context, text = None, realfile = ""): raise e def simple_exec(code, context): - exec(code, _context, context) + exec(code, get_context(), context) def better_eval(source, locals): - return eval(source, _context, locals) + return eval(source, get_context(), locals) @contextmanager def fileslocked(files): -- cgit v1.2.3-54-g00ecf