4 from optparse import OptionParser
6 # Text file containing list of EWK APIs
7 filepath = 'API_LIST.txt'
12 # ewk_interface_main.cc defines few APIs (like ewk_init, ewk_shutdown etc.) to setup
13 # and preinitialize dl library parameters. Those APIs are excluded from auto-generated
14 # code to avoid duplicate symbols.
15 exclude_list = ["ewk_init", "ewk_shutdown", "ewk_set_version_policy", "ewk_wait_chromium_ready", "ewk_check_chromium_ready"]
17 # Few ewk headers are directly included in impl, so they are
19 main_headers_list = ["ewk_interface_main.h", "dlog_util.h"]
20 headers_list = ["ewk_cookie_parser.h", "ewk_media_playback_info_product.h", "ewk_media_subtitle_info_product.h"]
21 headers_list_inc = ["EWebKit.h", "EWebKit_internal.h", "EWebKit_product.h", "dlfcn.h"]
23 basepath = os.path.dirname(os.path.realpath(__file__))
24 path = basepath + "/../ewk/efl_integration/public/ewk*.h"
26 files = glob.glob(path)
27 with open(filepath, 'w') as outfile:
29 if (file.find("ewk_export.h") != -1):
36 # Extract lines containing EXPORT_API
38 with open(filepath, 'r') as f:
40 if (line.find('EXPORT_API') == -1):
43 api_line = api_line + line.strip()
44 while (api_line.find(");") == -1):
45 if sys.version_info < (3, 0):
46 api_line = api_line + " " + f.next().strip()
48 api_line = api_line + " " + f.readline().strip()
50 # Special case for ewk_view_hit_test_request, because one of its args does not have name
51 if (api_line.find("Ewk_View_Hit_Test_Request_Callback") != -1):
52 api_line = api_line.replace("Callback", "Callback callback")
54 # Special case for ewk_context_background_music_set to avoid duplicate
55 if (api_line.find("ewk_context_background_music_set") != -1):
56 api_line = api_line.replace("Ewk_Context *ewkContext", "Ewk_Context* context")
58 API_LIST.append(api_line)
61 # Parse function declarations extracted in API_LIST.txt
63 start = line.find('EXPORT_API')
64 line = line[start + len('EXPORT_API') + 1:]
66 # Parse to extract return type, api name and params
67 split_api_params = line.split("(")
68 api_name = split_api_params[0]
69 index = api_name.rfind(' ')
70 RETURN_TYPE = api_name[:index]
71 api_name = api_name[index+1:]
72 if api_name[0] == '*':
73 API_NAME = api_name[1:]
74 RETURN_TYPE = RETURN_TYPE + '*'
78 # Since ewk_init and ewk_shutdown have manually written code, exclude them here
80 for api in exclude_list:
87 # Generate params list from params string
88 params = split_api_params[1]
89 index = params.rfind(');')
90 PARAMS = params[:index]
91 params_list = PARAMS.split(",")
93 # Trim '*' char from param name and append it to return type
107 # Generate definition code by concatinating string peices and related macro
108 func_def = RETURN_TYPE + " " + API_NAME + "(" + PARAMS + ")\n{\n\t"
109 func_ptr_decl = "typedef " + RETURN_TYPE + " (*func_ptr_t)(" + PARAMS + ");"
111 func_def = func_def + func_ptr_decl + "\n\t"
112 func_def = func_def + "DL_FUNCTION("
113 func_def = func_def + RETURN_TYPE + ", " + API_NAME
115 if len(params_list) > 0:
116 for x in params_list:
117 func_def = func_def + ', ' + x
119 func_def = func_def + ");\n}\n"
120 FUNC_DEFI.append(func_def)
122 # There might duplicate entries because of inclusion of both public and internal APIs,
123 # so make the list unique by creating a set
124 FUNC_DEFI = list(set(FUNC_DEFI))
127 parser = OptionParser()
128 parser.add_option('--out-cpp', dest='out_cpp')
129 (options, args) = parser.parse_args()
130 output_file = options.out_cpp
132 # Include required headers
133 text_file = open(output_file, "w")
135 for header_file in headers_list_inc:
136 str = "#include <" + header_file + ">\n"
138 text_file.write("\n")
140 # Include main headers
141 for header_file in main_headers_list:
142 str = "#include \"" + header_file + "\"\n"
145 # Include other ewk headers by checking file existance
146 header_path = basepath + "/../ewk/efl_integration/public/"
147 for header_file in headers_list:
148 print(header_path + header_file)
149 if os.path.isfile(header_path + header_file):
150 str = "#include \"" + header_file + "\"\n"
154 #define DL_FUNCTION(return_type, func_name, ...) \\
156 if (!g_impl_lib_handle && !open_library()) \\
157 return static_cast<return_type>(0); \\
159 reinterpret_cast<func_ptr_t>(dlsym(g_impl_lib_handle, #func_name)); \\
161 return fp(__VA_ARGS__); \\
162 return static_cast<return_type>(0); \\
166 text_file.write(DL_MACRO + "\n")
167 text_file.write("using namespace ewk_interface;\n\n")
169 # Write funtion definition to output file
171 text_file.write(x + '\n')