2013-03-06 01:08:15 -08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import subprocess
|
2013-03-08 08:15:59 -08:00
|
|
|
import argparse
|
2013-03-06 01:08:15 -08:00
|
|
|
|
2013-04-07 05:54:37 -07:00
|
|
|
c_exclude_list = [
|
2014-05-16 00:36:50 -07:00
|
|
|
"elm_app", # These are only useful for C apps
|
|
|
|
"elm_widget", # Custom widgets, probably not feasible for us to provide
|
|
|
|
"elm_quicklaunch", # Is quicklaunch relevant for us?
|
|
|
|
"emotion_object_extension_may_play_fast_get", # this optimization does
|
|
|
|
# not work from py
|
|
|
|
"edje_edit_", # Disabled
|
|
|
|
"ecore_thread_", # python has his own thread abstraction library
|
|
|
|
"ecore_pipe_", # python has his own pipe abstraction library
|
|
|
|
"ecore_getopt_", # python has his own getopt implementation
|
|
|
|
"ecore_coroutine_", # python has someting similar...maybe
|
|
|
|
"ecore_fork_", # low level stuff, not to be exposed
|
|
|
|
"ecore_timer_dump", # this is just usefull for debugging
|
|
|
|
"ecore_throttle_", # I don't know what this is :/ - davemds
|
|
|
|
"elm_check_state_pointer_set", # Cannot be implemented in Python
|
|
|
|
"elm_access", # Access disabled until 1.9
|
|
|
|
"elm_config_access", # Access disabled until 1.9
|
|
|
|
"elm_object_item_access", # Access disabled until 1.9
|
2013-04-07 05:54:37 -07:00
|
|
|
]
|
|
|
|
c_excludes = "|".join(c_exclude_list)
|
|
|
|
|
|
|
|
py_exclude_list = [
|
2014-05-16 00:36:50 -07:00
|
|
|
"elm_naviframe_item_simple_push", # macro
|
|
|
|
"elm_object_item_content", # macro
|
|
|
|
"elm_object_item_text", # macro
|
|
|
|
"elm_object_content", # macro
|
|
|
|
"elm_object_text", # macro
|
|
|
|
"elm_layout_end", # macros
|
|
|
|
"elm_layout_icon", # macros
|
|
|
|
"elm_object_domain_translatable_text", # macros
|
|
|
|
"elm_object_tooltip_translatable_text", # macros
|
|
|
|
"elm_object_translatable_text", # macros
|
|
|
|
"elm_access", # Access disabled until 1.9
|
|
|
|
"elm_config_access", # Access disabled until 1.9
|
|
|
|
"elm_object_item_access", # Access disabled until 1.9
|
2013-04-07 05:54:37 -07:00
|
|
|
]
|
|
|
|
py_excludes = "|".join(py_exclude_list)
|
|
|
|
|
|
|
|
params = {
|
|
|
|
"eo": ("include", "Eo", "eo"),
|
|
|
|
"evas": ("include", "Evas", "evas"),
|
2014-05-16 00:36:50 -07:00
|
|
|
"ecore": ("efl/ecore", "Ecore", "ecore"),
|
|
|
|
"ecore-file": ("efl/ecore", "Ecore_File", "ecore_file"),
|
|
|
|
"ecore-x": ("efl/ecore", "Ecore_X", "ecore_x"),
|
2013-04-07 05:54:37 -07:00
|
|
|
"edje": ("include", "Edje", "edje"),
|
|
|
|
"emotion": ("include", "Emotion", "emotion"),
|
|
|
|
"elementary": ("efl/elementary", "Elementary", "elm"),
|
|
|
|
}
|
2013-03-10 03:56:34 -07:00
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
EFL_MIN_VERSION = "1.9.99"
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Reports EFL vs. Python-EFL API functions coverage"
|
|
|
|
)
|
|
|
|
api_group = parser.add_argument_group("api")
|
|
|
|
api_group.add_argument(
|
|
|
|
"--python",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Show Python API coverage"
|
|
|
|
)
|
|
|
|
api_group.add_argument(
|
|
|
|
"--c",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Show C API coverage"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"libs",
|
|
|
|
nargs="*",
|
2014-08-31 07:26:19 -07:00
|
|
|
choices=(list(params.keys()) + ["all"]),
|
2014-05-16 00:36:50 -07:00
|
|
|
default="all"
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if "all" in args.libs:
|
|
|
|
args.libs = params.keys()
|
|
|
|
|
|
|
|
if not args.python and not args.c:
|
|
|
|
args.python = True
|
|
|
|
args.c = True
|
|
|
|
|
|
|
|
|
2013-03-08 08:15:59 -08:00
|
|
|
def pkg_config(require, min_vers=None):
|
|
|
|
name = require.capitalize()
|
2013-03-06 01:08:15 -08:00
|
|
|
try:
|
2014-05-16 00:36:50 -07:00
|
|
|
ver = subprocess.check_output(
|
|
|
|
["pkg-config", "--modversion", require]
|
|
|
|
).decode("utf-8").strip()
|
2013-03-06 01:08:15 -08:00
|
|
|
if min_vers is not None:
|
2014-05-16 00:36:50 -07:00
|
|
|
assert 0 == subprocess.call(
|
|
|
|
["pkg-config", "--atleast-version", min_vers, require]
|
|
|
|
)
|
|
|
|
cflags = subprocess.check_output(
|
|
|
|
["pkg-config", "--cflags-only-I", require]
|
|
|
|
).decode("utf-8").split()
|
2013-03-08 08:15:59 -08:00
|
|
|
return cflags
|
2013-03-06 01:08:15 -08:00
|
|
|
except (OSError, subprocess.CalledProcessError):
|
2014-05-16 00:36:50 -07:00
|
|
|
raise SystemExit(
|
|
|
|
"Failed to find %s with 'pkg-config'. Please make sure that it "
|
|
|
|
"is installed and available on your system path."
|
|
|
|
) % (name)
|
2013-03-06 01:08:15 -08:00
|
|
|
except (AssertionError):
|
2014-05-16 00:36:50 -07:00
|
|
|
raise SystemExit(
|
|
|
|
"Failed to match version. Found: %s Needed: %s" % (ver, min_vers)
|
|
|
|
)
|
|
|
|
|
2013-03-06 01:08:15 -08:00
|
|
|
|
2013-03-08 08:15:59 -08:00
|
|
|
def get_capis(inc_path, prefix):
|
|
|
|
capis = []
|
2014-05-16 04:23:20 -07:00
|
|
|
capilns = []
|
2014-05-16 00:36:50 -07:00
|
|
|
capi_pattern = re.compile(
|
|
|
|
"^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" +
|
|
|
|
c_excludes + ")(" + prefix +
|
|
|
|
"_\w+) *\(",
|
|
|
|
flags=re.S | re.M
|
|
|
|
)
|
2013-03-06 01:08:15 -08:00
|
|
|
|
2013-03-08 08:15:59 -08:00
|
|
|
for path, dirs, files in os.walk(inc_path):
|
|
|
|
for f in files:
|
2014-05-16 00:36:50 -07:00
|
|
|
if f.endswith(".eo.h") or not f.endswith(".h"):
|
2014-04-29 02:19:14 -07:00
|
|
|
continue
|
2013-09-14 02:43:07 -07:00
|
|
|
open_args = (os.path.join(path, f),)
|
|
|
|
open_kwargs = dict(mode="r")
|
2014-05-16 00:36:50 -07:00
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
open_kwargs["encoding"] = "UTF-8"
|
2013-04-06 04:38:20 -07:00
|
|
|
|
2013-09-14 02:43:07 -07:00
|
|
|
with open(*open_args, **open_kwargs) as header:
|
|
|
|
capi = header.read()
|
2013-04-06 04:38:20 -07:00
|
|
|
|
2014-05-16 04:23:20 -07:00
|
|
|
line_starts = []
|
|
|
|
i = 0
|
|
|
|
header.seek(0)
|
|
|
|
for line in header:
|
|
|
|
line_starts.append(i)
|
|
|
|
i += len(line)
|
2013-09-14 02:43:07 -07:00
|
|
|
matches = re.finditer(capi_pattern, capi)
|
|
|
|
for match in matches:
|
|
|
|
func = match.group(1)
|
2014-05-16 04:23:20 -07:00
|
|
|
start = match.start()
|
|
|
|
line_n = line_starts.index(start) + 1
|
|
|
|
capilns.append((f, line_n))
|
2013-09-14 02:43:07 -07:00
|
|
|
capis.append(func)
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-16 04:23:20 -07:00
|
|
|
return capilns, capis
|
2013-03-06 01:08:15 -08:00
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
|
2013-03-08 08:15:59 -08:00
|
|
|
def get_pyapis(pxd_path, header_name, prefix):
|
2014-05-16 04:23:20 -07:00
|
|
|
pyapilns = []
|
2013-03-08 08:15:59 -08:00
|
|
|
pyapis = []
|
2014-05-16 00:36:50 -07:00
|
|
|
pyapi_pattern1 = re.compile(
|
2014-05-16 04:23:20 -07:00
|
|
|
'cdef extern from "' + header_name + '\.h":\n(.+)',
|
2014-05-16 00:36:50 -07:00
|
|
|
flags=re.S
|
|
|
|
)
|
|
|
|
pyapi_pattern2 = re.compile(
|
|
|
|
"^ +[a-zA-Z _*]+?(?!" + py_excludes + ")(" + prefix + "_\w+)\(",
|
|
|
|
flags=re.M
|
|
|
|
)
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2013-03-08 08:15:59 -08:00
|
|
|
for path, dirs, files in os.walk(pxd_path):
|
|
|
|
for f in files:
|
2014-04-29 02:19:14 -07:00
|
|
|
if not f.endswith(".pxd"):
|
|
|
|
continue
|
|
|
|
open_args = (os.path.join(path, f),)
|
|
|
|
open_kwargs = dict(mode="r")
|
2014-05-16 00:36:50 -07:00
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
open_kwargs["encoding"] = "UTF-8"
|
2014-04-29 02:19:14 -07:00
|
|
|
|
|
|
|
with open(*open_args, **open_kwargs) as pxd:
|
|
|
|
pyapi = pxd.read()
|
|
|
|
cdef = re.search(pyapi_pattern1, pyapi)
|
|
|
|
if cdef:
|
2014-05-16 04:23:20 -07:00
|
|
|
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))
|
2014-04-29 02:19:14 -07:00
|
|
|
for match in matches:
|
|
|
|
func = match.group(1)
|
2014-05-16 04:23:20 -07:00
|
|
|
start = match.start() + offset
|
|
|
|
line_n = line_starts.index(start) + 1
|
|
|
|
pyapilns.append((f, line_n))
|
2014-04-29 02:19:14 -07:00
|
|
|
pyapis.append(func)
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-16 04:23:20 -07:00
|
|
|
return pyapilns, pyapis
|
2013-03-08 08:15:59 -08:00
|
|
|
|
|
|
|
|
2014-05-17 08:26:24 -07:00
|
|
|
rows, columns = os.popen('stty size', 'r').read().split()
|
|
|
|
|
|
|
|
print(
|
|
|
|
"{0:=^{columns}}".format(
|
|
|
|
"Python-EFL API coverage report ", columns=columns
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print("")
|
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
for lib in args.libs:
|
2013-11-05 19:00:49 -08:00
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
inc_paths = pkg_config(lib, EFL_MIN_VERSION)
|
2013-11-05 19:00:49 -08:00
|
|
|
inc_path = None
|
|
|
|
for p in inc_paths:
|
|
|
|
if lib in p:
|
|
|
|
inc_path = p[2:]
|
|
|
|
break
|
|
|
|
|
|
|
|
if inc_path is None:
|
|
|
|
raise SystemExit
|
|
|
|
|
2013-04-07 05:54:37 -07:00
|
|
|
pxd_path, header_name, prefix = params[lib]
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-16 04:23:20 -07:00
|
|
|
c_api_line_ns, c_apis = get_capis(inc_path, prefix)
|
|
|
|
py_api_line_ns, py_apis = get_pyapis(pxd_path, header_name, prefix)
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-16 04:23:20 -07:00
|
|
|
capis = set(c_apis)
|
|
|
|
pyapis = set(py_apis)
|
2013-09-14 02:43:07 -07:00
|
|
|
differences = capis.union(pyapis) - capis.intersection(pyapis)
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-17 08:26:24 -07:00
|
|
|
if args.python:
|
|
|
|
s = " %s API missing from Python-EFL " % (lib.capitalize())
|
|
|
|
print(
|
|
|
|
"{0:-^{columns}}".format(
|
|
|
|
s, columns=int(columns)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for d in sorted(differences):
|
2014-05-16 04:23:20 -07:00
|
|
|
try:
|
|
|
|
i = c_apis.index(d)
|
|
|
|
line_f, line_n = c_api_line_ns[i]
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
else:
|
2014-05-17 08:26:24 -07:00
|
|
|
print("{0:{third}}{1:5}: {2}".format(
|
|
|
|
line_f, line_n, d, third=int(columns)/3
|
2014-05-16 04:23:20 -07:00
|
|
|
))
|
2014-05-17 08:26:24 -07:00
|
|
|
|
|
|
|
print("{0:-<{columns}}".format("", columns=columns))
|
|
|
|
print("")
|
|
|
|
|
|
|
|
if args.c:
|
|
|
|
s = " %s API in Python-EFL but not in C " % (lib.capitalize())
|
|
|
|
print(
|
|
|
|
"{0:-^{columns}}".format(
|
|
|
|
s, columns=int(columns)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for d in sorted(differences):
|
2014-05-16 04:23:20 -07:00
|
|
|
try:
|
|
|
|
i = py_apis.index(d)
|
|
|
|
line_f, line_n = py_api_line_ns[i]
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
else:
|
2014-05-17 08:26:24 -07:00
|
|
|
print("{0:20}{1:5}: {2}".format(
|
2014-05-16 04:23:20 -07:00
|
|
|
line_f, line_n, d
|
|
|
|
))
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-17 08:26:24 -07:00
|
|
|
print("{0:-<{columns}}".format("", columns=columns))
|
|
|
|
print("")
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2013-03-08 10:35:13 -08:00
|
|
|
if args.python:
|
2014-05-16 00:36:50 -07:00
|
|
|
print(
|
|
|
|
"Number of functions missing from Python API: {0}".format(
|
|
|
|
len(capis - capis.intersection(pyapis))
|
|
|
|
)
|
|
|
|
)
|
2013-03-08 10:35:13 -08:00
|
|
|
if args.c:
|
2014-05-16 00:36:50 -07:00
|
|
|
print(
|
|
|
|
"Number of functions missing from C API: {0}".format(
|
|
|
|
len(pyapis - capis.intersection(pyapis))
|
|
|
|
)
|
|
|
|
)
|
2013-03-08 10:35:13 -08:00
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
if args.python or args.c:
|
|
|
|
print("---")
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2013-03-08 10:35:13 -08:00
|
|
|
if args.python:
|
2013-09-14 02:43:07 -07:00
|
|
|
print("Python API functions: {0}".format(len(pyapis)))
|
2013-03-08 10:35:13 -08:00
|
|
|
if args.c:
|
2013-09-14 02:43:07 -07:00
|
|
|
print("C API functions: {0}".format(len(capis)))
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2013-09-14 02:43:07 -07:00
|
|
|
if args.python and len(capis) > 0:
|
2014-05-16 00:36:50 -07:00
|
|
|
percentage = \
|
|
|
|
float(len(capis.intersection(pyapis))) / \
|
|
|
|
float(len(capis)) * 100.0
|
2013-03-08 10:35:13 -08:00
|
|
|
print("===")
|
|
|
|
print("Bindings coverage {0:.2f}%".format(percentage))
|
2013-03-08 16:13:54 -08:00
|
|
|
|
2014-05-16 00:36:50 -07:00
|
|
|
if args.python or args.c:
|
|
|
|
print("---\n")
|