Commit 9818f481 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #324 from StevenPuttemans:fix_matlab_bindings

parents b36d5118 f0121eba
...@@ -101,7 +101,6 @@ string(REGEX REPLACE "(\r?\n)+$" "" GIT_COMMIT "${GIT_COMMIT}") ...@@ -101,7 +101,6 @@ string(REGEX REPLACE "(\r?\n)+$" "" GIT_COMMIT "${GIT_COMMIT}")
# set the path to the C++ header and doc parser, and template engine # set the path to the C++ header and doc parser, and template engine
set(JINJA2_PATH ${CMAKE_SOURCE_DIR}/3rdparty) set(JINJA2_PATH ${CMAKE_SOURCE_DIR}/3rdparty)
set(HDR_PARSER_PATH ${CMAKE_SOURCE_DIR}/modules/python/src2) set(HDR_PARSER_PATH ${CMAKE_SOURCE_DIR}/modules/python/src2)
set(RST_PARSER_PATH ${CMAKE_SOURCE_DIR}/modules/java/generator)
# set mex compiler options # set mex compiler options
prepend("-I" MEX_INCLUDE_DIRS ${CMAKE_BINARY_DIR}) prepend("-I" MEX_INCLUDE_DIRS ${CMAKE_BINARY_DIR})
...@@ -158,7 +157,6 @@ if (NOT MEX_WORKS) ...@@ -158,7 +157,6 @@ if (NOT MEX_WORKS)
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py
--jinja2 ${JINJA2_PATH} --jinja2 ${JINJA2_PATH}
--hdrparser ${HDR_PARSER_PATH} --hdrparser ${HDR_PARSER_PATH}
--rstparser ${RST_PARSER_PATH}
--extra "test=${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp" --extra "test=${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp"
--outdir ${CMAKE_BINARY_DIR}/junk --outdir ${CMAKE_BINARY_DIR}/junk
ERROR_VARIABLE GEN_ERROR ERROR_VARIABLE GEN_ERROR
...@@ -218,7 +216,6 @@ add_custom_command( ...@@ -218,7 +216,6 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py
--jinja2 ${JINJA2_PATH} --jinja2 ${JINJA2_PATH}
--hdrparser ${HDR_PARSER_PATH} --hdrparser ${HDR_PARSER_PATH}
--rstparser ${RST_PARSER_PATH}
--moduleroot ${CMAKE_SOURCE_DIR}/modules ${OPENCV_EXTRA_MODULES_PATH} --moduleroot ${CMAKE_SOURCE_DIR}/modules ${OPENCV_EXTRA_MODULES_PATH}
--modules ${opencv_modules} --modules ${opencv_modules}
--extra ${opencv_extra_hdrs} --extra ${opencv_extra_hdrs}
......
...@@ -29,19 +29,12 @@ class MatlabWrapperGenerator(object): ...@@ -29,19 +29,12 @@ class MatlabWrapperGenerator(object):
# dynamically import the parsers # dynamically import the parsers
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
import hdr_parser import hdr_parser
import rst_parser
# parse each of the files and store in a dictionary # parse each of the files and store in a dictionary
# as a separate "namespace" # as a separate "namespace"
parser = hdr_parser.CppHeaderParser() parser = hdr_parser.CppHeaderParser()
rst = rst_parser.RstParser(parser)
rst_parser.verbose = False
rst_parser.show_warnings = False
rst_parser.show_errors = False
rst_parser.show_critical_errors = False
ns = dict((key, []) for key in modules) ns = dict((key, []) for key in modules)
doc = dict((key, []) for key in modules)
path_template = Template('${module}/include/opencv2/${module}.hpp') path_template = Template('${module}/include/opencv2/${module}.hpp')
for module in modules: for module in modules:
...@@ -55,10 +48,6 @@ class MatlabWrapperGenerator(object): ...@@ -55,10 +48,6 @@ class MatlabWrapperGenerator(object):
# parse the definitions # parse the definitions
ns[module] = parser.parse(header) ns[module] = parser.parse(header)
# parse the documentation
rst.parse(module, os.path.join(module_root, module))
doc[module] = rst.definitions
rst.definitions = {}
for extra in extras: for extra in extras:
module = extra.split("=")[0] module = extra.split("=")[0]
...@@ -97,7 +86,6 @@ class MatlabWrapperGenerator(object): ...@@ -97,7 +86,6 @@ class MatlabWrapperGenerator(object):
tfunction = jtemplate.get_template('template_function_base.cpp') tfunction = jtemplate.get_template('template_function_base.cpp')
tclassm = jtemplate.get_template('template_class_base.m') tclassm = jtemplate.get_template('template_class_base.m')
tclassc = jtemplate.get_template('template_class_base.cpp') tclassc = jtemplate.get_template('template_class_base.cpp')
tdoc = jtemplate.get_template('template_doc_base.m')
tconst = jtemplate.get_template('template_map_base.m') tconst = jtemplate.get_template('template_map_base.m')
# create the build directory # create the build directory
...@@ -121,10 +109,6 @@ class MatlabWrapperGenerator(object): ...@@ -121,10 +109,6 @@ class MatlabWrapperGenerator(object):
populated = tfunction.render(fun=method, time=time, includes=namespace.name) populated = tfunction.render(fun=method, time=time, includes=namespace.name)
with open(output_source_dir+'/'+method.name+'.cpp', 'wb') as f: with open(output_source_dir+'/'+method.name+'.cpp', 'wb') as f:
f.write(populated.encode('utf-8')) f.write(populated.encode('utf-8'))
if namespace.name in doc and method.name in doc[namespace.name]:
populated = tdoc.render(fun=method, doc=doc[namespace.name][method.name], time=time)
with open(output_class_dir+'/'+method.name+'.m', 'wb') as f:
f.write(populated.encode('utf-8'))
# classes # classes
for clss in namespace.classes: for clss in namespace.classes:
# cpp converter # cpp converter
...@@ -147,7 +131,6 @@ if __name__ == "__main__": ...@@ -147,7 +131,6 @@ if __name__ == "__main__":
""" """
Usage: python gen_matlab.py --jinja2 /path/to/jinja2/engine Usage: python gen_matlab.py --jinja2 /path/to/jinja2/engine
--hdrparser /path/to/hdr_parser/dir --hdrparser /path/to/hdr_parser/dir
--rstparser /path/to/rst_parser/dir
--moduleroot [ /path/to/opencv/modules /path/to/opencv_contrib/modules etc ] --moduleroot [ /path/to/opencv/modules /path/to/opencv_contrib/modules etc ]
--modules [core imgproc objdetect etc] --modules [core imgproc objdetect etc]
--extra namespace=/path/to/extra/header.hpp --extra namespace=/path/to/extra/header.hpp
...@@ -158,8 +141,7 @@ if __name__ == "__main__": ...@@ -158,8 +141,7 @@ if __name__ == "__main__":
1. constructs the headers to parse from the module root and list of modules 1. constructs the headers to parse from the module root and list of modules
2. parses the headers using CppHeaderParser 2. parses the headers using CppHeaderParser
3. refactors the definitions using ParseTree 3. refactors the definitions using ParseTree
4. parses .rst docs using RstParser 4. populates the templates for classes, function, enums from the
5. populates the templates for classes, function, enums and docs from the
definitions definitions
gen_matlab.py requires the following inputs: gen_matlab.py requires the following inputs:
...@@ -167,8 +149,6 @@ if __name__ == "__main__": ...@@ -167,8 +149,6 @@ if __name__ == "__main__":
e.g. ${CMAKE_SOURCE_DIR}/3rdparty e.g. ${CMAKE_SOURCE_DIR}/3rdparty
--hdrparser the path to the header parser directory --hdrparser the path to the header parser directory
(opencv/modules/python/src2) (opencv/modules/python/src2)
--rstparser the path to the rst parser directory
(opencv/modules/java/generator)
--moduleroot (optional) paths to the opencv directories containing the modules --moduleroot (optional) paths to the opencv directories containing the modules
--modules (optional - required if --moduleroot specified) the modules --modules (optional - required if --moduleroot specified) the modules
to produce bindings for. The path to the include directories to produce bindings for. The path to the include directories
...@@ -187,17 +167,15 @@ if __name__ == "__main__": ...@@ -187,17 +167,15 @@ if __name__ == "__main__":
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('--jinja2') parser.add_argument('--jinja2')
parser.add_argument('--hdrparser') parser.add_argument('--hdrparser')
parser.add_argument('--rstparser')
parser.add_argument('--moduleroot', nargs='*', default=[], required=False) parser.add_argument('--moduleroot', nargs='*', default=[], required=False)
parser.add_argument('--modules', nargs='*', default=[], required=False) parser.add_argument('--modules', nargs='*', default=[], required=False)
parser.add_argument('--extra', nargs='*', default=[], required=False) parser.add_argument('--extra', nargs='*', default=[], required=False)
parser.add_argument('--outdir') parser.add_argument('--outdir')
args = parser.parse_args() args = parser.parse_args()
# add the hdr_parser and rst_parser modules to the path # add the hdr_parser module to the path
sys.path.append(args.jinja2) sys.path.append(args.jinja2)
sys.path.append(args.hdrparser) sys.path.append(args.hdrparser)
sys.path.append(args.rstparser)
# create the generator # create the generator
mwg = MatlabWrapperGenerator() mwg = MatlabWrapperGenerator()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment