[libvirt PATCH 4/4] scripts: emit raw enum value in API build description

Daniel P. Berrangé posted 4 patches 5 years, 8 months ago
[libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Daniel P. Berrangé 5 years, 8 months ago
Currently the value for an enum is only emitted if it is a plain
string. If the enum is an integer or hex value, or a complex code block,
it is omitted from the API build. This fixes that by emitting the raw
value if no string value is present.

With this change:

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

  <macro name='LIBVIR_CHECK_VERSION'
         file='libvirt-common'
         params='major,minor,micro'
         raw='((major) * 1000000 + (minor) * 1000 + (micro) <= LIBVIR_VERSION_NUMBER)'>
  <macro name='LIBVIR_VERSION_NUMBER'
         file='libvirt-common'
         raw='6004000'>
  <macro name='VIR_COPY_CPUMAP'
         file='libvirt-domain'
         params='cpumaps,maplen,vcpu,cpumap'
         raw='memcpy(cpumap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen)'>
  ...snip...

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/apibuild.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/scripts/apibuild.py b/scripts/apibuild.py
index 9faf15a75e..d63489ba62 100755
--- a/scripts/apibuild.py
+++ b/scripts/apibuild.py
@@ -1027,11 +1027,14 @@ class CParser:
                     return token
 
                 strValue = None
+                rawValue = None
                 if len(lst) == 1 and lst[0][0] == '"' and lst[0][-1] == '"':
                     strValue = lst[0][1:-1]
+                else:
+                    rawValue = " ".join(lst)
                 (args, desc) = self.parseMacroComment(name, not self.is_header)
                 self.index_add(name, self.filename, not self.is_header,
-                               "macro", (args, desc, params, strValue))
+                               "macro", (args, desc, params, strValue, rawValue))
                 return token
 
         #
@@ -2178,13 +2181,16 @@ class docBuilder:
             desc = None
             params = None
             strValue = None
+            rawValue = None
         else:
-            (args, desc, params, strValue) = id.info
+            (args, desc, params, strValue, rawValue) = id.info
 
         if params is not None:
             output.write(" params='%s'" % params)
         if strValue is not None:
             output.write(" string='%s'" % strValue)
+        else:
+            output.write(" raw='%s'" % rawValue)
         output.write(">\n")
 
         if desc is not None and desc != "":
-- 
2.26.2

Re: [libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Michal Privoznik 5 years, 8 months ago
On 5/19/20 3:01 PM, Daniel P. Berrangé wrote:
> Currently the value for an enum is only emitted if it is a plain
> string. If the enum is an integer or hex value, or a complex code block,
> it is omitted from the API build. This fixes that by emitting the raw
> value if no string value is present.
> 
> With this change:
> 
>    <macro name='LIBVIR_CHECK_VERSION'
>           file='libvirt-common'
>           params='major,minor,micro'>
>    <macro name='LIBVIR_VERSION_NUMBER'
>           file='libvirt-common'>
>    <macro name='VIR_COPY_CPUMAP'
>           file='libvirt-domain'
>           params='cpumaps,maplen,vcpu,cpumap'>
>    ...snip...
> 
>    <macro name='LIBVIR_CHECK_VERSION'
>           file='libvirt-common'
>           params='major,minor,micro'
>           raw='((major) * 1000000 + (minor) * 1000 + (micro) <= LIBVIR_VERSION_NUMBER)'>
>    <macro name='LIBVIR_VERSION_NUMBER'
>           file='libvirt-common'
>           raw='6004000'>
>    <macro name='VIR_COPY_CPUMAP'
>           file='libvirt-domain'
>           params='cpumaps,maplen,vcpu,cpumap'
>           raw='memcpy(cpumap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen)'>
>    ...snip...
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   scripts/apibuild.py | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)

I'm seeing some weird errors after I apply this one, like:

make[2]: Entering directory 
'/home/zippy/work/libvirt/libvirt.git/_build/docs'
/usr/bin/xsltproc --nonet -o ./ \
   --stringparam builddir '/home/zippy/work/libvirt/libvirt.git/_build' \
   --stringparam timestamp "Thu May 21 12:42:53 UTC 2020" \
   ../../docs/newapi.xsl libvirt-api.xml
