>From 8ae0b3d9fbe314e33923ad2dfe9ea1ded95f66ff Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 31 May 2011 23:06:12 +0100 Subject: [PATCH 1/2] bitbake: Add ability to save out parsed recipes and then compare the data Signed-off-by: Richard Purdie --- bitbake/lib/bb/cache.py | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 46 insertions(+), 3 deletions(-) diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py index d083c51..34210fc 100644 --- a/bitbake/lib/bb/cache.py +++ b/bitbake/lib/bb/cache.py @@ -127,13 +127,56 @@ class RecipeInfo(namedtuple('RecipeInfo', recipe_fields)): return cls(**kwargs) @classmethod - def from_metadata(cls, filename, metadata): + def from_metadata(cls, filename, metadata, virtualfn): if cls.getvar('__SKIPPED', metadata): return cls.make_optional(skipped=True, file_depends=metadata.getVar('__depends', False), timestamp=bb.parse.cached_mtime(filename), variants=cls.listvar('__VARIANTS', metadata) + ['']) + tname = "/tmp/bbsave/" + str(os.path.basename(virtualfn)) + bb.cache.Cache.virtualfn2realfn(virtualfn)[1] + + bb.mkdirhier("/tmp/bbsave/") + newdict = {} + for k in metadata.keys(): + newdict[k] = metadata.getVarFlags(k) + if newdict[k] == None: + newdict[k] = {} + newdict[k]['content'] = metadata.getVar(k, False) + + if os.path.exists(tname): + # Compare against existing data + with open(tname, "rb") as tfile: + pickled = pickle.Unpickler(tfile) + olddict = pickled.load() + for k in olddict: + # Ignore non-interesting bits + if k == "__base_depends" or k == "TIME": + continue + if k not in newdict: + bb.note("Variable %s disappeared (%s)" % (k, tname)) + continue + for f in olddict[k]: + if f not in newdict[k]: + bb.note("Flag %s in variable %s disappeared (%s)" % (f, k, tname)) + continue + if newdict[k][f] != olddict[k][f]: + if k.find("virtclass-") == -1: + bb.note("Variable %s(%s) changed from %s to %s (%s)" % (k, f, olddict[k][f], newdict[k][f], tname)) + for f in newdict[k]: + if f not in olddict[k]: + bb.note("Flag %s in variable %s added %s" % (f, k, tname)) + continue + for k in newdict: + if k not in olddict: + bb.note("Variable %s was added" % k) + + else: + # Otherwise save data out + with open(tname, "wb") as tfile: + pickler = pickle.Pickler(tfile, pickle.HIGHEST_PROTOCOL) + pickler.dump(newdict) + tasks = metadata.getVar('__BBTASKS', False) pn = cls.getvar('PN', metadata) @@ -314,7 +357,7 @@ class Cache(object): depends |= (data.getVar("__depends", False) or set()) if depends and not variant: data.setVar("__depends", depends) - info = RecipeInfo.from_metadata(filename, data) + info = RecipeInfo.from_metadata(filename, data, virtualfn) infos.append((virtualfn, info)) return infos @@ -500,7 +543,7 @@ class Cache(object): """ realfn = self.virtualfn2realfn(file_name)[0] - info = RecipeInfo.from_metadata(realfn, data) + info = RecipeInfo.from_metadata(realfn, data, file_name) self.add_info(file_name, info, cacheData, parsed) @staticmethod -- 1.7.4.1