api_coverage.py: Print file name and line number with the reported item
This commit is contained in:
parent
ea2fa02667
commit
a605fdfe8b
|
@ -116,6 +116,7 @@ def pkg_config(require, min_vers=None):
|
||||||
|
|
||||||
def get_capis(inc_path, prefix):
|
def get_capis(inc_path, prefix):
|
||||||
capis = []
|
capis = []
|
||||||
|
capilns = []
|
||||||
capi_pattern = re.compile(
|
capi_pattern = re.compile(
|
||||||
"^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" +
|
"^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" +
|
||||||
c_excludes + ")(" + prefix +
|
c_excludes + ")(" + prefix +
|
||||||
|
@ -135,18 +136,28 @@ def get_capis(inc_path, prefix):
|
||||||
with open(*open_args, **open_kwargs) as header:
|
with open(*open_args, **open_kwargs) as header:
|
||||||
capi = header.read()
|
capi = header.read()
|
||||||
|
|
||||||
|
line_starts = []
|
||||||
|
i = 0
|
||||||
|
header.seek(0)
|
||||||
|
for line in header:
|
||||||
|
line_starts.append(i)
|
||||||
|
i += len(line)
|
||||||
matches = re.finditer(capi_pattern, capi)
|
matches = re.finditer(capi_pattern, capi)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
func = match.group(1)
|
func = match.group(1)
|
||||||
|
start = match.start()
|
||||||
|
line_n = line_starts.index(start) + 1
|
||||||
|
capilns.append((f, line_n))
|
||||||
capis.append(func)
|
capis.append(func)
|
||||||
|
|
||||||
return capis
|
return capilns, capis
|
||||||
|
|
||||||
|
|
||||||
def get_pyapis(pxd_path, header_name, prefix):
|
def get_pyapis(pxd_path, header_name, prefix):
|
||||||
|
pyapilns = []
|
||||||
pyapis = []
|
pyapis = []
|
||||||
pyapi_pattern1 = re.compile(
|
pyapi_pattern1 = re.compile(
|
||||||
'(cdef extern from "' + header_name + '\.h":\n)(.+)',
|
'cdef extern from "' + header_name + '\.h":\n(.+)',
|
||||||
flags=re.S
|
flags=re.S
|
||||||
)
|
)
|
||||||
pyapi_pattern2 = re.compile(
|
pyapi_pattern2 = re.compile(
|
||||||
|
@ -165,15 +176,24 @@ def get_pyapis(pxd_path, header_name, prefix):
|
||||||
|
|
||||||
with open(*open_args, **open_kwargs) as pxd:
|
with open(*open_args, **open_kwargs) as pxd:
|
||||||
pyapi = pxd.read()
|
pyapi = pxd.read()
|
||||||
|
|
||||||
cdef = re.search(pyapi_pattern1, pyapi)
|
cdef = re.search(pyapi_pattern1, pyapi)
|
||||||
if cdef:
|
if cdef:
|
||||||
matches = re.finditer(pyapi_pattern2, cdef.group(2))
|
offset = cdef.start(1)
|
||||||
|
line_starts = []
|
||||||
|
i = 0
|
||||||
|
pxd.seek(0)
|
||||||
|
for line in pxd:
|
||||||
|
line_starts.append(i)
|
||||||
|
i += len(line)
|
||||||
|
matches = re.finditer(pyapi_pattern2, cdef.group(1))
|
||||||
for match in matches:
|
for match in matches:
|
||||||
func = match.group(1)
|
func = match.group(1)
|
||||||
|
start = match.start() + offset
|
||||||
|
line_n = line_starts.index(start) + 1
|
||||||
|
pyapilns.append((f, line_n))
|
||||||
pyapis.append(func)
|
pyapis.append(func)
|
||||||
|
|
||||||
return pyapis
|
return pyapilns, pyapis
|
||||||
|
|
||||||
|
|
||||||
for lib in args.libs:
|
for lib in args.libs:
|
||||||
|
@ -190,18 +210,34 @@ for lib in args.libs:
|
||||||
|
|
||||||
pxd_path, header_name, prefix = params[lib]
|
pxd_path, header_name, prefix = params[lib]
|
||||||
|
|
||||||
capis = get_capis(inc_path, prefix)
|
c_api_line_ns, c_apis = get_capis(inc_path, prefix)
|
||||||
pyapis = get_pyapis(pxd_path, header_name, prefix)
|
py_api_line_ns, py_apis = get_pyapis(pxd_path, header_name, prefix)
|
||||||
|
|
||||||
capis = set(capis)
|
capis = set(c_apis)
|
||||||
pyapis = set(pyapis)
|
pyapis = set(py_apis)
|
||||||
differences = capis.union(pyapis) - capis.intersection(pyapis)
|
differences = capis.union(pyapis) - capis.intersection(pyapis)
|
||||||
|
|
||||||
for d in sorted(differences):
|
for d in sorted(differences):
|
||||||
if args.python and d in capis:
|
if args.python:
|
||||||
print("{0} is missing from Python API".format(d))
|
try:
|
||||||
if args.c and d in pyapis:
|
i = c_apis.index(d)
|
||||||
print("{0} is missing from C API".format(d))
|
line_f, line_n = c_api_line_ns[i]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print("{0} line {1}: {2} is missing from Python API".format(
|
||||||
|
line_f, line_n, d
|
||||||
|
))
|
||||||
|
if args.c:
|
||||||
|
try:
|
||||||
|
i = py_apis.index(d)
|
||||||
|
line_f, line_n = py_api_line_ns[i]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print("{0} line {1}: {2} is missing from C API".format(
|
||||||
|
line_f, line_n, d
|
||||||
|
))
|
||||||
|
|
||||||
if args.python or args.c:
|
if args.python or args.c:
|
||||||
print("\n---")
|
print("\n---")
|
||||||
|
|
Loading…
Reference in New Issue