From 0cfaf415f400ae483354709cb82765b9a44ac081 Mon Sep 17 00:00:00 2001 From: Ankit Deepak Date: Thu, 6 Jul 2017 11:49:29 -0700 Subject: [PATCH] bindings: Replace gccxml usage with castxml --- .../ns3modulegen_core_customizations.py | 2 +- bindings/python/ns3modulescan-modular.py | 24 +++++---- bindings/python/ns3modulescan.py | 4 +- bindings/python/wscript | 52 ++++++++++--------- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/bindings/python/ns3modulegen_core_customizations.py b/bindings/python/ns3modulegen_core_customizations.py index fa79960f2..aaf425d16 100644 --- a/bindings/python/ns3modulegen_core_customizations.py +++ b/bindings/python/ns3modulegen_core_customizations.py @@ -71,7 +71,7 @@ class SmartPointerTransformation(typehandlers.TypeTransformation): args = tuple([correct_ctype] + list(args[1:])) handler = type_handler(*args, **kwargs) - handler.set_tranformation(self, orig_ctype) + handler.set_transformation(self, orig_ctype) return handler def untransform(self, type_handler, declarations, code_block, expression): diff --git a/bindings/python/ns3modulescan-modular.py b/bindings/python/ns3modulescan-modular.py index ab1bb9cf7..de4785338 100644 --- a/bindings/python/ns3modulescan-modular.py +++ b/bindings/python/ns3modulescan-modular.py @@ -4,20 +4,21 @@ import sys import os.path import pybindgen.settings -from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection, WrapperWarning, find_declaration_from_name +from pybindgen.castxmlparser import ModuleParser, PygenClassifier, PygenSection, WrapperWarning, find_declaration_from_name from pybindgen.typehandlers.codesink import FileCodeSink from pygccxml.declarations import templates from pygccxml.declarations.enumeration import enumeration_t from pygccxml.declarations.class_declaration import class_t -from pygccxml.declarations.calldef import free_function_t, member_function_t, constructor_t, calldef_t - +from pygccxml.declarations.free_calldef import free_function_t +from pygccxml.declarations.calldef_members import constructor_t, member_function_t +from pygccxml.declarations.calldef import calldef_t ## we need the smart pointer type transformation to be active even -## during gccxml scanning. +## during castxml scanning. import ns3modulegen_core_customizations -## silence gccxmlparser errors; we only want error handling in the +## silence castxmlparser errors; we only want error handling in the ## generated python script, not while scanning. class ErrorHandler(pybindgen.settings.ErrorHandler): def handle_error(self, dummy_wrapper, dummy_exception, dummy_traceback_): @@ -34,6 +35,8 @@ type_annotations = ns3modulescan.type_annotations def get_ns3_relative_path(path): l = [] head = path + if not path: + return while head: new_head, tail = os.path.split(head) if new_head == head: @@ -58,7 +61,8 @@ class PreScanHook: ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name) except ValueError: # the header is not from ns3 return # ignore the definition, it's not ns-3 def. - + if not ns3_header: + return definition_module = self.headers_map[ns3_header] ## Note: we don't include line numbers in the comments because @@ -78,7 +82,7 @@ class PreScanHook: if isinstance(pygccxml_definition, member_function_t) \ and pygccxml_definition.parent.name == 'Object' \ and pygccxml_definition.name == 'GetObject': - template_args = templates.args(pygccxml_definition.demangled_name) + template_args = templates.args(str(pygccxml_definition)) if template_args == ['ns3::Object']: global_annotations['template_instance_names'] = 'ns3::Object=>GetObject' @@ -227,13 +231,13 @@ def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name, cf module_parser.add_pre_scan_hook(PreScanHook(headers_map, module_name)) #module_parser.add_post_scan_hook(post_scan_hook) - gccxml_options = dict( + castxml_options = dict( include_paths=[top_builddir], define_symbols={ #'NS3_ASSERT_ENABLE': None, #'NS3_LOG_ENABLE': None, }, - cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags) + cflags=('-std=c++14 %s' % cflags) ) try: @@ -257,7 +261,7 @@ def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name, cf None, whitelist_paths=[top_builddir], #includes=['"ns3/everything.h"'], pygen_sink=output_sink, - gccxml_options=gccxml_options) + castxml_options=castxml_options) module_parser.scan_types() callback_classes_file = open(os.path.join(os.path.dirname(output_file_name), "callbacks_list.py"), "wt") diff --git a/bindings/python/ns3modulescan.py b/bindings/python/ns3modulescan.py index 36436d399..316267734 100644 --- a/bindings/python/ns3modulescan.py +++ b/bindings/python/ns3modulescan.py @@ -8,7 +8,9 @@ from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection, from pybindgen.typehandlers.codesink import FileCodeSink from pygccxml.declarations import templates from pygccxml.declarations.class_declaration import class_t -from pygccxml.declarations.calldef import free_function_t, member_function_t, constructor_t, calldef_t +from pygccxml.declarations.free_calldef import free_function_t +from pygccxml.declarations.calldef_members import constructor_t, member_function_t +from pygccxml.declarations.calldef import calldef_t ## we need the smart pointer type transformation to be active even diff --git a/bindings/python/wscript b/bindings/python/wscript index a10bee87c..fa9c0f592 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -15,7 +15,8 @@ from waflib.Errors import WafError # https://github.com/gjcarneiro/pybindgen REQUIRED_PYBINDGEN_VERSION = '0.17.0.post58+ngcf00cc0' -REQUIRED_PYGCCXML_VERSION = (0, 9, 5) +REQUIRED_PYGCCXML_VERSION = (1, 9, 0) +REQUIRED_CASTXML_VERSION = '0.1' RUN_ME=-3 @@ -268,7 +269,7 @@ int main () try: conf.check_python_module('pygccxml') except Errors.ConfigurationError: - conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, + conf.report_optional_feature("castxml", "Python API Scanning Support", False, "Missing 'pygccxml' Python module") return @@ -285,40 +286,43 @@ int main () "automatic scanning of API definitions will not be possible" % (pygccxml_version_str, '.'.join([str(x) for x in REQUIRED_PYGCCXML_VERSION]))) - conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, - "pygccxml too old") + conf.report_optional_feature("castxml", "Python API Scanning Support", False, + "pygccxml Python module too old") return - ## Check gccxml version + ## Check castxml version try: - gccxml = conf.find_program('gccxml', var='GCCXML') + castxml = conf.find_program('castxml', var='CASTXML') except WafError: - gccxml = None - if not gccxml: - Logs.warn("gccxml missing; automatic scanning of API definitions will not be possible") - conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, - "gccxml missing") + castxml = None + if not castxml: + Logs.warn("castxml missing; automatic scanning of API definitions will not be possible") + conf.report_optional_feature("castxml", "Python API Scanning Support", False, + "castxml missing") return - gccxml_version_line = os.popen(gccxml[0] + " --version").readline().strip() - m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line) + out = subprocess.Popen([castxml[0], '--version'], + stdout=subprocess.PIPE).communicate()[0] + castxml_version_line = maybe_decode(out).split('\n', 1)[0].strip() + ## Expecting version string such as 'castxml version 0.1-gfab9c47' + m = re.match( "^castxml version (\d\.\d)(-)?(\w+)?", castxml_version_line) try: - gccxml_version = m.group(1) - gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9]) + castxml_version = m.group(1) + castxml_version_ok = castxml_version >= REQUIRED_CASTXML_VERSION except AttributeError: - gccxml_version = gccxml_version_line - gccxml_version_ok = False - conf.msg('Checking for gccxml version', gccxml_version) - if not gccxml_version_ok: - Logs.warn("gccxml version unknown or too old, need version >= 0.9; automatic scanning of API definitions will not be possible") - conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, - "gccxml too old") + castxml_version = castxml_version_line + castxml_version_ok = False + conf.msg('Checking for castxml version', castxml_version) + if not castxml_version_ok: + Logs.warn("castxml version unknown or too old, need version >= %s; automatic scanning of API definitions will not be possible" % REQUIRED_CASTXML_VERSION) + conf.report_optional_feature("castxml", "Python API Scanning Support", False, + "castxml too old") return ## If we reached conf.env['ENABLE_PYTHON_SCANNING'] = True - conf.report_optional_feature("pygccxml", "Python API Scanning Support", True, None) + conf.report_optional_feature("castxml", "Python API Scanning Support", True, None) # --------------------- @@ -342,7 +346,7 @@ def get_module_path(bld, module): return ns3headers.path.abspath() class apiscan_task(Task.Task): - """Uses gccxml to scan the file 'everything.h' and extract API definitions. + """Uses castxml to scan the file 'everything.h' and extract API definitions. """ after = 'gen_ns3_module_header ns3header' before = 'cxx command'