Patchwork [bitbake-devel] Cache parse warnings

login
register
mail settings
Submitter Valentin Popa
Date Oct. 17, 2013, 3:55 p.m.
Message ID <1382025314-29807-1-git-send-email-valentin.popa@intel.com>
Download mbox | patch
Permalink /patch/60141/
State New
Headers show

Comments

Valentin Popa - Oct. 17, 2013, 3:55 p.m.
During parsing, if .bb files are already parsed,
bitbake loads the cache and doesn't throw any
of the warnings generated during the previously
parsing process.
With this patch, bitbake caches also the warnings
that appear during parsing.

In case of loading from cache, the warnings are sent after
CacheLoadCompleted event and the parse warnings log handler
has to mutate the records so HobEventHandler can discriminate
warnings.

[YOCTO #3783]
Signed-off-by: Valentin Popa <valentin.popa@intel.com>
---
 bitbake/lib/bb/cache.py                     | 41 ++++++++++++++++++++++++++++-
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |  7 ++++-
 2 files changed, 46 insertions(+), 2 deletions(-)

Patch

diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py
index 318781b..ac343ff 100644
--- a/bitbake/lib/bb/cache.py
+++ b/bitbake/lib/bb/cache.py
@@ -31,11 +31,16 @@ 
 
 import os
 import logging
+import copy
 from collections import defaultdict
 import bb.utils
 
 logger = logging.getLogger("BitBake.Cache")
 
+#logger to handle warnings during parsing
+parseLogger = logging.getLogger("BitBake")
+parseLogger.setLevel(logging.WARNING)
+
 try:
     import cPickle as pickle
 except ImportError:
@@ -45,6 +50,24 @@  except ImportError:
 
 __cache_version__ = "147"
 
+
+class ParseLogHandler(logging.Handler):
+    """
+    Handler for warnings generated during parsing.
+    Mutates records' name so the event handler can
+    discrimate between warnings generated during the
+    parsing and other warnings.
+    """
+    def __init__(self, queue):
+        logging.Handler.__init__(self)
+        self.queue = queue
+
+    def emit(self, record):
+        self.record = record
+        self.record.name = "Bitbake.Parsing"
+        self.queue.append(self.record)
+
+
 def getCacheFile(path, filename, data_hash):
     return os.path.join(path, filename + "." + data_hash)
 
@@ -94,7 +117,8 @@  class CoreRecipeInfo(RecipeInfoCommon):
 
     cachefile = "bb_cache.dat"   
 
-    def __init__(self, filename, metadata):      
+    def __init__(self, filename, metadata):
+        self.parse_warnings = []
         self.file_depends = metadata.getVar('__depends', False)
         self.timestamp = bb.parse.cached_mtime(filename)
         self.variants = self.listvar('__VARIANTS', metadata) + ['']
@@ -150,6 +174,7 @@  class CoreRecipeInfo(RecipeInfoCommon):
     @classmethod
     def init_cacheData(cls, cachedata):
         # CacheData in Core RecipeInfo Class
+        cachedata.parse_warnings = []
         cachedata.task_deps = {}
         cachedata.pkg_fn = {}
         cachedata.pkg_pn = defaultdict(list)
@@ -197,6 +222,9 @@  class CoreRecipeInfo(RecipeInfoCommon):
         cachedata.stamp_extrainfo[fn] = self.stamp_extrainfo
         cachedata.file_checksums[fn] = self.file_checksums
 
+        if self.parse_warnings:
+            cachedata.parse_warnings = self.parse_warnings
+
         provides = [self.pn]
         for provide in self.provides:
             if provide not in provides:
@@ -413,9 +441,14 @@  class Cache(object):
                 data.setVar("__depends", depends)
 
             info_array = []
+
             for cache_class in caches_array:
                 if type(cache_class) is type and issubclass(cache_class, RecipeInfoCommon):
+                    warnings = []
+                    handler = ParseLogHandler(warnings)
+                    parseLogger.addHandler(handler)
                     info = cache_class(filename, data)
+                    info.parse_warnings = copy.deepcopy(warnings);
                     info_array.append(info)
             infos.append((virtualfn, info_array))
 
@@ -434,6 +467,12 @@  class Cache(object):
             infos = []
             # info_array item is a list of [CoreRecipeInfo, XXXRecipeInfo]
             info_array = self.depends_cache[filename]
+
+            if isinstance(info_array[0], CoreRecipeInfo):
+                if info_array[0].parse_warnings:
+                    for record in info_array[0].parse_warnings:
+                        logger.callHandlers(record)
+
             for variant in info_array[0].variants:
                 virtualfn = self.realfn2virtual(filename, variant)
                 infos.append((virtualfn, self.depends_cache[virtualfn]))
diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
index 393c258..069df82 100644
--- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
+++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
@@ -216,7 +216,12 @@  class HobHandler(gobject.GObject):
                     formatter = bb.msg.BBLogFormatter()
                     msg = formatter.format(event)
                     self.error_msg += msg + '\n'
-                elif event.levelno >= logging.WARNING and self.parsing == True:
+
+                #elif there are warnings during the parsing or after
+                #CacheLoadCompleted event (and records belonging to
+                #'Bitbake.Parsing' logger exist) then emit parsing-warning signal
+                elif event.levelno >= logging.WARNING and (self.parsing == True or
+                        event.name == "Bitbake.Parsing"):
                     formatter = bb.msg.BBLogFormatter()
                     msg = formatter.format(event)
                     warn_msg = msg + '\n'