summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-05-16 14:23:20 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-05-16 14:23:20 +0300
commita605fdfe8b817432ed486800954a59bcae7525c2 (patch)
tree36780060cebab214390bb54bea73bb8800e55faf
parentea2fa02667cd6ddc92406fd73e288ed14ab77983 (diff)
api_coverage.py: Print file name and line number with the reported item
-rwxr-xr-xapi_coverage.py62
1 files changed, 49 insertions, 13 deletions
diff --git a/api_coverage.py b/api_coverage.py
index 442d9ff..235ad0c 100755
--- a/api_coverage.py
+++ b/api_coverage.py
@@ -116,6 +116,7 @@ def pkg_config(require, min_vers=None):
116 116
117def get_capis(inc_path, prefix): 117def get_capis(inc_path, prefix):
118 capis = [] 118 capis = []
119 capilns = []
119 capi_pattern = re.compile( 120 capi_pattern = re.compile(
120 "^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" + 121 "^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" +
121 c_excludes + ")(" + prefix + 122 c_excludes + ")(" + prefix +
@@ -135,18 +136,28 @@ def get_capis(inc_path, prefix):
135 with open(*open_args, **open_kwargs) as header: 136 with open(*open_args, **open_kwargs) as header:
136 capi = header.read() 137 capi = header.read()
137 138
139 line_starts = []
140 i = 0
141 header.seek(0)
142 for line in header:
143 line_starts.append(i)
144 i += len(line)
138 matches = re.finditer(capi_pattern, capi) 145 matches = re.finditer(capi_pattern, capi)
139 for match in matches: 146 for match in matches:
140 func = match.group(1) 147 func = match.group(1)
148 start = match.start()
149 line_n = line_starts.index(start) + 1
150 capilns.append((f, line_n))
141 capis.append(func) 151 capis.append(func)
142 152
143 return capis 153 return capilns, capis
144 154
145 155
146def get_pyapis(pxd_path, header_name, prefix): 156def get_pyapis(pxd_path, header_name, prefix):
157 pyapilns = []
147 pyapis = [] 158 pyapis = []
148 pyapi_pattern1 = re.compile( 159 pyapi_pattern1 = re.compile(
149 '(cdef extern from "' + header_name + '\.h":\n)(.+)', 160 'cdef extern from "' + header_name + '\.h":\n(.+)',
150 flags=re.S 161 flags=re.S
151 ) 162 )
152 pyapi_pattern2 = re.compile( 163 pyapi_pattern2 = re.compile(
@@ -165,15 +176,24 @@ def get_pyapis(pxd_path, header_name, prefix):
165 176
166 with open(*open_args, **open_kwargs) as pxd: 177 with open(*open_args, **open_kwargs) as pxd:
167 pyapi = pxd.read() 178 pyapi = pxd.read()
168
169 cdef = re.search(pyapi_pattern1, pyapi) 179 cdef = re.search(pyapi_pattern1, pyapi)
170 if cdef: 180 if cdef:
171 matches = re.finditer(pyapi_pattern2, cdef.group(2)) 181 offset = cdef.start(1)
182 line_starts = []
183 i = 0
184 pxd.seek(0)
185 for line in pxd:
186 line_starts.append(i)
187 i += len(line)
188 matches = re.finditer(pyapi_pattern2, cdef.group(1))
172 for match in matches: 189 for match in matches:
173 func = match.group(1) 190 func = match.group(1)
191 start = match.start() + offset
192 line_n = line_starts.index(start) + 1
193 pyapilns.append((f, line_n))
174 pyapis.append(func) 194 pyapis.append(func)
175 195
176 return pyapis 196 return pyapilns, pyapis
177 197
178 198
179for lib in args.libs: 199for lib in args.libs:
@@ -190,18 +210,34 @@ for lib in args.libs:
190 210
191 pxd_path, header_name, prefix = params[lib] 211 pxd_path, header_name, prefix = params[lib]
192 212
193 capis = get_capis(inc_path, prefix) 213 c_api_line_ns, c_apis = get_capis(inc_path, prefix)
194 pyapis = get_pyapis(pxd_path, header_name, prefix) 214 py_api_line_ns, py_apis = get_pyapis(pxd_path, header_name, prefix)
195 215
196 capis = set(capis) 216 capis = set(c_apis)
197 pyapis = set(pyapis) 217 pyapis = set(py_apis)
198 differences = capis.union(pyapis) - capis.intersection(pyapis) 218 differences = capis.union(pyapis) - capis.intersection(pyapis)
199 219
200 for d in sorted(differences): 220 for d in sorted(differences):
201 if args.python and d in capis: 221 if args.python:
202 print("{0} is missing from Python API".format(d)) 222 try:
203 if args.c and d in pyapis: 223 i = c_apis.index(d)
204 print("{0} is missing from C API".format(d)) 224 line_f, line_n = c_api_line_ns[i]
225 except ValueError:
226 pass
227 else:
228 print("{0} line {1}: {2} is missing from Python API".format(
229 line_f, line_n, d
230 ))
231 if args.c:
232 try:
233 i = py_apis.index(d)
234 line_f, line_n = py_api_line_ns[i]
235 except ValueError:
236 pass
237 else:
238 print("{0} line {1}: {2} is missing from C API".format(
239 line_f, line_n, d
240 ))
205 241
206 if args.python or args.c: 242 if args.python or args.c:
207 print("\n---") 243 print("\n---")