diff options
Diffstat (limited to 'bitbake/lib/bb/data.py')
-rw-r--r-- | bitbake/lib/bb/data.py | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index db938be1e6..82eefef1a6 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py @@ -6,7 +6,7 @@ BitBake 'Data' implementations Functions for interacting with the data structure used by the BitBake build tools. -The expandData and update_data are the most expensive +The expandKeys and update_data are the most expensive operations. At night the cookie monster came by and suggested 'give me cookies on setting the variables and things will work out'. Taking this suggestion into account @@ -15,7 +15,7 @@ Analyse von Algorithmen' lecture and the cookie monster seems to be right. We will track setVar more carefully to have faster update_data and expandKeys operations. -This is a treade-off between speed and memory again but +This is a trade-off between speed and memory again but the speed is more critical here. """ @@ -35,7 +35,7 @@ the speed is more critical here. # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -#Based on functions from the base bb module, Copyright 2003 Holger Schurig +# Based on functions from the base bb module, Copyright 2003 Holger Schurig import sys, os, re if sys.argv[0][-5:] == "pydoc": @@ -219,6 +219,13 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False): val = str(val) + if varExpanded.startswith("BASH_FUNC_"): + varExpanded = varExpanded[10:-2] + val = val[3:] # Strip off "() " + o.write("%s() %s\n" % (varExpanded, val)) + o.write("export -f %s\n" % (varExpanded)) + return 1 + if func: # NOTE: should probably check for unbalanced {} within the var o.write("%s() {\n%s\n}\n" % (varExpanded, val)) @@ -231,6 +238,7 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False): # to a shell, we need to escape the quotes in the var alter = re.sub('"', '\\"', val) alter = re.sub('\n', ' \\\n', alter) + alter = re.sub('\\$', '\\\\$', alter) o.write('%s="%s"\n' % (varExpanded, alter)) return 0 @@ -281,6 +289,41 @@ def emit_func(func, o=sys.__stdout__, d = init()): newdeps |= set((d.getVarFlag(dep, "vardeps", True) or "").split()) newdeps -= seen +_functionfmt = """ +def {function}(d): +{body}""" + +def emit_func_python(func, o=sys.__stdout__, d = init()): + """Emits all items in the data store in a format such that it can be sourced by a shell.""" + + def write_func(func, o, call = False): + body = d.getVar(func, True) + if not body.startswith("def"): + body = _functionfmt.format(function=func, body=body) + + o.write(body.strip() + "\n\n") + if call: + o.write(func + "(d)" + "\n\n") + + write_func(func, o, True) + pp = bb.codeparser.PythonParser(func, logger) + pp.parse_python(d.getVar(func, True)) + newdeps = pp.execs + newdeps |= set((d.getVarFlag(func, "vardeps", True) or "").split()) + seen = set() + while newdeps: + deps = newdeps + seen |= deps + newdeps = set() + for dep in deps: + if d.getVarFlag(dep, "func") and d.getVarFlag(dep, "python"): + write_func(dep, o) + pp = bb.codeparser.PythonParser(dep, logger) + pp.parse_python(d.getVar(dep, True)) + newdeps |= pp.execs + newdeps |= set((d.getVarFlag(dep, "vardeps", True) or "").split()) + newdeps -= seen + def update_data(d): """Performs final steps upon the datastore, including application of overrides""" d.finalize(parent = True) |