summaryrefslogtreecommitdiff
path: root/misc/update-vulkan-gir.py
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2019-05-03 15:37:46 +1000
committerMatthew Waters <matthew@centricular.com>2019-06-03 22:22:39 +1000
commit2d87a1e2522629e15a26093e970246b66237ddfd (patch)
treed01eeb411f9849cf3e188a0301b61c29e9772fce /misc/update-vulkan-gir.py
parentdac89688b7f2c4caf466772125f6a00a668600bd (diff)
downloadgobject-introspection-2d87a1e2522629e15a26093e970246b66237ddfd.tar.gz
Add Vulkan gir
Diffstat (limited to 'misc/update-vulkan-gir.py')
-rw-r--r--misc/update-vulkan-gir.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/misc/update-vulkan-gir.py b/misc/update-vulkan-gir.py
new file mode 100644
index 00000000..89792c12
--- /dev/null
+++ b/misc/update-vulkan-gir.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+# Example invocation
+# cd /path/to/gobject-introspection
+# python3 misc/update-vulkan-gir.py -i /usr/include/vulkan/vulkan.h -o gir/Vulkan-1.0.gir --extra-cpp-args='-I/path/to/pycparser/utils/fake_libc_include/'
+
+import sys
+import argparse
+
+from pycparser import c_parser, c_ast, parse_file
+
+class TypedefVisitor(c_ast.NodeVisitor):
+ def __init__ (self, f):
+ super().__init__()
+ self.f = f
+
+ def visit_Typedef(self, node):
+ if node.name.startswith("Vk"):
+ self.f.write("<record name=\"" + str(node.name)[2:] + "\" c:type=\"" + str(node.name) + "\"/>\n")
+
+def show_func_defs(filename, output, extra_cpp_args=None):
+ # Note that cpp is used. Provide a path to your own cpp or
+ # make sure one exists in PATH.
+ ast = parse_file(filename, use_cpp=True,
+ cpp_args=extra_cpp_args)
+
+ with open(output, 'w') as f:
+ f.write("""<?xml version="1.0"?>
+<repository version="1.2"
+ xmlns="http://www.gtk.org/introspection/core/1.0"
+ xmlns:c="http://www.gtk.org/introspection/c/1.0">
+ <namespace name="Vulkan" version="1.0"
+ c:identifier-prefixes="VK"
+ c:symbol-prefixes="vk">
+""")
+ v = TypedefVisitor(f)
+ v.visit(ast)
+ f.write("""
+ </namespace>
+</repository>
+""")
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Parse Vulkan header files to produce Vulkan-1.0.gir")
+ parser.add_argument('-i', '--input', type=str,
+ help='The input vulkan header to process')
+ parser.add_argument('--extra-cpp-args', type=str, default=None,
+ help='Extra arguments to parse to the C Preprocesser. e.g. the location pycparser\'s fake libc includes')
+ parser.add_argument('-o', '--output', type=str, default='Vulkan-1.0.gir',
+ help='The output Vulkan-1.0.gir location')
+ args = parser.parse_args(sys.argv[1:])
+ show_func_defs(args.input, args.output, args.extra_cpp_args)