]> code.ossystems Code Review - openembedded-core.git/commitdiff
rootfs.py: Unify _log_check_warn() and _log_check_error()
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>
Wed, 18 May 2016 22:28:18 +0000 (00:28 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 19 May 2016 21:31:34 +0000 (22:31 +0100)
Use a common _log_check_common() function (based on the old
_log_check_warn() function) to implement the logic for both
_log_check_warn() and _log_check_error().

The main benefit of this is that now all error messages will be
reported again, not just the first one found. Additionally the output
will now look the same for both error and warning messages.

This removes the context for the error messages. However, since there
was no indication in the output that some of the lines were context,
they were more confusing than helping.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oe/rootfs.py

index 479e4ccc5e9221da3789194ce87e79ac5d7b7cf0..f5c465fbd20e3d4d52c555db7bf3ab43c8459e11 100644 (file)
@@ -40,7 +40,7 @@ class Rootfs(object):
     def _log_check(self):
         pass
 
-    def _log_check_warn(self):
+    def _log_check_common(self, type, match):
         # Ignore any lines containing log_check to avoid recursion, and ignore
         # lines beginning with a + since sh -x may emit code which isn't
         # actually executed, but may contain error messages
@@ -48,7 +48,7 @@ class Rootfs(object):
         if hasattr(self, 'log_check_expected_regexes'):
             excludes.extend(self.log_check_expected_regexes)
         excludes = [re.compile(x) for x in excludes]
-        r = re.compile('^(warn|Warn|WARNING:)')
+        r = re.compile(match)
         log_path = self.d.expand("${T}/log.do_rootfs")
         messages = []
         with open(log_path, 'r') as log:
@@ -65,45 +65,21 @@ class Rootfs(object):
                     messages.append('[log_check] %s' % line)
         if messages:
             if len(messages) == 1:
-                msg = 'a warning message'
+                msg = '1 %s message' % type
             else:
-                msg = '%d warning messages' % len(messages)
-            bb.warn('[log_check] %s: found %s in the logfile:\n%s'
-                    % (self.d.getVar('PN', True), msg, ''.join(messages)))
-
-    def _log_check_error(self):
-        # Ignore any lines containing log_check to avoid recursion, and ignore
-        # lines beginning with a + since sh -x may emit code which isn't
-        # actually executed, but may contain error messages
-        excludes = [ 'log_check', r'^\+' ]
-        if hasattr(self, 'log_check_expected_regexes'):
-            excludes.extend(self.log_check_expected_regexes)
-        excludes = [re.compile(x) for x in excludes]
-        r = re.compile(self.log_check_regex)
-        log_path = self.d.expand("${T}/log.do_rootfs")
-        with open(log_path, 'r') as log:
-            found_error = 0
-            message = "\n"
-            for line in log:
-                for ee in excludes:
-                    m = ee.search(line)
-                    if m:
-                        break
-                if m:
-                    continue
-
-                m = r.search(line)
-                if m:
-                    found_error = 1
-                    bb.warn('[log_check] %s: found an error message in the logfile (keyword \'%s\'):\n[log_check] %s'
-                                   % (self.d.getVar('PN', True), m.group(), line))
+                msg = '%d %s messages' % (len(messages), type)
+            msg = '[log_check] %s: found %s in the logfile:\n%s' % \
+                (self.d.getVar('PN', True), msg, ''.join(messages))
+            if type == 'error':
+                bb.fatal(msg)
+            else:
+                bb.warn(msg)
 
-                if found_error >= 1 and found_error <= 5:
-                    message += line + '\n'
-                    found_error += 1
+    def _log_check_warn(self):
+        self._log_check_common('warning', '^(warn|Warn|WARNING:)')
 
-                if found_error == 6:
-                    bb.fatal(message)
+    def _log_check_error(self):
+        self._log_check_common('error', self.log_check_regex)
 
     def _insert_feed_uris(self):
         if bb.utils.contains("IMAGE_FEATURES", "package-management",