libvirt-api.xml:2092: parser error : Unescaped '<' not allowed in 
attributes values
' params='major,minor,micro' raw='((major) * 1000000 + (minor) * 1000 + 
(micro)
 
        ^
libvirt-api.xml:2092: parser error : attributes construct error
' params='major,minor,micro' raw='((major) * 1000000 + (minor) * 1000 + 
(micro)
 
        ^
libvirt-api.xml:2092: parser error : Couldn't find end of Start Tag 
macro line 2092
' params='major,minor,micro' raw='((major) * 1000000 + (minor) * 1000 + 
(micro)
 
        ^
libvirt-api.xml:2092: parser error : StartTag: invalid element name
  params='major,minor,micro' raw='((major) * 1000000 + (minor) * 1000 + 
(micro) <
 
        ^
libvirt-api.xml:2097: parser error : Opening and ending tag mismatch: 
symbols line 2091 and macro
     </macro>
             ^
libvirt-api.xml:2146: parser error : xmlParseEntityRef: no name
_CPU_USED' file='libvirt-domain' params='cpumap,cpu' 
raw='((cpumap)[(cpu) / 8] &
 
        ^
libvirt-api.xml:2146: parser error : Unescaped '<' not allowed in 
attributes values
_USED' file='libvirt-domain' params='cpumap,cpu' raw='((cpumap)[(cpu) / 
8] & (1
 
        ^
libvirt-api.xml:2146: parser error : attributes construct error
_USED' file='libvirt-domain' params='cpumap,cpu' raw='((cpumap)[(cpu) / 
8] & (1
 
        ^
libvirt-api.xml:2146: parser error : Couldn't find end of Start Tag 
macro line 2146
_USED' file='libvirt-domain' params='cpumap,cpu' raw='((cpumap)[(cpu) / 
8] & (1
 
        ^
libvirt-api.xml:2146: parser error : StartTag: invalid element name
USED' file='libvirt-domain' params='cpumap,cpu' raw='((cpumap)[(cpu) / 
8] & (1 <
 
        ^
libvirt-api.xml:2146: parser error : StartTag: invalid element name
SED' file='libvirt-domain' params='cpumap,cpu' raw='((cpumap)[(cpu) / 8] 
& (1 <<
 
        ^
libvirt-api.xml:2150: parser error : Opening and ending tag mismatch: 
api line 2 and macro
     </macro>
             ^
libvirt-api.xml:2151: parser error : Extra content at the end of the 
document
     <macro name='VIR_DOMAIN_BANDWIDTH_IN_AVERAGE' file='libvirt-domain' 
string='
     ^
unable to parse libvirt-api.xml


Michal

Re: [libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Daniel P. Berrangé 5 years, 8 months ago
On Thu, May 21, 2020 at 02:43:10PM +0200, Michal Privoznik wrote:
> On 5/19/20 3:01 PM, Daniel P. Berrangé wrote:
> > Currently the value for an enum is only emitted if it is a plain
> > string. If the enum is an integer or hex value, or a complex code block,
> > it is omitted from the API build. This fixes that by emitting the raw
> > value if no string value is present.
> > 
> > With this change:
> > 
> >    <macro name='LIBVIR_CHECK_VERSION'
> >           file='libvirt-common'
> >           params='major,minor,micro'>
> >    <macro name='LIBVIR_VERSION_NUMBER'
> >           file='libvirt-common'>
> >    <macro name='VIR_COPY_CPUMAP'
> >           file='libvirt-domain'
> >           params='cpumaps,maplen,vcpu,cpumap'>
> >    ...snip...
> > 
> >    <macro name='LIBVIR_CHECK_VERSION'
> >           file='libvirt-common'
> >           params='major,minor,micro'
> >           raw='((major) * 1000000 + (minor) * 1000 + (micro) <= LIBVIR_VERSION_NUMBER)'>
> >    <macro name='LIBVIR_VERSION_NUMBER'
> >           file='libvirt-common'
> >           raw='6004000'>
> >    <macro name='VIR_COPY_CPUMAP'
> >           file='libvirt-domain'
> >           params='cpumaps,maplen,vcpu,cpumap'
> >           raw='memcpy(cpumap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen)'>
> >    ...snip...
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   scripts/apibuild.py | 10 ++++++++--
> >   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> I'm seeing some weird errors after I apply this one, like:

Sigh, the patch i sent was missing the "escape()" call  to
escape <>"


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Michal Privoznik 5 years, 8 months ago
On 5/21/20 2:47 PM, Daniel P. Berrangé wrote:
> 
> Sigh, the patch i sent was missing the "escape()" call  to
> escape <>"
> 

That's okay. Just send a diff you squash in before pushing so that I can 
ACK these.

Michal

Re: [libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Daniel P. Berrangé 5 years, 8 months ago
On Tue, May 19, 2020 at 02:01:19PM +0100, Daniel P. Berrangé wrote:
> Currently the value for an enum is only emitted if it is a plain
> string. If the enum is an integer or hex value, or a complex code block,
> it is omitted from the API build. This fixes that by emitting the raw
> value if no string value is present.
> 
> With this change:
> 
>   <macro name='LIBVIR_CHECK_VERSION'
>          file='libvirt-common'
>          params='major,minor,micro'>
>   <macro name='LIBVIR_VERSION_NUMBER'
>          file='libvirt-common'>
>   <macro name='VIR_COPY_CPUMAP'
>          file='libvirt-domain'
>          params='cpumaps,maplen,vcpu,cpumap'>
>   ...snip...
> 
>   <macro name='LIBVIR_CHECK_VERSION'
>          file='libvirt-common'
>          params='major,minor,micro'
>          raw='((major) * 1000000 + (minor) * 1000 + (micro) <= LIBVIR_VERSION_NUMBER)'>
>   <macro name='LIBVIR_VERSION_NUMBER'
>          file='libvirt-common'
>          raw='6004000'>
>   <macro name='VIR_COPY_CPUMAP'
>          file='libvirt-domain'
>          params='cpumaps,maplen,vcpu,cpumap'
>          raw='memcpy(cpumap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen)'>
>   ...snip...
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/apibuild.py | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/apibuild.py b/scripts/apibuild.py
> index 9faf15a75e..d63489ba62 100755
> --- a/scripts/apibuild.py
> +++ b/scripts/apibuild.py
> @@ -1027,11 +1027,14 @@ class CParser:
>                      return token
>  
>                  strValue = None
> +                rawValue = None
>                  if len(lst) == 1 and lst[0][0] == '"' and lst[0][-1] == '"':
>                      strValue = lst[0][1:-1]
> +                else:
> +                    rawValue = " ".join(lst)
>                  (args, desc) = self.parseMacroComment(name, not self.is_header)
>                  self.index_add(name, self.filename, not self.is_header,
> -                               "macro", (args, desc, params, strValue))
> +                               "macro", (args, desc, params, strValue, rawValue))
>                  return token
>  
>          #
> @@ -2178,13 +2181,16 @@ class docBuilder:
>              desc = None
>              params = None
>              strValue = None
> +            rawValue = None
>          else:
> -            (args, desc, params, strValue) = id.info
> +            (args, desc, params, strValue, rawValue) = id.info
>  
>          if params is not None:
>              output.write(" params='%s'" % params)
>          if strValue is not None:
>              output.write(" string='%s'" % strValue)
> +        else:
> +            output.write(" raw='%s'" % rawValue)
>          output.write(">\n")
>  
>          if desc is not None and desc != "":

This last chunk needs to be

         if strValue is not None:
             output.write(" string='%s'" % strValue)
+        else:
+            output.write(" raw='%s'" % escape(rawValue))
         output.write(">\n")
 
         if desc is not None and desc != "":


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCH 4/4] scripts: emit raw enum value in API build description
Posted by Michal Privoznik 5 years, 8 months ago
On 5/22/20 11:07 AM, Daniel P. Berrangé wrote:
> output.write(" raw='%s'" % escape(rawValue))

For the whole series:

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal