qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v2 0/8] qapi: add generator for Golang interface


From: Victor Toso
Subject: [RFC PATCH v2 0/8] qapi: add generator for Golang interface
Date: Fri, 17 Jun 2022 14:19:24 +0200

Hi,

This is the second iteration of RFC v1:
  https://lists.gnu.org/archive/html/qemu-devel/2022-04/msg00226.html


# What this is about?

To generate a simple Golang interface that could communicate with QEMU
over QMP. The Go code that is generated is meant to be used as the bare
bones to exchange QMP messages.

The goal is to have this as a Go module in QEMU gitlab namespace,
similar to what have been done to pyhon-qemu-qmp
  https://gitlab.com/qemu-project/python-qemu-qmp


# Issues raised in RFC v1

  The leading '*' for issues I addressed in this iteration

* 1) Documentation was removed to avoid License issues, by Daniel
     Thread: 
https://lists.nongnu.org/archive/html/qemu-devel/2022-05/msg01889.html

     It is important for the generated Go module to be compatible with
     Licenses used by projects that would be using this. Copying the
     documentation of the QAPI spec might conflict with GPLv2+.

     I have not proposed another license in this iteration, but I'm
     planning to go with MIT No Attribution, aka MIT-0 [0]. Does it make
     sense to bind the generated code's license to MIT-0 already at
     generator level?

     [0] https://github.com/aws/mit-0/blob/master/MIT-0

  2) Inconsistent generated Names, by Andrea + Markus
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-04/msg05026.html
     Example 1:
         |    qapi    |    Go     |  Expected |
         | @logappend | Logappend | LogAppend |
 
     Example 2:
         (acronyms) VncInfo and DisplayReloadOptionsVNC
 
     This was not addressed in RFC v2 mainly because it seems to need
     more metadata support from the QAPI spec to handle specific
     scenarios. The solution seems either an extra metadata proposal by
     Andrea [1] or reviving Kevin's work [2]
     
     [1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg00127.html
     [2] https://lists.gnu.org/archive/html/qemu-devel/2021-09/msg04703.html

* 3) Better type safety, by Andrea + Daniel
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg01906.html
 
     Most of the 'Any' type (interface {}) has been removed. The only
     place it still exists is for fields that uses QAPI's any type, like
     with command qom-set or the struct type ObjectPropertyInfo.

* 4) QAPI enums mapped to String instead of Int type, by Daniel.
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg01904.html

     I'm still over the fence about using string here, mostly by the
     same issue reported here:
     
https://gitlab.com/libvirt/libvirt-go-module/-/merge_requests/30#note_975517740

* 5) Events and Commands as interface, by Daniel
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg01914.html

     So, instead of having a Command/Event struct with a Any type for
     the Arguments (which could be set with SetPasswordCommand struct
     type for example); now we have a Command interface which all
     previous structs that behaved as Arguments implement.

     I've included Marshal{Command Event} and Unmarshal{Command Event}
     helper functions that operate on top of each interface.

* 6) Removing Any from Unions, by Daniel
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg01912.html

     I basically followed the above suggestion to all other types that
     used Any. Specifically to unions were the removal of the
     'discriminator' field, as proposed also in the above link.

* 7) Flat structs by removing embed types. Discussion with Andrea
     Thread: 
https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg01590.html 

     No one required it but I decided to give it a try. Major issue that
     I see with this approach is to have generated a few 'Base' structs
     that are now useless. Overall, less nested structs seems better to
     me. Opnions?

     Example:
      | /* This is now useless, should be removed? */
      | type InetSocketAddressBase struct {
      |     Host string `json:"host"`
      |     Port string `json:"port"`
      | }
      |
      | type InetSocketAddress struct {
      |     // Base fields
      |     Host string `json:"host"`
      |     Port string `json:"port"`
      |
      |
      |     Numeric   *bool   `json:"numeric,omitempty"`
      |     To        *uint16 `json:"to,omitempty"`
      |     Ipv4      *bool   `json:"ipv4,omitempty"`
      |     Ipv6      *bool   `json:"ipv6,omitempty"`
      |     KeepAlive *bool   `json:"keep-alive,omitempty"`
      |     Mptcp     *bool   `json:"mptcp,omitempty"`
      | }

  8) Supporting multiple versions
     Thread: https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg02147.html

     I'm keen to working on the proposed solution above as it seems a
     good compromise to make code that can be compatible with multiple
     versions of qmp/qemu.

     But the basis needs to be defined first, so this is for the future.

* 9) Handling { "error": { ... } }
     This was missing in the RFC v1. I've added a QapiError type that is
     included in all CommandReturn types, following Andrea's suggestion:

     https://lists.gnu.org/archive/html/qemu-devel/2022-04/msg02199.html


# victortoso/qapi-go and victortoso/qemu

I'm currently hosting the generated code from this RFCv2 at:
    https://gitlab.com/victortoso/qapi-go/-/tree/main/pkg/qapi

This series can also be found at:
    https://gitlab.com/victortoso/qemu/-/commits/qapi-golang


Thanks for taking a look,
Victor

Victor Toso (8):
  qapi: golang: Generate qapi's enum types in Go
  qapi: golang: Generate qapi's alternate types in Go
  qapi: golang: Generate qapi's struct types in Go
  qapi: golang: Generate qapi's union types in Go
  qapi: golang: Generate qapi's event types in Go
  qapi: golang: Generate qapi's command types in Go
  qapi: golang: Add CommandResult type to Go
  qapi: golang: document skip function visit_array_types

 scripts/qapi/golang.py | 765 +++++++++++++++++++++++++++++++++++++++++
 scripts/qapi/main.py   |   2 +
 2 files changed, 767 insertions(+)
 create mode 100644 scripts/qapi/golang.py

-- 
2.36.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]