diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-03 14:30:20 +0100 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-31 12:47:41 +0100 |
commit | 332c33af188c14dd0051d8a45fe0ad680611db69 (patch) | |
tree | 62b50d333ac8404671b591b7f6ba8fc71abc1c89 /bitbake/lib/bb/data.py | |
parent | 3492bff64a809b3a2a2376b83f41e099e16d22f6 (diff) | |
download | poky-332c33af188c14dd0051d8a45fe0ad680611db69.tar.gz |
bitbake/data.py: Add emit_func() and generate_dependencies() functions
These functions allow generation of dependency data between funcitons and
variables allowing moves to be made towards generating checksums and allowing
use of the dependency information in other parts of bitbake.
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/data.py')
-rw-r--r-- | bitbake/lib/bb/data.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index 223f9c5052..4cad495b0a 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -46,6 +46,7 @@ sys.path.insert(0, path) | |||
46 | from itertools import groupby | 46 | from itertools import groupby |
47 | 47 | ||
48 | from bb import data_smart | 48 | from bb import data_smart |
49 | from bb import codeparser | ||
49 | import bb | 50 | import bb |
50 | 51 | ||
51 | _dict_type = data_smart.DataSmart | 52 | _dict_type = data_smart.DataSmart |
@@ -243,10 +244,84 @@ def export_vars(d): | |||
243 | pass | 244 | pass |
244 | return ret | 245 | return ret |
245 | 246 | ||
247 | def emit_func(func, o=sys.__stdout__, d = init()): | ||
248 | """Emits all items in the data store in a format such that it can be sourced by a shell.""" | ||
249 | |||
250 | keys = (key for key in d.keys() if not key.startswith("__") and not d.getVarFlag(key, "func")) | ||
251 | for key in keys: | ||
252 | emit_var(key, o, d, False) and o.write('\n') | ||
253 | |||
254 | emit_var(func, o, d, False) and o.write('\n') | ||
255 | newdeps = bb.codeparser.ShellParser().parse_shell(d.getVar(func, True)) | ||
256 | seen = set() | ||
257 | while newdeps: | ||
258 | deps = newdeps | ||
259 | seen |= deps | ||
260 | newdeps = set() | ||
261 | for dep in deps: | ||
262 | if bb.data.getVarFlag(dep, "func", d): | ||
263 | emit_var(dep, o, d, False) and o.write('\n') | ||
264 | newdeps |= bb.codeparser.ShellParser().parse_shell(d.getVar(dep, True)) | ||
265 | newdeps -= seen | ||
266 | |||
246 | def update_data(d): | 267 | def update_data(d): |
247 | """Performs final steps upon the datastore, including application of overrides""" | 268 | """Performs final steps upon the datastore, including application of overrides""" |
248 | d.finalize() | 269 | d.finalize() |
249 | 270 | ||
271 | def build_dependencies(key, keys, shelldeps, d): | ||
272 | deps = set() | ||
273 | try: | ||
274 | if d.getVarFlag(key, "func"): | ||
275 | if d.getVarFlag(key, "python"): | ||
276 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) | ||
277 | parser = bb.codeparser.PythonParser() | ||
278 | parser.parse_python(parsedvar.value) | ||
279 | deps = deps | parser.references | ||
280 | else: | ||
281 | parsedvar = d.expandWithRefs(d.getVar(key, False), key) | ||
282 | parser = bb.codeparser.ShellParser() | ||
283 | parser.parse_shell(parsedvar.value) | ||
284 | deps = deps | shelldeps | ||
285 | deps = deps | parsedvar.references | ||
286 | deps = deps | (keys & parser.execs) | (keys & parsedvar.execs) | ||
287 | else: | ||
288 | parser = d.expandWithRefs(d.getVar(key, False), key) | ||
289 | deps |= parser.references | ||
290 | deps = deps | (keys & parser.execs) | ||
291 | except: | ||
292 | bb.note("Error expanding variable %s" % key) | ||
293 | raise | ||
294 | return deps | ||
295 | #bb.note("Variable %s references %s and calls %s" % (key, str(deps), str(execs))) | ||
296 | #d.setVarFlag(key, "vardeps", deps) | ||
297 | |||
298 | def generate_dependencies(d): | ||
299 | |||
300 | keys = set(key for key in d.keys() if not key.startswith("__")) | ||
301 | shelldeps = set(key for key in keys if d.getVarFlag(key, "export") and not d.getVarFlag(key, "unexport")) | ||
302 | |||
303 | deps = {} | ||
304 | taskdeps = {} | ||
305 | |||
306 | tasklist = bb.data.getVar('__BBTASKS', d) or [] | ||
307 | for task in tasklist: | ||
308 | deps[task] = build_dependencies(task, keys, shelldeps, d) | ||
309 | |||
310 | newdeps = deps[task] | ||
311 | seen = set() | ||
312 | while newdeps: | ||
313 | nextdeps = newdeps | ||
314 | seen |= nextdeps | ||
315 | newdeps = set() | ||
316 | for dep in nextdeps: | ||
317 | if dep not in deps: | ||
318 | deps[dep] = build_dependencies(dep, keys, shelldeps, d) | ||
319 | newdeps |= deps[dep] | ||
320 | newdeps -= seen | ||
321 | taskdeps[task] = seen | newdeps | ||
322 | #print "For %s: %s" % (task, str(taskdeps[task])) | ||
323 | return taskdeps, deps | ||
324 | |||
250 | def inherits_class(klass, d): | 325 | def inherits_class(klass, d): |
251 | val = getVar('__inherit_cache', d) or [] | 326 | val = getVar('__inherit_cache', d) or [] |
252 | if os.path.join('classes', '%s.bbclass' % klass) in val: | 327 | if os.path.join('classes', '%s.bbclass' % klass) in val: |