| 1 |
|
| 2 |
from __future__ import unicode_literals, print_function |
| 3 |
|
| 4 |
import sys |
| 5 |
import os.path |
| 6 |
|
| 7 |
import pybindgen |
| 8 |
from pybindgen.typehandlers import base as typehandlers |
| 9 |
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink) |
| 10 |
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum) |
| 11 |
from pybindgen.function import CustomFunctionWrapper |
| 12 |
from pybindgen.cppmethod import CustomCppMethodWrapper |
| 13 |
|
| 14 |
import foomodulegen_common |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
def my_module_gen(): |
| 20 |
if sys.argv[6] == 'castxml': |
| 21 |
from pybindgen.castxmlparser import ModuleParser, PygenClassifier, PygenSection |
| 22 |
else: |
| 23 |
from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection |
| 24 |
|
| 25 |
class MyPygenClassifier(PygenClassifier): |
| 26 |
def classify(self, pygccxml_definition): |
| 27 |
if pygccxml_definition.name and pygccxml_definition.name.lower() <= 'l': |
| 28 |
return 'foomodulegen_module1' |
| 29 |
else: |
| 30 |
return 'foomodulegen_module2' |
| 31 |
|
| 32 |
pygen = [ |
| 33 |
PygenSection('__main__', FileCodeSink(open(sys.argv[3], "wt"))), |
| 34 |
PygenSection('foomodulegen_module1', FileCodeSink(open(sys.argv[4], "wt")), |
| 35 |
'foomodulegen_module1_local'), |
| 36 |
PygenSection('foomodulegen_module2', FileCodeSink(open(sys.argv[5], "wt")), |
| 37 |
'foomodulegen_module2_local'), |
| 38 |
] |
| 39 |
module_parser = ModuleParser('foo4', '::') |
| 40 |
module_parser.enable_anonymous_containers = True |
| 41 |
|
| 42 |
gccxml_options = dict( |
| 43 |
include_paths=eval(sys.argv[2]), |
| 44 |
) |
| 45 |
|
| 46 |
module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=pygen, pygen_classifier=MyPygenClassifier(), |
| 47 |
gccxml_options=gccxml_options) |
| 48 |
module = module_parser.module |
| 49 |
foomodulegen_common.customize_module_pre(module) |
| 50 |
module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') |
| 51 |
module_parser.scan_types() |
| 52 |
module_parser.scan_methods() |
| 53 |
module_parser.scan_functions() |
| 54 |
module_parser.parse_finalize() |
| 55 |
|
| 56 |
for sect in pygen: |
| 57 |
sect.code_sink.file.close() |
| 58 |
|
| 59 |
|
| 60 |
if __name__ == '__main__': |
| 61 |
import os |
| 62 |
if "PYBINDGEN_ENABLE_PROFILING" in os.environ: |
| 63 |
try: |
| 64 |
import cProfile as profile |
| 65 |
except ImportError: |
| 66 |
my_module_gen() |
| 67 |
else: |
| 68 |
print("** running under profiler", file=sys.stderr) |
| 69 |
profile.run('my_module_gen()', 'foomodulegen-auto-split.pstat') |
| 70 |
else: |
| 71 |
my_module_gen() |
| 72 |
|