[libvirt PATCH 3/4] scripts: emit enum parameters in API build description

Daniel P. Berrangé berrange at redhat.com
Tue May 19 13:01:18 UTC 2020


Currently the information about enums in the API document lacks any
mention of parameters, so it is impossible to tell what kind of enum
declaration is present in the libvirt API header. With this change

  <macro name='LIBVIR_CHECK_VERSION' file='libvirt-common'>
  <macro name='VIR_COPY_CPUMAP' file='libvirt-domain'>
  ...snip...

becomes

  <macro name='LIBVIR_CHECK_VERSION' file='libvirt-common' params='major,minor,micro'>
  <macro name='VIR_COPY_CPUMAP' file='libvirt-domain' params='cpumaps,maplen,vcpu,cpumap'>
  ...snip...

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 scripts/apibuild.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/scripts/apibuild.py b/scripts/apibuild.py
index 68c588d8b6..9faf15a75e 100755
--- a/scripts/apibuild.py
+++ b/scripts/apibuild.py
@@ -1013,10 +1013,12 @@ class CParser:
                        token[1][0] != '#'):
                     lst.append(token[1])
                     token = self.lexer.token()
-                try:
-                    name = name.split('(')[0]
-                except Exception:
-                    pass
+
+                paramStart = name.find("(")
+                params = None
+                if paramStart != -1:
+                    params = name[paramStart+1:-1]
+                    name = name[0:paramStart]
 
                 # skip hidden macros
                 if name in hidden_macros:
@@ -1029,7 +1031,7 @@ class CParser:
                     strValue = lst[0][1:-1]
                 (args, desc) = self.parseMacroComment(name, not self.is_header)
                 self.index_add(name, self.filename, not self.is_header,
-                               "macro", (args, desc, strValue))
+                               "macro", (args, desc, params, strValue))
                 return token
 
         #
@@ -2174,10 +2176,13 @@ class docBuilder:
         if id.info is None:
             args = []
             desc = None
+            params = None
             strValue = None
         else:
-            (args, desc, strValue) = id.info
+            (args, desc, params, strValue) = id.info
 
+        if params is not None:
+            output.write(" params='%s'" % params)
         if strValue is not None:
             output.write(" string='%s'" % strValue)
         output.write(">\n")
-- 
2.26.2




More information about the libvir-list mailing list