Browse Source

bindgen: Include top comment in Zig & Odin

Alexander Arvidsson 8 months ago
parent
commit
81dfc1d0e9
3 changed files with 12 additions and 3 deletions
  1. 4 1
      bindgen/gen_ir.py
  2. 3 0
      bindgen/gen_odin.py
  3. 5 2
      bindgen/gen_zig.py

+ 4 - 1
bindgen/gen_ir.py

@@ -1,7 +1,7 @@
 #-------------------------------------------------------------------------------
 #   Generate an intermediate representation of a clang AST dump.
 #-------------------------------------------------------------------------------
-import json, sys, subprocess
+import re, json, sys, subprocess
 
 def is_api_decl(decl, prefix):
     if 'name' in decl:
@@ -136,6 +136,9 @@ def gen(header_path, source_path, module, main_prefix, dep_prefixes, with_commen
     outp['decls'] = []
     with open(header_path, 'r') as f:
         source = f.read()
+        first_comment = re.search(r"/\*(.*?)\*/", source, re.S).group(1)
+        if first_comment and "Project URL" in first_comment:
+            outp['comment'] = first_comment
         for decl in inp['inner']:
             is_dep = is_dep_decl(decl, dep_prefixes)
             if is_api_decl(decl, main_prefix) or is_dep:

+ 3 - 0
bindgen/gen_odin.py

@@ -509,6 +509,9 @@ def gen_module(inp, c_prefix, dep_prefixes):
     l('// machine generated, do not edit')
     l('')
     l(f"package sokol_{inp['module']}")
+    if inp.get('comment'):
+        l('')
+        c(inp['comment'])
     gen_imports(dep_prefixes)
     gen_helpers(inp)
     prefix = inp['prefix']

+ 5 - 2
bindgen/gen_zig.py

@@ -126,10 +126,10 @@ def l(s):
     global out_lines
     out_lines += s + '\n'
 
-def c(s, indent=""):
+def c(s, indent="", comment="///"):
     if not s:
         return
-    prefix = f"{indent}///"
+    prefix = f"{indent}{comment}"
     for line in textwrap.dedent(s).splitlines():
         l(f"{prefix} {line}" if line else prefix )
 
@@ -554,6 +554,9 @@ def gen_helpers(inp):
 
 def gen_module(inp, dep_prefixes):
     l('// machine generated, do not edit')
+    if inp.get('comment'):
+        l('')
+        c(inp['comment'], comment="//")
     l('')
     gen_imports(inp, dep_prefixes)
     gen_helpers(inp)