Patchwork [05/12] base.bbclass: switch to current OE's imports handling

login
register
mail settings
Submitter Christopher Larson
Date March 17, 2011, 4:19 p.m.
Message ID <c47222c1e7c4bb7842d2d693f8a0d6e8f39ada4a.1300378596.git.chris_larson@mentor.com>
Download mbox | patch
Permalink /patch/1537/
State New, archived
Headers show

Comments

Christopher Larson - March 17, 2011, 4:19 p.m.
From: Chris Larson <chris_larson@mentor.com>

The current mechanism makes it easier for classes to add new oe modules to be
automatically imported, and thereby made available to python snippets (${@}).

Signed-off-by: Chris Larson <chris_larson@mentor.com>
---
 meta/classes/base.bbclass |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

Patch

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index e53ebe4..7a87f57 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -9,31 +9,28 @@  inherit utility-tasks
 inherit metadata_scm
 inherit buildstats
 
-python sys_path_eh () {
+OE_IMPORTS += "oe.path oe.utils sys os time"
+
+python oe_import () {
     if isinstance(e, bb.event.ConfigParsed):
-        import sys
-        import os
-        import time
+        import os, sys
 
         bbpath = e.data.getVar("BBPATH", True).split(":")
         sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
 
         def inject(name, value):
-            """Make a python object accessible from everywhere for the metadata"""
+            """Make a python object accessible from the metadata"""
             if hasattr(bb.utils, "_context"):
                 bb.utils._context[name] = value
             else:
                 __builtins__[name] = value
 
-        import oe.path
-        import oe.utils
-        inject("bb", bb)
-        inject("sys", sys)
-        inject("time", time)
-        inject("oe", oe)
+        for toimport in e.data.getVar("OE_IMPORTS", True).split():
+            imported = __import__(toimport)
+            inject(toimport.split(".", 1)[0], imported)
 }
 
-addhandler sys_path_eh
+addhandler oe_import
 
 die() {
 	oefatal "$*"