1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #25986 from asmorkalov:as/js_for_contrib

Split Javascript white-list to support contrib modules #25986

Single whitelist converted to several per-module json files. They are concatenated automatically and can be overriden by user config.

Related to https://github.com/opencv/opencv/pull/25656

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Alexander Smorkalov
2024-08-23 10:49:08 +03:00
committed by GitHub
parent 697512bb9f
commit 6c6d5cd7b2
11 changed files with 295 additions and 12 deletions
+14 -1
View File
@@ -38,8 +38,21 @@ set(scripts_hdr_parser "${JS_SOURCE_DIR}/../python/src2/hdr_parser.py")
if(DEFINED ENV{OPENCV_JS_WHITELIST})
set(OPENCV_JS_WHITELIST_FILE "$ENV{OPENCV_JS_WHITELIST}")
message(STATUS "Use white list from environment ${OPENCV_JS_WHITELIST_FILE}")
else()
set(OPENCV_JS_WHITELIST_FILE "${OpenCV_SOURCE_DIR}/platforms/js/opencv_js.config.py")
#generate white list from modules/<module_name>/misc/js/whitelist.json
set(OPENCV_JS_WHITELIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/whitelist.json")
foreach(m in ${OPENCV_JS_MODULES})
set(js_whitelist "${OPENCV_MODULE_${m}_LOCATION}/misc/js/gen_dict.json")
if (EXISTS "${js_whitelist}")
file(READ "${js_whitelist}" whitelist_content)
list(APPEND OPENCV_JS_WHITELIST_CONTENT "\"${m}\": ${whitelist_content}")
endif()
endforeach(m)
string(REPLACE ";" ", \n" OPENCV_JS_WHITELIST_CONTENT_STRING "${OPENCV_JS_WHITELIST_CONTENT}")
set(OPENCV_JS_WHITELIST_CONTENT_STRING "{\n${OPENCV_JS_WHITELIST_CONTENT_STRING}}\n")
ocv_update_file("${OPENCV_JS_WHITELIST_FILE}" "${OPENCV_JS_WHITELIST_CONTENT_STRING}")
message(STATUS "Use autogenerated whitelist ${OPENCV_JS_WHITELIST_FILE}")
endif()
add_custom_command(
+46 -8
View File
@@ -76,6 +76,7 @@ if sys.version_info[0] >= 3:
else:
from cStringIO import StringIO
import json
func_table = {}
@@ -103,11 +104,32 @@ def makeWhiteList(module_list):
wl[k] = m[k]
return wl
def makeWhiteListJson(module_list):
wl = {}
for n, gen_dict in module_list.items():
m = gen_dict["whitelist"]
for k in m.keys():
if k in wl:
wl[k] += m[k]
else:
wl[k] = m[k]
return wl
def makeNamespacePrefixOverride(module_list):
wl = {}
for n, gen_dict in module_list.items():
if "namespace_prefix_override" in gen_dict:
m = gen_dict["namespace_prefix_override"]
for k in m.keys():
if k in wl:
wl[k] += m[k]
else:
wl[k] = m[k]
return wl
white_list = None
namespace_prefix_override = {
'dnn' : '',
'aruco' : '',
}
namespace_prefix_override = None
# Features to be exported
export_enums = False
@@ -834,6 +856,7 @@ class JSWrapperGenerator(object):
if method.cname in ignore_list:
continue
if not method.name in white_list[method.class_name]:
#print('Not in whitelist: "{}"'.format(method.name))
continue
if method.is_constructor:
for variant in method.variants:
@@ -938,9 +961,9 @@ if __name__ == "__main__":
if len(sys.argv) < 5:
print("Usage:\n", \
os.path.basename(sys.argv[0]), \
"<full path to hdr_parser.py> <bindings.cpp> <headers.txt> <core_bindings.cpp> <opencv_js.config.py>")
"<full path to hdr_parser.py> <bindings.cpp> <headers.txt> <core_bindings.cpp> <whitelist.json or opencv_js.config.py>")
print("Current args are: ", ", ".join(["'"+a+"'" for a in sys.argv]))
exit(0)
exit(1)
dstdir = "."
hdr_parser_path = os.path.abspath(sys.argv[1])
@@ -953,8 +976,23 @@ if __name__ == "__main__":
headers = open(sys.argv[3], 'r').read().split(';')
coreBindings = sys.argv[4]
whiteListFile = sys.argv[5]
exec(open(whiteListFile).read())
assert(white_list)
if whiteListFile.endswith(".json") or whiteListFile.endswith(".JSON"):
with open(whiteListFile) as f:
gen_dict = json.load(f)
f.close()
white_list = makeWhiteListJson(gen_dict)
namespace_prefix_override = makeNamespacePrefixOverride(gen_dict)
elif whiteListFile.endswith(".py") or whiteListFile.endswith(".PY"):
exec(open(whiteListFile).read())
assert(white_list)
namespace_prefix_override = {
'dnn' : '',
'aruco' : '',
}
else:
print("Unexpected format of OpenCV config file", whiteListFile)
exit(1)
generator = JSWrapperGenerator()
generator.gen(bindingsCpp, headers, coreBindings)