summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2009-10-13 08:37:08 +0100
committerRichard Purdie <rpurdie@linux.intel.com>2009-10-13 08:38:13 +0100
commit76425295541165421914ef354900a3f2534f59f2 (patch)
treedc871f1369b66f1f4c2fc92638f7758322a9f593
parent44549775ebc01edbca7d934875a43a2d315bdd9b (diff)
downloadopenembedded-core-76425295541165421914ef354900a3f2534f59f2.tar.gz
openembedded-core-76425295541165421914ef354900a3f2534f59f2.tar.bz2
openembedded-core-76425295541165421914ef354900a3f2534f59f2.zip
bitbake: Anonymous funciton improvements - use methodpool to allow cached code and remove anonymous function indentation mismatch problems
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rw-r--r--bitbake-dev/lib/bb/parse/parse_py/BBHandler.py29
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py29
2 files changed, 34 insertions, 24 deletions
diff --git a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py b/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
index f92b31fd0a..f13bb015ba 100644
--- a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
@@ -25,7 +25,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-import re, bb, os, sys, time
+import re, bb, os, sys, time, string
import bb.fetch, bb.build, bb.utils
from bb import data, fetch, methodpool
@@ -89,7 +89,12 @@ def finalise(fn, d):
try:
t = data.getVar('T', d)
data.setVar('T', '${TMPDIR}/anonfunc/', d)
- build.exec_func("__anonfunc", d)
+ anonfuncs = data.getVar('__BBANONFUNCS', d) or []
+ code = ""
+ for f in anonfuncs:
+ code = code + " %s(d)\n" % f
+ data.setVar("__anonfunc", code, d)
+ build.exec_func_python("__anonfunc", d)
data.delVar('T', d)
if t:
data.setVar('T', t, d)
@@ -211,17 +216,17 @@ def feeder(lineno, s, fn, root, d):
if __infunc__:
if s == '}':
__body__.append('')
- data.setVar(__infunc__, '\n'.join(__body__), d)
- data.setVarFlag(__infunc__, "func", 1, d)
if __infunc__ == "__anonymous":
- anonqueue = bb.data.getVar("__anonqueue", d) or []
- anonitem = {}
- anonitem["content"] = bb.data.getVar("__anonymous", d)
- anonitem["flags"] = bb.data.getVarFlags("__anonymous", d)
- anonqueue.append(anonitem)
- bb.data.setVar("__anonqueue", anonqueue, d)
- bb.data.delVarFlags("__anonymous", d)
- bb.data.delVar("__anonymous", d)
+ funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
+ if not funcname in methodpool._parsed_fns:
+ text = "def %s(d):\n" % (funcname) + '\n'.join(__body__)
+ methodpool.insert_method(funcname, text, fn)
+ anonfuncs = data.getVar('__BBANONFUNCS', d) or []
+ anonfuncs.append(funcname)
+ data.setVar('__BBANONFUNCS', anonfuncs, d)
+ else:
+ data.setVarFlag(__infunc__, "func", 1, d)
+ data.setVar(__infunc__, '\n'.join(__body__), d)
__infunc__ = ""
__body__ = []
else:
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index e918ce3bb8..03976d4d8c 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -25,7 +25,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-import re, bb, os, sys, time
+import re, bb, os, sys, time, string
import bb.fetch, bb.build, bb.utils
from bb import data, fetch, methodpool
@@ -89,7 +89,12 @@ def finalise(fn, d):
try:
t = data.getVar('T', d)
data.setVar('T', '${TMPDIR}/', d)
- build.exec_func("__anonfunc", d)
+ anonfuncs = data.getVar('__BBANONFUNCS', d) or []
+ code = ""
+ for f in anonfuncs:
+ code = code + " %s(d)\n" % f
+ data.setVar("__anonfunc", code, d)
+ build.exec_func_python("__anonfunc", d)
data.delVar('T', d)
if t:
data.setVar('T', t, d)
@@ -205,17 +210,17 @@ def feeder(lineno, s, fn, root, d):
if __infunc__:
if s == '}':
__body__.append('')
- data.setVar(__infunc__, '\n'.join(__body__), d)
- data.setVarFlag(__infunc__, "func", 1, d)
if __infunc__ == "__anonymous":
- anonqueue = bb.data.getVar("__anonqueue", d) or []
- anonitem = {}
- anonitem["content"] = bb.data.getVar("__anonymous", d)
- anonitem["flags"] = bb.data.getVarFlags("__anonymous", d)
- anonqueue.append(anonitem)
- bb.data.setVar("__anonqueue", anonqueue, d)
- bb.data.delVarFlags("__anonymous", d)
- bb.data.delVar("__anonymous", d)
+ funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
+ if not funcname in methodpool._parsed_fns:
+ text = "def %s(d):\n" % (funcname) + '\n'.join(__body__)
+ methodpool.insert_method(funcname, text, fn)
+ anonfuncs = data.getVar('__BBANONFUNCS', d) or []
+ anonfuncs.append(funcname)
+ data.setVar('__BBANONFUNCS', anonfuncs, d)
+ else:
+ data.setVarFlag(__infunc__, "func", 1, d)
+ data.setVar(__infunc__, '\n'.join(__body__), d)
__infunc__ = ""
__body__ = []
else: