[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 2/9] qapi: golang: Generate qapi's alternate types in Go
From: |
Victor Toso |
Subject: |
Re: [PATCH v1 2/9] qapi: golang: Generate qapi's alternate types in Go |
Date: |
Fri, 29 Sep 2023 14:23:22 +0200 |
Hi,
On Thu, Sep 28, 2023 at 03:51:50PM +0100, Daniel P. Berrangé wrote:
> On Wed, Sep 27, 2023 at 01:25:37PM +0200, Victor Toso wrote:
> > This patch handles QAPI alternate types and generates data structures
> > in Go that handles it.
>
> This file (and most others) needs some imports added.
> I found the following to be required in order to
> actually compile this:
This was by design, I mean, my preference. I decided that the
generator should output correct but not necessarly
formatted/buildable Go code. The consumer should still use
gofmt/goimports.
Do you think we should do this in QEMU? What about extra
dependencies in QEMU with go binaries?
This is how it is done in victortoso/qapi-go module:
# to generate
toso@tapioca ~> QEMU_REPO=/home/toso/src/qemu go generate ./...
# the generation
toso@tapioca ~> cat src/qapi-go/pkg/qapi/doc.go
//go:generate ../../scripts/generate.sh
//go:generate gofmt -w .
//go:generate goimports -w .
package qapi
# script
URL="https://gitlab.com/victortoso/qemu.git"
BRANCH="qapi-golang"
if [[ -z "${QEMU_REPO}" ]]; then
git clone --depth 1 --branch $BRANCH $URL
QEMU_REPO="$PWD/qemu"
fi
python3 $QEMU_REPO/scripts/qapi-gen.py -o tmp
$QEMU_REPO/qapi/qapi-schema.json
mv tmp/go/* .
rm -rf tmp qemu
Cheers,
Victor
> alternates.go:import (
> alternates.go- "encoding/json"
> alternates.go- "errors"
> alternates.go- "fmt"
> alternates.go-)
>
>
> commands.go:import (
> commands.go- "encoding/json"
> commands.go- "errors"
> commands.go- "fmt"
> commands.go-)
>
>
> events.go:import (
> events.go- "encoding/json"
> events.go- "errors"
> events.go- "fmt"
> events.go-)
>
>
> helpers.go:import (
> helpers.go- "encoding/json"
> helpers.go- "fmt"
> helpers.go- "strings"
> helpers.go-)
>
>
> structs.go:import (
> structs.go- "encoding/json"
> structs.go-)
>
>
> unions.go:import (
> unions.go- "encoding/json"
> unions.go- "errors"
> unions.go- "fmt"
> unions.go-)
>
>
>
>
> With 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 :|
>
signature.asc
Description: PGP signature
- Re: [PATCH v1 1/9] qapi: golang: Generate qapi's enum types in Go, (continued)
[PATCH v1 5/9] qapi: golang: Generate qapi's union types in Go, Victor Toso, 2023/09/27
[PATCH v1 6/9] qapi: golang: Generate qapi's event types in Go, Victor Toso, 2023/09/27
[PATCH v1 2/9] qapi: golang: Generate qapi's alternate types in Go, Victor Toso, 2023/09/27
[PATCH v1 3/9] qapi: golang: Generate qapi's struct types in Go, Victor Toso, 2023/09/27
[PATCH v1 4/9] qapi: golang: structs: Address 'null' members, Victor Toso, 2023/09/27
[PATCH v1 7/9] qapi: golang: Generate qapi's command types in Go, Victor Toso, 2023/09/27
[PATCH v1 8/9] qapi: golang: Add CommandResult type to Go, Victor Toso, 2023/09/27