diff options
author | Julien Cabieces <julien.cabieces@oslandia.com> | 2019-04-03 10:46:21 +0200 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2019-07-10 17:20:17 +0300 |
commit | 4f287a8a7f1c72a04952c39ab2a4b8ae9f98b648 (patch) | |
tree | 94b429c719f301ce93c086091fb7afb8154844a1 | |
parent | 8b116b291e2a9c205690482f542126da67ba7306 (diff) |
Add a script to generate valid Qt mappings file
-rwxr-xr-x | generate_qt_mappings.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/generate_qt_mappings.py b/generate_qt_mappings.py new file mode 100755 index 0000000..5dbcd47 --- /dev/null +++ b/generate_qt_mappings.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +This script generates the Qt mapping file according to given Qt include +directory + +Example usage : + + $ ./generate_qt_mappings.py /usr/include/x86_64-linux-gnu/qt5 qt5_11.imp + +""" + +from __future__ import print_function +import argparse +import glob +import os +import re +import sys + + +def main(qt_include_dir, output_file): + symbols_map = [] + includes_map = [] + + headers = glob.glob(os.path.join(args.qt_include_dir, '**/*[!.h]')) + for header in headers: + if os.path.isdir(header): + continue + + class_name = os.path.basename(header) + module_name = os.path.basename(os.path.dirname(header)) + + symbols_map += ['{ symbol: [ "%s", "private", ' % class_name + + '"<%s>", "public" ] }' % class_name] + + with open(header, 'r') as f: + content = f.read() + + includes = re.findall(r'#include "(.*)\.h"', content) + for include in includes: + includes_map += [ + '{ include: [ "@[\\"<](%s/)?%s\\\\.h[\\">]", ' % ( + module_name, include) + + '"private", "<%s>", "public" ] }' % class_name] + + with open(args.output_file, 'w') as f: + print("# Do not edit! This file was generated by the script %s." % + os.path.basename(__file__), file=f) + print("[", file=f) + print(" %s" % ",\n ".join(symbols_map + includes_map), file=f) + print("]", file=f) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("qt_include_dir", help="Qt include directoy") + parser.add_argument("output_file", help="Generated output mapping file") + args = parser.parse_args() + sys.exit(main(args.qt_include_dir, args.output_file)) |