OSDN Git Service

Better pattern matching and dump of warning messages.
authorChih-Hung Hsieh <chh@google.com>
Tue, 11 Oct 2016 22:33:19 +0000 (15:33 -0700)
committerChih-Hung Hsieh <chh@google.com>
Tue, 11 Oct 2016 22:33:19 +0000 (15:33 -0700)
* Warning messages must start with source file path.
  This will reject lines containing only 'warning:'
  but not a source file path prefix.
* Escape both backslash and quotation marks in the
  dump of strings to JavaScript string literals.

Bug: 32060052
Test: run through build.log files
Change-Id: Ib064768b1ba2954f974604ea054f7a6d2ad15ae7

tools/warn.py

index ea1cd22..7abca32 100755 (executable)
@@ -2028,7 +2028,8 @@ def parse_input_file():
   infile = open(args.buildlog, 'r')
   line_counter = 0
 
-  warning_pattern = re.compile('.* warning:.*')
+  # handle only warning messages with a file path
+  warning_pattern = re.compile('^[^ ]*/[^ ]*: warning: .*')
   compile_patterns()
 
   # read the log file and classify all the warnings
@@ -2055,9 +2056,9 @@ def parse_input_file():
         target_variant = m.group(0)
 
 
-# Return s with escaped quotation characters.
+# Return s with escaped backslash and quotation characters.
 def escape_string(s):
-  return s.replace('"', '\\"')
+  return s.replace('\\', '\\\\').replace('"', '\\"')
 
 
 # Return s without trailing '\n' and escape the quotation characters.