aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-07-19 19:48:26 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-07-19 20:13:09 +0200
commite83f8a4737e67d7bc6447bbdc814db5df743daef (patch)
tree0a58108c1994e2cbb9cb1f165cf6dd46a3c14a79
parent6475204b4ca6fd77fbeaa1d1be07d3bcefc518bc (diff)
scripts/verify_log_statements.py: on parse error, print file
If string eval encounters an uncovered parse error, it's useful to know which file it happened in. Change-Id: I5fe9a3bbdbfb8a995f24596bf09e70ca5bb3fe8a
-rwxr-xr-xscripts/verify_log_statements.py109
1 files changed, 56 insertions, 53 deletions
diff --git a/scripts/verify_log_statements.py b/scripts/verify_log_statements.py
index 567a96a..9a9cd1b 100755
--- a/scripts/verify_log_statements.py
+++ b/scripts/verify_log_statements.py
@@ -63,59 +63,62 @@ def check_file(f):
if not (f.endswith('.h') or f.endswith('.c') or f.endswith('.cpp')):
return []
- errors_found = []
-
- file_content = codecs.open(f, "r", "utf-8").read()
-
- for log in log_statement_re.finditer(file_content):
- quoted = log.group(2)
-
- # Skip 'LOG("bla" fmt )' strings that typically appear as #defines.
- if fmt_re.match(quoted):
- if debug:
- errors_found.append(error_found(f, log.start(), 'Skipping define', log.group(0)))
- continue
-
- # Drop PRI* parts of 'LOG("bla %"PRIu64" foo")'
- for n in (16,32,64):
- quoted = quoted.replace('PRIu' + str(n), '')
- quoted = quoted.replace('PRId' + str(n), '')
- quoted = ''.join(osmo_stringify_re.split(quoted))
-
- # Use py eval to join separate string constants: drop any tabs/newlines
- # that are not in quotes, between separate string constants.
- try:
- quoted = eval('(' + quoted + '\n)' )
- except:
- # hopefully eval broke because of some '## args' macro def
- if debug:
- ignored.append(error_found(f, log.start(), 'Ignoring', log.group(0)))
- continue
-
- # check for errors...
-
- # final newline
- if not quoted.endswith('\n'):
- errors_found.append(error_found(f, log.start(), 'Missing final newline', log.group(0)))
-
- # disallowed chars and extra newlines
- for c in quoted[:-1]:
- if not c.isprintable() and not c == '\t':
- if c == '\n':
- msg = 'Extraneous newline'
- else:
- msg = 'Illegal char'
- errors_found.append(error_found(f, log.start(), msg + ' %r' % c, log.group(0)))
-
- if not error_found:
- return []
-
- line_idx = make_line_idx(file_content)
- for r, line in zip(errors_found, char_pos_2_line(line_idx, [rr.charpos for rr in errors_found])):
- r.line = line
-
- return errors_found
-
+ try:
+ errors_found = []
+
+ file_content = codecs.open(f, "r", "utf-8").read()
+
+ for log in log_statement_re.finditer(file_content):
+ quoted = log.group(2)
+
+ # Skip 'LOG("bla" fmt )' strings that typically appear as #defines.
+ if fmt_re.match(quoted):
+ if debug:
+ errors_found.append(error_found(f, log.start(), 'Skipping define', log.group(0)))
+ continue
+
+ # Drop PRI* parts of 'LOG("bla %"PRIu64" foo")'
+ for n in (16,32,64):
+ quoted = quoted.replace('PRIu' + str(n), '')
+ quoted = quoted.replace('PRId' + str(n), '')
+ quoted = ''.join(osmo_stringify_re.split(quoted))
+
+ # Use py eval to join separate string constants: drop any tabs/newlines
+ # that are not in quotes, between separate string constants.
+ try:
+ quoted = eval('(' + quoted + '\n)' )
+ except:
+ # hopefully eval broke because of some '## args' macro def
+ if debug:
+ ignored.append(error_found(f, log.start(), 'Ignoring', log.group(0)))
+ continue
+
+ # check for errors...
+
+ # final newline
+ if not quoted.endswith('\n'):
+ errors_found.append(error_found(f, log.start(), 'Missing final newline', log.group(0)))
+
+ # disallowed chars and extra newlines
+ for c in quoted[:-1]:
+ if not c.isprintable() and not c == '\t':
+ if c == '\n':
+ msg = 'Extraneous newline'
+ else:
+ msg = 'Illegal char'
+ errors_found.append(error_found(f, log.start(), msg + ' %r' % c, log.group(0)))
+
+ if not error_found:
+ return []
+
+ line_idx = make_line_idx(file_content)
+ for r, line in zip(errors_found, char_pos_2_line(line_idx, [rr.charpos for rr in errors_found])):
+ r.line = line
+
+ return errors_found
+ except:
+ print("ERROR WHILE PROCESSING %r" % f, file=sys.stderr)
+ raise
all_errors_found = []
for f in args: