diff options
Diffstat (limited to 'gr-utils/bindtool/scripts')
-rw-r--r-- | gr-utils/bindtool/scripts/bind_from_json.py | 15 | ||||
-rw-r--r-- | gr-utils/bindtool/scripts/bind_gr_module.py | 60 | ||||
-rw-r--r-- | gr-utils/bindtool/scripts/bind_intree_file.py | 58 | ||||
-rw-r--r-- | gr-utils/bindtool/scripts/header_utils.py | 86 |
4 files changed, 219 insertions, 0 deletions
diff --git a/gr-utils/bindtool/scripts/bind_from_json.py b/gr-utils/bindtool/scripts/bind_from_json.py new file mode 100644 index 0000000000..863b40f5b4 --- /dev/null +++ b/gr-utils/bindtool/scripts/bind_from_json.py @@ -0,0 +1,15 @@ +import argparse +import os +from gnuradio.bindtool import BindingGenerator +import pathlib + +parser = argparse.ArgumentParser(description='Bind a GR header file from the generated json') +parser.add_argument('pathnames', type=str, nargs='+', + help='Json files to bind') + +args = parser.parse_args() + +bg = BindingGenerator() + +for p in args.pathnames: + bg.bind_from_json(p)
\ No newline at end of file diff --git a/gr-utils/bindtool/scripts/bind_gr_module.py b/gr-utils/bindtool/scripts/bind_gr_module.py new file mode 100644 index 0000000000..271ce62765 --- /dev/null +++ b/gr-utils/bindtool/scripts/bind_gr_module.py @@ -0,0 +1,60 @@ +import argparse +import os +from gnuradio.bindtool import BindingGenerator +import pathlib + +parser = argparse.ArgumentParser(description='Bind a GR In-Tree Module') +parser.add_argument('names', type=str, nargs='+', + help='Names of gr modules to bind (e.g. fft digital analog)') + +parser.add_argument('--output_dir', default='/tmp', + help='Output directory of generated bindings') +parser.add_argument('--prefix', help='Prefix of Installed GNU Radio') +parser.add_argument('--src', help='Directory of gnuradio source tree', + default=os.path.dirname(os.path.abspath(__file__))+'/../../..') +parser.add_argument( + '--include', help='Additional Include Dirs, comma separated', default='') +args = parser.parse_args() + +# NOTES: +# To generate QTGUI requires adding the QT headers as --include, e.g. +# bind_gr_module.py --prefix /share/gnuradio/grpybind --output_dir /share/tmp/take5 +# --include /usr/include/x86_64-linux-gnu/qt5/QtGui,/usr/include/x86_64-linux-gnu/qt5, +# /usr/include/x86_64-linux-gnu/qt5/QtCore,/usr/include/x86_64-linux-gnu/qt5/QtWidgets,/usr/include/qwt qtgui + +# To generate UHD requires adding the UHD headers, e.g. +# python3 /share/gnuradio/grpybind/src/gnuradio/gr-utils/python/bindtool/scripts/bind_gr_module.py +# --prefix /share/gnuradio/grpybind +# --include $UHD_PATH,$UHD_PATH/utils,$UHD_PATH/types,$UHD_PATH/transport,$UHD_PATH/usrp_clock,$UHD_PATH/rfnoc +# --output_dir /share/tmp/take5 uhd + + +print(pathlib.Path(__file__).parent.absolute()) +print(args) + +prefix = args.prefix +output_dir = args.output_dir +includes = args.include +for name in args.names: + if name not in ['gr', 'pmt']: + namespace = ['gr', name.replace("-","_")] + module_dir = os.path.abspath( + os.path.join(args.src, 'gr-'+name, 'include')) + prefix_include_root = 'gnuradio/'+name # pmt, gnuradio/digital, etc. + else: + namespace = [name] + module_dir = os.path.abspath(os.path.join( + args.src, 'gnuradio-runtime', 'include')) + if name == 'gr': + prefix_include_root = 'gnuradio' + module_dir = os.path.join(module_dir, 'gnuradio') + elif name == 'pmt': + prefix_include_root = 'pmt' + module_dir = os.path.join(module_dir, 'pmt') + + import warnings + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + bg = BindingGenerator(prefix, namespace, prefix_include_root, + output_dir, addl_includes=includes, match_include_structure=True, write_json_output=True) + bg.gen_bindings(module_dir) diff --git a/gr-utils/bindtool/scripts/bind_intree_file.py b/gr-utils/bindtool/scripts/bind_intree_file.py new file mode 100644 index 0000000000..79a9c3da1a --- /dev/null +++ b/gr-utils/bindtool/scripts/bind_intree_file.py @@ -0,0 +1,58 @@ +import warnings +import argparse +import os +from gnuradio.bindtool import BindingGenerator +import pathlib +import sys + +parser = argparse.ArgumentParser(description='Bind a GR In-Tree Module') +parser.add_argument('--module', type=str, + help='Name of gr module containing file to bind (e.g. fft digital analog)') + +parser.add_argument('--output_dir', default='/tmp', + help='Output directory of generated bindings') +parser.add_argument('--prefix', help='Prefix of Installed GNU Radio') +parser.add_argument('--src', help='Directory of gnuradio source tree', + default=os.path.dirname(os.path.abspath(__file__))+'/../../..') + +parser.add_argument( + '--filename', help="File to be parsed") + +parser.add_argument( + '--include', help='Additional Include Dirs, separated', default=(), nargs='+') + +parser.add_argument( + '--status', help='Location of output file for general status (used during cmake)', default=None +) +parser.add_argument( + '--flag_automatic', default='0' +) +parser.add_argument( + '--flag_pygccxml', default='0' +) + +args = parser.parse_args() + +prefix = args.prefix +output_dir = args.output_dir +includes = args.include +name = args.module + +if name not in ['gr', 'pmt']: + namespace = ['gr', name] + prefix_include_root = 'gnuradio/'+name # pmt, gnuradio/digital, etc. +else: + namespace = [name] + if name == 'gr': + prefix_include_root = 'gnuradio' + elif name == 'pmt': + prefix_include_root = 'pmt' + +with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + + bg = BindingGenerator(args.prefix, namespace, + prefix_include_root, output_dir, addl_includes=','.join(args.include), catch_exceptions=False, write_json_output=False, status_output=args.status, + flag_automatic=True if args.flag_automatic.lower() in ['1','true'] else False, + flag_pygccxml=True if args.flag_pygccxml.lower() in ['1','true'] else False) + bg.gen_file_binding(args.filename) diff --git a/gr-utils/bindtool/scripts/header_utils.py b/gr-utils/bindtool/scripts/header_utils.py new file mode 100644 index 0000000000..4071f6fa86 --- /dev/null +++ b/gr-utils/bindtool/scripts/header_utils.py @@ -0,0 +1,86 @@ +# Utilities for reading values in header files + +from argparse import ArgumentParser +import re + + +class PybindHeaderParser: + def __init__(self, pathname): + try: + with open(pathname,'r') as f: + self.file_txt = f.read() + except: + self.file_txt = "" + + def get_flag_automatic(self): + try: + m = re.search(r'BINDTOOL_GEN_AUTOMATIC\(([^\s])\)', self.file_txt) + if (m and m.group(1) == '1'): + return True + else: + return False + except: + return False + + def get_flag_pygccxml(self): + try: + m = re.search(r'BINDTOOL_USE_PYGCCXML\(([^\s])\)', self.file_txt) + if (m and m.group(1) == '1'): + return True + else: + return False + except: + return False + + def get_header_filename(self): + try: + m = re.search(r'BINDTOOL_HEADER_FILE\(([^\s]*)\)', self.file_txt) + if (m): + return m.group(1) + else: + return None + except: + return None + + + def get_header_file_hash(self): + try: + m = re.search(r'BINDTOOL_HEADER_FILE_HASH\(([^\s]*)\)', self.file_txt) + if (m): + return m.group(1) + else: + return None + except: + return None + + def get_flags(self): + return f'{self.get_flag_automatic()};{self.get_flag_pygccxml()};{self.get_header_filename()};{self.get_header_file_hash()};' + + + +def argParse(): + """Parses commandline args.""" + desc='Reads the parameters from the comment block in the pybind files' + parser = ArgumentParser(description=desc) + + parser.add_argument("function", help="Operation to perform on comment block of pybind file", choices=["flag_auto","flag_pygccxml","header_filename","header_file_hash","all"]) + parser.add_argument("pathname", help="Pathname of pybind c++ file to read, e.g. blockname_python.cc") + + return parser.parse_args() + +if __name__ == "__main__": + # Parse command line options and set up doxyxml. + args = argParse() + + pbhp = PybindHeaderParser(args.pathname) + + if args.function == "flag_auto": + print(pbhp.get_flag_automatic()) + elif args.function == "flag_pygccxml": + print(pbhp.get_flag_pygccxml()) + elif args.function == "header_filename": + print(pbhp.get_header_filename()) + elif args.function == "header_file_hash": + print(pbhp.get_header_file_hash()) + elif args.function == "all": + print(pbhp.get_flags())
\ No newline at end of file |