include_tracer.py: Fix crashes by SkRefCnt.h and gmock_link_test.cc
- Do not crash with |#include SK_REF_CNT_MIXIN_INCLUDE|.
"SK_REF_CND_MIXIN_INCLUDE" will be handled as a file name, and Walk()
will show the " -- not found" message for it.
- Do not crash with '#include "..."'.
Support multiple spaces between '#include' and '"' or '<'.
Bug: 849199
Change-Id: I67ef457778fad47b2a6a7edf050fbe3c86e951df
Reviewed-on: https://chromium-review.googlesource.com/1086547
Commit-Queue: Kent Tamura <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#564365}
diff --git a/tools/include_tracer.py b/tools/include_tracer.py
index 8f817c3..e7089bf 100755
--- a/tools/include_tracer.py
+++ b/tools/include_tracer.py
@@ -13,6 +13,7 @@
"""
import os
+import re
import sys
# Created by copying the command line for prerender_browsertest.cc, replacing
@@ -178,13 +179,12 @@
lines = []
for line in lines:
line = line.strip()
- if line.startswith('#include "'):
- total_bytes += Walk(
- seen, line.split('"')[1], resolved_filename, indent + 2)
- elif line.startswith('#include '):
- include = '<' + line.split('<')[1].split('>')[0] + '>'
- total_bytes += Walk(
- seen, include, resolved_filename, indent + 2)
+ match = re.match(r'#include\s+(\S+).*', line)
+ if match:
+ include = match.group(1)
+ if include.startswith('"'):
+ include = include[1:-1]
+ total_bytes += Walk(seen, include, resolved_filename, indent + 2)
elif line.startswith('import '):
total_bytes += Walk(
seen, line.split('"')[1], resolved_filename, indent + 2)