Commit Graph

26 Commits

Author SHA1 Message Date
Han Han
28141adfdc scripts: Fix the flake8 syntax-check failures
Fix the syntax-check failures (which can be seen after
python3-flake8-import-order package is installed) with the help
of isort[1]:

289/316 libvirt:syntax-check / flake8   FAIL   5.24s   exit status 2

[1]: https://pycqa.github.io/isort/

Signed-off-by: Han Han <hhan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-06-29 11:51:27 +02:00
Peter Krempa
69615c91c8 scripts/apibuild: Extract and format API ACLs
As an additional step before processing the API parse the protocol file
and extract all ACL definitions. This way we can distribute them for any
user of the libvirt API XML files. We will be also able to avoid another
call to gendispatch, which generates all this data into a standalone
XML.

The remote procedure to API name is inspired by what rpcgen does.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-03-06 13:09:16 +01:00
Peter Krempa
d03b6bf0cb apibuild: Add infrastructure for generating ACL flag info into function docs
If the user of the 'docBuilder' class provides a dict (key is API name,
value is a tuple of arrays (acls, aclfilters), use the dict to generate
ACL definitions into the function definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-03-06 13:09:15 +01:00
Peter Krempa
1bea629cbc apibuild: Don't include the Copyright in the <description> of a module
When building the top level description from a header file the
'parseTopComment' method of the 'CParser' would include all trailing
lines into the <description> field. This was designed to concatenate
multi-line descriptions, but unfortunately in all cases also included
the Copyright statement which followed.

Explicitly end the scanning of the header on a line which starts with
'Copyright (C)' and truncate the spaces from the end of the last item.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-03 14:11:22 +01:00
Peter Krempa
12a76fb81e scripts: apibuild: Improve error when API is missing from symbol file
Improve:

 KeyError: 'virAdmConnectSetDaemonTimeout'

to

 Exception: Missing symbol file entry for 'virAdmConnectSetDaemonTimeout'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-07-07 14:35:30 +02:00
luzhipeng
3e009bbdb8 apibuild: Fix self.waring method call
The parameters of self.warning is inconsistent with its definition, So
fix it.

Signed-off-by: luzhipeng <luzhipeng@cestc.cn>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2022-05-09 14:44:36 +02:00
Victor Toso
f3d4102d67 apibuild: remove 'v' from pattern matching
This makes it mandatory to *not* add 'v' to version numbers.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-05-04 18:12:30 +02:00
Victor Toso
6975ed0a94 scripts: apibuild: add parsing variable's comments
scripts/apibuild.py did not consider exporting external variable's
comments into the XML API. This commits fixes that.

Noe that the way that CParser is designed, it is currently possible to
lose a parsed comment when parsing other fields as self.comment in
several places. I've added a comment to highlight this.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:33 +02:00
Victor Toso
4bce59d963 scripts: apibuild: factor out comment cleaning
So we can use for comments that are being hold in helper variables.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:30 +02:00
Victor Toso
034600e601 scripts: apibuild: parse 'Since' for functions
This patch adds 'version' parameter to generated XML API for functions
and functypes.

The 'version' metadata has been added with e0e0bf6628 by parsing .syms
files. This commit does not override that but it will warn if there is
not 'Since' metadata with new additions.

There is not clear benefit for keeping both. For now, I've added a
warning in case there is a mismatch between the version provided by
.syms and docstring.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:28 +02:00
Victor Toso
b7472a1d79 scripts: apibuild: parse 'Since' for macros
This patch adds 'version' parameter to the generated XML API for
macros

It'll require, for new additions, to add a comment with the version
that the macro was added. An example bellow of code diff and
the change in the generated XML.

Note that the Since tag is removed from the comment as there is a
proper field for it in the XML.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:27 +02:00
Victor Toso
8be766e39c scripts: apibuild: parse 'Since' for typedefs
This patch adds 'version' parameter to the generated XML API for
typedefs

It'll require, for new additions, to add a comment with the version
that the typedef value was added. An example bellow of code diff and
the change in the generated XML.

Note that the Since tag is removed from the comment as there is a
proper field for it in the XML.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:25 +02:00
Victor Toso
2f1c01e672 scripts: apibuild: fix parsing block comments from typedef enum
Removed the TODO as we can rely to the serialize_typedef() the job to
report missing comments.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:22 +02:00
Victor Toso
7958b7d9c5 scripts: apibuild: parse 'Since' version for enums
This patch adds 'version' parameter to the generated XML API for
enums.

It'll require, for new additions, to add a comment with the version
that the enum value was added.

Note that the Since tag is removed from the comment as there is a
proper field for it in the XML.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-04-26 17:54:17 +02:00
Daniel P. Berrangé
e0e0bf6628 scripts: include function versions in API definition
In order to auto-generate more of the language binding code, it is
desirable to know what libvirt version an API was introduced in.
We can extract this information from the .syms files and expose
it in the API description

eg instead of

  <function name='virNodeNumOfDevices' file='libvirt-nodedev'
            module='libvirt-nodedev'>

we now have

  <function name='virNodeNumOfDevices' file='libvirt-nodedev'
            module='libvirt-nodedev' version='0.5.0'>

This will benefit this proposal:

  https://gitlab.com/libvirt/libvirt-go-module/-/merge_requests/7

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Victor Toso <victortoso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-23 16:30:18 +01:00
Ján Tomko
c066cb6dc1 scripts: apibuild: fix spacing
Syntax check reports:
E226 missing whitespace around arithmetic operator

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2021-09-21 18:04:00 +02:00
Daniel P. Berrangé
81b63c3d78 scripts: fix API parsing of *** pointers
The currrent generated API contains *** pointer types with bogus
whitespace in the middle:

  <arg name='keys' type='char ** *' info='pointer to a variable to store authorized keys'/>

because the tokenizer only tries to merge 2 distinct '*' together.
This refactors the code to merge an arbitrary number, resulting
in

  <arg name='keys' type='char ***' info='pointer to a variable to store authorized keys'/>

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-21 16:22:30 +01:00
Martin Kletzander
c5872b9a1b tests: Add simple test for virDomainMigrateCheckNotLocal
For this we need to make the function accessible (at least privately).  The
behaviour will change in following patches and the test helps explaining the
change.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2020-09-04 10:20:49 +02:00
Pavel Hrdina
4dc0e601c7 meson: docs: build api XML files
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
2020-08-03 09:27:06 +02:00
Daniel P. Berrangé
61fdc96706 scripts: emit raw enum value in API build description
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...

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-05-22 11:32:55 +01:00
Daniel P. Berrangé
38f3fa6140 scripts: emit enum parameters in API build description
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...

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-05-22 11:32:55 +01:00
Daniel P. Berrangé
34204f9923 scripts: fix tokenizing of enum parameters in API builder
The API build script tokenizes enums declarations by first splitting on
whitespace. This is unhelpful as it means an enum

 # define VIR_USE_CPU(cpumap, cpu) ((cpumap)[(cpu) / 8] |= (1 << ((cpu) % 8)))

Gets tokenized as

  #define
  VIR_USE_CPU(cpumap,
  cpu)
  ((cpumap)[(cpu)
  /
  8]
  |=
  (1
  <<
  ((cpu)
  %
  8)))

With this change, the set of parameters are all merged into the first
token:

  #define
  VIR_USE_CPU(cpumap,cpu)
  ((cpumap)[(cpu)
  /
  8]
  |=
  (1
  <<
  ((cpu)
  %
  8)))

which is more convenient to process later on in the script.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-05-22 11:32:55 +01:00
Daniel P. Berrangé
50eb22e343 scripts: use UTF-8 for API XML files
The build system will be running in UTF-8 locale, so any content in the
API XML files will also end up being UTF-8, not ISO-8859-1.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-05-22 11:32:55 +01:00
Michal Privoznik
4a09c143f6 virerror: Make it easier to add new error number
In v5.0.0-rc1~94 we switched from one huge switch() to an array
for translating error numbers into error messages. However, the
array is declared to have VIR_ERR_NUMBER_LAST items which makes
it impossible to spot this place by compile checking when adding
new error number.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2020-01-10 13:53:32 +01:00
Daniel P. Berrangé
f0b3840fb6 build: only support python3 binary
python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-12-04 13:13:01 +00:00
Daniel P. Berrangé
5ffbad2575 docs: move apibuild.py to the scripts/ directory
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-12-04 11:41:32 +00:00