bitbake/method pool:
authorHolger Hans Peter Freyther <zecke@selfish.org>
Thu, 23 Mar 2006 23:11:02 +0000 (23:11 +0000)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Thu, 23 Mar 2006 23:11:02 +0000 (23:11 +0000)
Create a common implementation of the global
method handling. It will be shared by the parsers
and the cache.
This commit breaks the cache again

MANIFEST
lib/bb/__init__.py
lib/bb/methodpool.py [new file with mode: 0644]
lib/bb/parse/parse_py/BBHandler.py

index 14a21d7..8851887 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -18,6 +18,7 @@ lib/bb/fetch/svk.py
 lib/bb/fetch/svn.py
 lib/bb/fetch/wget.py
 lib/bb/manifest.py
+lib/bb/methodpool.py
 lib/bb/parse/__init__.py
 lib/bb/parse/parse_py/BBHandler.py
 lib/bb/parse/parse_py/ConfHandler.py
index c6c0beb..1206905 100644 (file)
@@ -60,7 +60,8 @@ __all__ = [
     "event",
     "build",
     "fetch",
-    "manifest"
+    "manifest",
+    "methodpool"
  ]
 
 whitespace = '\t\n\x0b\x0c\r '
diff --git a/lib/bb/methodpool.py b/lib/bb/methodpool.py
new file mode 100644 (file)
index 0000000..27bc4be
--- /dev/null
@@ -0,0 +1,81 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+#
+# Copyright (C)       2006 Holger Hans Peter Freyther
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   Redistributions of source code must retain the above copyright notice,
+#   this list of conditions and the following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+#
+#   Neither the name Holger Hans Peter Freyther nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+"""
+    What is a method pool?
+
+    BitBake has a global method scope where .bb, .inc and .bbclass
+    files can install methods. These methods are parsed from strings.
+    To avoid recompiling and executing these string we introduce
+    a method pool to do this task.
+
+    This pool will be used to compile and execute the functions. It
+    will be smart enough to 
+"""
+
+from bb.utils import better_compile, better_exec
+
+# A dict of modules we have handled
+# it is the number of .bbclasses + x in size
+_parsed_methods = { }
+
+def insert_method(modulename, code, fn):
+    """
+    Add code of a module should be added. The methods
+    will be simply added, no checking will be done
+    """
+    comp = better_compile(code, "<bb>", fn )
+    better_exec(comp, __builtins__, code, fn)
+
+def check_insert_method(modulename, code, fn):
+    """
+    Add the code if it wasnt added before. The module
+    name will be used for that 
+    """
+    if not modulename in _parsed_methods:
+        return insert_method(modulename, code)
+
+def parsed_module(modulename):
+    """
+    Inform me file xyz was parsed
+    """
+    return modulename in _parsed_methods
+
+
+def get_parsed_dict():
+    """
+    shortcut
+    """
+    return _parsed_methods    
index a1bf980..4d2679e 100644 (file)
@@ -23,7 +23,7 @@
 
 import re, bb, os, sys, time
 import bb.fetch, bb.build, bb.utils
-from bb import debug, data, fetch, fatal
+from bb import debug, data, fetch, fatal, methodpool
 
 from ConfHandler import include, localpath, obtain, init
 from bb.parse import ParseError
@@ -44,13 +44,7 @@ __bbpath_found__ = 0
 __classname__ = ""
 classes = [ None, ]
 
-#
-# A cache of parsed bbclasses. We will use this cache to make a
-# decision if we should compile and execute a method.
-# This dict contains a list of classes which might have methods
-# we have already added.
-#
-__parsed_methods__ = {}
+__parsed_methods__ = methodpool.get_parsed_dict()
 
 def supports(fn, d):
     localfn = localpath(fn, d)
@@ -232,10 +226,14 @@ def feeder(lineno, s, fn, root, d):
         else:
             if not root  in __parsed_methods__:
                 text = '\n'.join(__body__)
-                comp = bb.utils.better_compile(text, "<bb>", fn )
-                bb.utils.better_exec(comp, __builtins__, text, fn)
-                funcs = data.getVar('__functions__', d) or ""
-                data.setVar('__functions__', "%s\n%s" % (funcs, text), d)
+                methodpool.insert_method( root, text, fn )
+                funcs = data.getVar('__functions__', d) or {}
+                if not funcs.has_key( root ):
+                    funcs[root] = text 
+                else:
+                    funcs[root] = "%s\n%s" % (funcs[root], text)
+
+                data.setVar('__functions__', funcs, d)
             __body__ = []
             __inpython__ = False