1 # Emit the datastore to a file, and if it was previously emitted, display the
2 # differences to the user.
4 EMIT_DIR = "${TMPDIR}/emit-data"
5 EMIT_BLACKLIST += "BUILDSTART DATE TIME DATETIME \
7 DISPLAY XDG_SESSION_COOKIE \
8 SSH_AUTH_SOCK SSH_TTY SSH_CLIENT SSH_CONNECTION \
9 SESSION_MANAGER DESKTOP_SESSION COLORTERM TERM \
10 XAUTHORITY GTK_RC_FILES DBUS_SESSION_BUS_ADDRESS \
12 GNOME_KEYRING GNOME_KEYRING_PID"
14 def diff_datadict(d, old_data, data):
15 from itertools import chain
16 from difflib import Differ
17 from fnmatch import fnmatchcase
19 blacklist = d.getVar("EMIT_BLACKLIST", True).split()
21 keys = sorted(set(chain(old_data.iterkeys(), data.iterkeys())))
22 keys = [key for key in keys
23 if not any(fnmatchcase(key, pat) for pat in blacklist)]
25 old = ["%s: %s\n" % (key, old_data.get(key)) for key in keys]
26 new = ["%s: %s\n" % (key, data.get(key)) for key in keys]
27 return Differ().compare(old, new)
30 python do_emit_data () {
33 data = dict((key, repr(d.getVar(key, False))) for key in d.keys())
34 outfile = os.path.join(d.getVar("EMIT_DIR", True), d.getVar("PF", True))
35 bb.mkdirhier(os.path.dirname(outfile))
36 if os.path.exists(outfile):
37 f = open(outfile, "rb")
38 old_data = pickle.load(f)
41 diff = diff_datadict(d, old_data, data)
42 differences = [line for line in diff if not line.startswith(" ")]
44 bb.note(bb.data.expand("${PF}: data has changed:", d))
45 for line in differences:
46 bb.note(line.rstrip())
48 pickle.dump(data, open(outfile, "wb"))
50 do_emit_data[nostamp] = "1"
53 do_emit_data_all[recrdeptask] = "do_emit_data"
54 do_emit_data_all[nostamp] = "1"
55 addtask emit_data_all after do_emit_data