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>
This commit is contained in:
Richard Purdie 2009-10-13 08:37:08 +01:00
parent 44549775eb
commit 7642529554
2 changed files with 34 additions and 24 deletions

View File

@ -25,7 +25,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 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 import bb.fetch, bb.build, bb.utils
from bb import data, fetch, methodpool from bb import data, fetch, methodpool
@ -89,7 +89,12 @@ def finalise(fn, d):
try: try:
t = data.getVar('T', d) t = data.getVar('T', d)
data.setVar('T', '${TMPDIR}/anonfunc/', 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) data.delVar('T', d)
if t: if t:
data.setVar('T', t, d) data.setVar('T', t, d)
@ -211,17 +216,17 @@ def feeder(lineno, s, fn, root, d):
if __infunc__: if __infunc__:
if s == '}': if s == '}':
__body__.append('') __body__.append('')
data.setVar(__infunc__, '\n'.join(__body__), d)
data.setVarFlag(__infunc__, "func", 1, d)
if __infunc__ == "__anonymous": if __infunc__ == "__anonymous":
anonqueue = bb.data.getVar("__anonqueue", d) or [] funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
anonitem = {} if not funcname in methodpool._parsed_fns:
anonitem["content"] = bb.data.getVar("__anonymous", d) text = "def %s(d):\n" % (funcname) + '\n'.join(__body__)
anonitem["flags"] = bb.data.getVarFlags("__anonymous", d) methodpool.insert_method(funcname, text, fn)
anonqueue.append(anonitem) anonfuncs = data.getVar('__BBANONFUNCS', d) or []
bb.data.setVar("__anonqueue", anonqueue, d) anonfuncs.append(funcname)
bb.data.delVarFlags("__anonymous", d) data.setVar('__BBANONFUNCS', anonfuncs, d)
bb.data.delVar("__anonymous", d) else:
data.setVarFlag(__infunc__, "func", 1, d)
data.setVar(__infunc__, '\n'.join(__body__), d)
__infunc__ = "" __infunc__ = ""
__body__ = [] __body__ = []
else: else:

View File

@ -25,7 +25,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 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 import bb.fetch, bb.build, bb.utils
from bb import data, fetch, methodpool from bb import data, fetch, methodpool
@ -89,7 +89,12 @@ def finalise(fn, d):
try: try:
t = data.getVar('T', d) t = data.getVar('T', d)
data.setVar('T', '${TMPDIR}/', 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) data.delVar('T', d)
if t: if t:
data.setVar('T', t, d) data.setVar('T', t, d)
@ -205,17 +210,17 @@ def feeder(lineno, s, fn, root, d):
if __infunc__: if __infunc__:
if s == '}': if s == '}':
__body__.append('') __body__.append('')
data.setVar(__infunc__, '\n'.join(__body__), d)
data.setVarFlag(__infunc__, "func", 1, d)
if __infunc__ == "__anonymous": if __infunc__ == "__anonymous":
anonqueue = bb.data.getVar("__anonqueue", d) or [] funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
anonitem = {} if not funcname in methodpool._parsed_fns:
anonitem["content"] = bb.data.getVar("__anonymous", d) text = "def %s(d):\n" % (funcname) + '\n'.join(__body__)
anonitem["flags"] = bb.data.getVarFlags("__anonymous", d) methodpool.insert_method(funcname, text, fn)
anonqueue.append(anonitem) anonfuncs = data.getVar('__BBANONFUNCS', d) or []
bb.data.setVar("__anonqueue", anonqueue, d) anonfuncs.append(funcname)
bb.data.delVarFlags("__anonymous", d) data.setVar('__BBANONFUNCS', anonfuncs, d)
bb.data.delVar("__anonymous", d) else:
data.setVarFlag(__infunc__, "func", 1, d)
data.setVar(__infunc__, '\n'.join(__body__), d)
__infunc__ = "" __infunc__ = ""
__body__ = [] __body__ = []
else: else: