Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
This commit is contained in:
@@ -44,7 +44,7 @@ class MyMultiSectionFactory(MultiSectionFactory):
|
||||
|
||||
|
||||
def main(argv):
|
||||
module_abs_src_path, target, output_cc_file_name = argv[1:]
|
||||
module_abs_src_path, target, extension_name, output_cc_file_name = argv[1:]
|
||||
module_name = os.path.basename(module_abs_src_path)
|
||||
out = MyMultiSectionFactory(output_cc_file_name)
|
||||
|
||||
@@ -70,6 +70,7 @@ def main(argv):
|
||||
sys.path.pop(0)
|
||||
|
||||
root_module = module_apidefs.module_init()
|
||||
root_module.set_name(extension_name)
|
||||
root_module.add_include('"ns3/%s-module.h"' % module_name)
|
||||
|
||||
# -----------
|
||||
|
||||
@@ -15,7 +15,7 @@ import Build
|
||||
import Utils
|
||||
|
||||
## https://launchpad.net/pybindgen/
|
||||
REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 777)
|
||||
REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 779)
|
||||
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
|
||||
|
||||
|
||||
|
||||
18
src/wscript
18
src/wscript
@@ -199,6 +199,19 @@ def ns3_python_bindings(bld):
|
||||
if bld.path.find_resource("bindings/modulegen_local.py"):
|
||||
source.append("bindings/modulegen_local.py")
|
||||
|
||||
module_py_name = module.replace('-', '_')
|
||||
module_target_dir = bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path)
|
||||
|
||||
# if bindings/<module>.py exists, it becomes the module frontend, and the C extension befomes _<module>
|
||||
if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
|
||||
bld.new_task_gen(
|
||||
features='copy',
|
||||
source=("bindings/%s.py" % (module_py_name,)),
|
||||
target=('%s/%s.py' % (module_target_dir, module_py_name)))
|
||||
extension_name = '_%s' % (module_py_name,)
|
||||
else:
|
||||
extension_name = module_py_name
|
||||
|
||||
target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
|
||||
#if not debug:
|
||||
# target.append('ns3modulegen.log')
|
||||
@@ -207,7 +220,7 @@ def ns3_python_bindings(bld):
|
||||
#if debug:
|
||||
# argv.extend(["-m", "pdb"])
|
||||
|
||||
argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, '${TGT[0]}'])
|
||||
argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}'])
|
||||
|
||||
argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
|
||||
|
||||
@@ -223,9 +236,10 @@ def ns3_python_bindings(bld):
|
||||
bindgen.after = 'gen_ns3_module_header_task'
|
||||
bindgen.name = "pybindgen(ns3 module %s)" % module
|
||||
|
||||
# generate the extension module
|
||||
pymod = bld.new_task_gen(features='cxx cshlib pyext')
|
||||
pymod.source = ['bindings/ns3module.cc']
|
||||
pymod.target = '%s/%s' % (bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path), module.replace('-', '_'))
|
||||
pymod.target = '%s/%s' % (module_target_dir, extension_name)
|
||||
pymod.name = 'ns3module_%s' % module
|
||||
pymod.uselib_local = "ns3-"+module
|
||||
if pymod.env['ENABLE_STATIC_NS3']:
|
||||
|
||||
Reference in New Issue
Block a user