rootfs.py: Unify _log_check_warn() and _log_check_error()

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.

(From OE-Core rev: dd73dcac36b80b3b886a2e9bf575b91c4f60d039)

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Peter Kjellerstedt 2016-05-19 00:28:18 +02:00 committed by Richard Purdie
parent 9948e0d3cb
commit 18eccfa383
1 changed files with 14 additions and 38 deletions

View 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)))
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)
def _log_check_warn(self):
self._log_check_common('warning', '^(warn|Warn|WARNING:)')
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))
if found_error >= 1 and found_error <= 5:
message += line + '\n'
found_error += 1
if found_error == 6:
bb.fatal(message)
self._log_check_common('error', self.log_check_regex)
def _insert_feed_uris(self):
if bb.utils.contains("IMAGE_FEATURES", "package-management",