golang: Fix bindings for golang 1.16.
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 8 Apr 2021 11:03:39 +0000 (12:03 +0100)
committerHilko Bengen <bengen@debian.org>
Tue, 7 Sep 2021 11:11:19 +0000 (12:11 +0100)
Gbp-Pq: Name 0023-golang-Fix-bindings-for-golang-1.16.patch

16 files changed:
.gitignore
generator/main.ml
golang/Makefile.am
golang/bindtests/go.mod [new file with mode: 0644]
golang/examples/Makefile.am
golang/examples/create-disk.go [deleted file]
golang/examples/create-disk/create-disk.go [new file with mode: 0644]
golang/examples/create-disk/go.mod [new file with mode: 0644]
golang/examples/inspect-vm.go [deleted file]
golang/examples/inspect-vm/go.mod [new file with mode: 0644]
golang/examples/inspect-vm/inspect-vm.go [new file with mode: 0644]
golang/run-bindtests
golang/run-tests
golang/src/libguestfs.org/guestfs/go.mod [new file with mode: 0644]
m4/guestfs-golang.m4
run.in

index 7a4696b9077cc10a47ab0735563d3bf54465ca94..d43258b8de8d817742404db4187137591c3a92ee 100644 (file)
@@ -301,10 +301,9 @@ Makefile.in
 /gobject/guestfs-gobject.3
 /gobject/libguestfs-gobject-1.0.vapi
 /gobject/stamp-guestfs-gobject.pod
-/golang/bindtests.go
+/golang/bindtests/bindtests.go
 /golang/examples/guestfs-golang.3
 /golang/examples/stamp-guestfs-golang.pod
-/golang/pkg
 /haskell/Bindtests
 /haskell/Bindtests.hs
 /haskell/Guestfs010Load
index c2e849e1104a8526631504eb19fe5264ab18a8a9..1e608798af0aac5668a8801b69361c62ab0d7069 100644 (file)
@@ -301,7 +301,7 @@ Run it from the top source directory using the command
 
   output_to "golang/src/libguestfs.org/guestfs/guestfs.go"
             Golang.generate_golang_go;
-  output_to "golang/bindtests.go"
+  output_to "golang/bindtests/bindtests.go"
             Bindtests.generate_golang_bindtests;
 
   output_to "gobject/bindtests.js"
index b97161180488954083a8847b0146cfb02b78df4e..ec8ad23a3d591beeb287c55270fa596858a2b648 100644 (file)
@@ -26,28 +26,24 @@ source_files = \
 
 generator_built = \
        $(source_files) \
-       bindtests.go
+       bindtests/bindtests.go
 
 EXTRA_DIST = \
        src/libguestfs.org/guestfs/.gitignore \
+       src/libguestfs.org/guestfs/go.mod \
        $(generator_built) \
+       bindtests/go.mod \
        config-test.go \
        run-bindtests \
        run-tests
 
 if HAVE_GOLANG
 
-golangpkgdir = $(GOROOT)/pkg/$(GOOS)_$(GOARCH)/$(pkg)
-golangsrcdir = $(GOROOT)/src/pkg/$(pkg)
-
-golangpkg_DATA = \
-       pkg/$(GOOS)_$(GOARCH)/$(pkg).a
-
-pkg/$(GOOS)_$(GOARCH)/$(pkg).a: src/$(pkg)/guestfs.go
-       -[ $(srcdir) != $(builddir) ] && ln -s $(abs_srcdir)/src $(builddir)/src
-       $(top_builddir)/run $(GOLANG) install $(pkg)
-
-golangsrc_DATA = $(source_files)
+all-local: $(source_files)
+       -[ "$(srcdir)" != "$(builddir)" ] && \
+           ln -s $(abs_srcdir)/src $(builddir)/src
+       cd src/$(pkg) && \
+           $(abs_top_builddir)/run $(GOLANG) build
 
 TESTS_ENVIRONMENT = pkg=$(pkg) $(top_builddir)/run $(VG) # --test
 
@@ -56,7 +52,3 @@ TESTS = run-bindtests run-tests
 endif
 
 CLEANFILES += src/$(pkg)/*~
-
-clean-local:
-       -[ $(srcdir) != $(builddir) ] && rm -f $(builddir)/src
-       rm -rf pkg
diff --git a/golang/bindtests/go.mod b/golang/bindtests/go.mod
new file mode 100644 (file)
index 0000000..64b27c5
--- /dev/null
@@ -0,0 +1,4 @@
+module main
+
+replace libguestfs.org/guestfs => ../src/libguestfs.org/guestfs
+require libguestfs.org/guestfs v1.0.0
index 53493e452a8076dd72947b53d53564b158c59a5e..68d8e5d3258c5001969c8fbe8ac96d623286b8ca 100644 (file)
@@ -19,8 +19,10 @@ include $(top_srcdir)/subdir-rules.mk
 
 EXTRA_DIST = \
        LICENSE \
-       create-disk.go \
-       inspect-vm.go \
+       create-disk/go.mod \
+       create-disk/create-disk.go \
+       inspect-vm/go.mod \
+       inspect-vm/inspect-vm.go \
        guestfs-golang.pod
 
 man_MANS = guestfs-golang.3
@@ -28,13 +30,14 @@ noinst_DATA = $(top_builddir)/website/guestfs-golang.3.html
 
 guestfs-golang.3 $(top_builddir)/website/guestfs-golang.3.html: stamp-guestfs-golang.pod
 
-stamp-guestfs-golang.pod: guestfs-golang.pod create-disk.go inspect-vm.go
-       $(PODWRAPPER) --path $(srcdir) \
+stamp-guestfs-golang.pod: guestfs-golang.pod \
+               create-disk/create-disk.go inspect-vm/inspect-vm.go
+       $(PODWRAPPER) \
          --section 3 \
          --man guestfs-golang.3 \
          --html $(top_builddir)/website/guestfs-golang.3.html \
-         --verbatim $(srcdir)/create-disk.go:@EXAMPLE1@ \
-         --verbatim $(srcdir)/inspect-vm.go:@EXAMPLE2@ \
+         --verbatim $(srcdir)/create-disk/create-disk.go:@EXAMPLE1@ \
+         --verbatim $(srcdir)/inspect-vm/inspect-vm.go:@EXAMPLE2@ \
          --license examples \
          $<
        touch $@
diff --git a/golang/examples/create-disk.go b/golang/examples/create-disk.go
deleted file mode 100644 (file)
index a59d3f4..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/* Example showing how to create a disk image. */
-
-package main
-
-import (
-       "fmt"
-       "libguestfs.org/guestfs"
-)
-
-func main() {
-       output := "disk.img"
-
-       g, errno := guestfs.Create ()
-       if errno != nil {
-               panic (errno)
-       }
-       defer g.Close ()
-
-       /* Create a raw-format sparse disk image, 512 MB in size. */
-       if err := g.Disk_create (output, "raw", 512 * 1024 * 1024); err != nil {
-               panic (err)
-       }
-
-       /* Set the trace flag so that we can see each libguestfs call. */
-       g.Set_trace (true)
-
-       /* Attach the disk image to libguestfs. */
-       optargs := guestfs.OptargsAdd_drive{
-               Format_is_set: true,
-               Format: "raw",
-               Readonly_is_set: true,
-               Readonly: false,
-       }
-       if err := g.Add_drive (output, &optargs); err != nil {
-               panic (err)
-       }
-
-       /* Run the libguestfs back-end. */
-       if err := g.Launch (); err != nil {
-               panic (err)
-       }
-
-       /* Get the list of devices.  Because we only added one drive
-        * above, we expect that this list should contain a single
-        * element.
-        */
-       devices, err := g.List_devices ()
-       if err != nil {
-               panic (err)
-       }
-       if len(devices) != 1 {
-               panic ("expected a single device from list-devices")
-       }
-
-       /* Partition the disk as one single MBR partition. */
-       err = g.Part_disk (devices[0], "mbr")
-       if err != nil {
-               panic (err)
-       }
-
-       /* Get the list of partitions.  We expect a single element, which
-        * is the partition we have just created.
-        */
-       partitions, err := g.List_partitions ()
-       if err != nil {
-               panic (err)
-       }
-       if len(partitions) != 1 {
-               panic ("expected a single partition from list-partitions")
-       }
-
-       /* Create a filesystem on the partition. */
-       err = g.Mkfs ("ext4", partitions[0], nil)
-       if err != nil {
-               panic (err)
-       }
-
-       /* Now mount the filesystem so that we can add files. */
-       err = g.Mount (partitions[0], "/")
-       if err != nil {
-               panic (err)
-       }
-
-       /* Create some files and directories. */
-       err = g.Touch ("/empty")
-       if err != nil {
-               panic (err)
-       }
-       message := []byte("Hello, world\n")
-       err = g.Write ("/hello", message)
-       if err != nil {
-               panic (err)
-       }
-       err = g.Mkdir ("/foo")
-       if err != nil {
-               panic (err)
-       }
-
-       /* This one uploads the local file /etc/resolv.conf into
-        * the disk image.
-        */
-       err = g.Upload ("/etc/resolv.conf", "/foo/resolv.conf")
-       if err != nil {
-               panic (err)
-       }
-
-       /* Because we wrote to the disk and we want to detect write
-        * errors, call g:shutdown.  You don't need to do this:
-        * g.Close will do it implicitly.
-        */
-       if err = g.Shutdown (); err != nil {
-               panic (fmt.Sprintf ("write to disk failed: %s", err))
-       }
-}
diff --git a/golang/examples/create-disk/create-disk.go b/golang/examples/create-disk/create-disk.go
new file mode 100644 (file)
index 0000000..a59d3f4
--- /dev/null
@@ -0,0 +1,114 @@
+/* Example showing how to create a disk image. */
+
+package main
+
+import (
+       "fmt"
+       "libguestfs.org/guestfs"
+)
+
+func main() {
+       output := "disk.img"
+
+       g, errno := guestfs.Create ()
+       if errno != nil {
+               panic (errno)
+       }
+       defer g.Close ()
+
+       /* Create a raw-format sparse disk image, 512 MB in size. */
+       if err := g.Disk_create (output, "raw", 512 * 1024 * 1024); err != nil {
+               panic (err)
+       }
+
+       /* Set the trace flag so that we can see each libguestfs call. */
+       g.Set_trace (true)
+
+       /* Attach the disk image to libguestfs. */
+       optargs := guestfs.OptargsAdd_drive{
+               Format_is_set: true,
+               Format: "raw",
+               Readonly_is_set: true,
+               Readonly: false,
+       }
+       if err := g.Add_drive (output, &optargs); err != nil {
+               panic (err)
+       }
+
+       /* Run the libguestfs back-end. */
+       if err := g.Launch (); err != nil {
+               panic (err)
+       }
+
+       /* Get the list of devices.  Because we only added one drive
+        * above, we expect that this list should contain a single
+        * element.
+        */
+       devices, err := g.List_devices ()
+       if err != nil {
+               panic (err)
+       }
+       if len(devices) != 1 {
+               panic ("expected a single device from list-devices")
+       }
+
+       /* Partition the disk as one single MBR partition. */
+       err = g.Part_disk (devices[0], "mbr")
+       if err != nil {
+               panic (err)
+       }
+
+       /* Get the list of partitions.  We expect a single element, which
+        * is the partition we have just created.
+        */
+       partitions, err := g.List_partitions ()
+       if err != nil {
+               panic (err)
+       }
+       if len(partitions) != 1 {
+               panic ("expected a single partition from list-partitions")
+       }
+
+       /* Create a filesystem on the partition. */
+       err = g.Mkfs ("ext4", partitions[0], nil)
+       if err != nil {
+               panic (err)
+       }
+
+       /* Now mount the filesystem so that we can add files. */
+       err = g.Mount (partitions[0], "/")
+       if err != nil {
+               panic (err)
+       }
+
+       /* Create some files and directories. */
+       err = g.Touch ("/empty")
+       if err != nil {
+               panic (err)
+       }
+       message := []byte("Hello, world\n")
+       err = g.Write ("/hello", message)
+       if err != nil {
+               panic (err)
+       }
+       err = g.Mkdir ("/foo")
+       if err != nil {
+               panic (err)
+       }
+
+       /* This one uploads the local file /etc/resolv.conf into
+        * the disk image.
+        */
+       err = g.Upload ("/etc/resolv.conf", "/foo/resolv.conf")
+       if err != nil {
+               panic (err)
+       }
+
+       /* Because we wrote to the disk and we want to detect write
+        * errors, call g:shutdown.  You don't need to do this:
+        * g.Close will do it implicitly.
+        */
+       if err = g.Shutdown (); err != nil {
+               panic (fmt.Sprintf ("write to disk failed: %s", err))
+       }
+}
diff --git a/golang/examples/create-disk/go.mod b/golang/examples/create-disk/go.mod
new file mode 100644 (file)
index 0000000..0ec0787
--- /dev/null
@@ -0,0 +1,4 @@
+module main
+
+replace libguestfs.org/guestfs => ../../src/libguestfs.org/guestfs
+require libguestfs.org/guestfs v1.0.0
diff --git a/golang/examples/inspect-vm.go b/golang/examples/inspect-vm.go
deleted file mode 100644 (file)
index 74a27a9..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Example showing how to inspect a virtual machine disk. */
-
-package main
-
-import (
-       "fmt"
-       "os"
-       "libguestfs.org/guestfs"
-)
-
-func main() {
-       if len(os.Args) < 2 {
-               panic ("usage: inspect-vm disk.img")
-       }
-       disk := os.Args[1]
-
-       g, errno := guestfs.Create ()
-       if errno != nil {
-               panic (fmt.Sprintf ("could not create handle: %s", errno))
-       }
-
-       /* Attach the disk image read-only to libguestfs. */
-       optargs := guestfs.OptargsAdd_drive{
-               Format_is_set: true,
-               Format: "raw",
-               Readonly_is_set: true,
-               Readonly: true,
-       }
-       if err := g.Add_drive (disk, &optargs); err != nil {
-               panic (err)
-       }
-
-       /* Run the libguestfs back-end. */
-       if err := g.Launch (); err != nil {
-               panic (err)
-       }
-
-       /* Ask libguestfs to inspect for operating systems. */
-       roots, err := g.Inspect_os ()
-       if err != nil {
-               panic (err)
-       }
-       if len(roots) == 0 {
-               panic ("inspect-vm: no operating systems found")
-       }
-
-       for _, root := range roots {
-               fmt.Printf ("Root device: %s\n", root)
-
-               /* Print basic information about the operating system. */
-               s, _ := g.Inspect_get_product_name (root)
-               fmt.Printf ("  Product name: %s\n", s)
-               major, _ := g.Inspect_get_major_version (root)
-               minor, _ := g.Inspect_get_minor_version (root)
-               fmt.Printf ("  Version:      %d.%d\n", major, minor)
-               s, _ = g.Inspect_get_type (root)
-               fmt.Printf ("  Type:         %s\n", s)
-               s, _ = g.Inspect_get_distro (root)
-               fmt.Printf ("  Distro:       %s\n", s)
-
-               /* XXX Incomplete example.  Sorting the keys by length
-                * is unnecessarily hard in golang.
-                */
-       }
-}
diff --git a/golang/examples/inspect-vm/go.mod b/golang/examples/inspect-vm/go.mod
new file mode 100644 (file)
index 0000000..0ec0787
--- /dev/null
@@ -0,0 +1,4 @@
+module main
+
+replace libguestfs.org/guestfs => ../../src/libguestfs.org/guestfs
+require libguestfs.org/guestfs v1.0.0
diff --git a/golang/examples/inspect-vm/inspect-vm.go b/golang/examples/inspect-vm/inspect-vm.go
new file mode 100644 (file)
index 0000000..74a27a9
--- /dev/null
@@ -0,0 +1,65 @@
+/* Example showing how to inspect a virtual machine disk. */
+
+package main
+
+import (
+       "fmt"
+       "os"
+       "libguestfs.org/guestfs"
+)
+
+func main() {
+       if len(os.Args) < 2 {
+               panic ("usage: inspect-vm disk.img")
+       }
+       disk := os.Args[1]
+
+       g, errno := guestfs.Create ()
+       if errno != nil {
+               panic (fmt.Sprintf ("could not create handle: %s", errno))
+       }
+
+       /* Attach the disk image read-only to libguestfs. */
+       optargs := guestfs.OptargsAdd_drive{
+               Format_is_set: true,
+               Format: "raw",
+               Readonly_is_set: true,
+               Readonly: true,
+       }
+       if err := g.Add_drive (disk, &optargs); err != nil {
+               panic (err)
+       }
+
+       /* Run the libguestfs back-end. */
+       if err := g.Launch (); err != nil {
+               panic (err)
+       }
+
+       /* Ask libguestfs to inspect for operating systems. */
+       roots, err := g.Inspect_os ()
+       if err != nil {
+               panic (err)
+       }
+       if len(roots) == 0 {
+               panic ("inspect-vm: no operating systems found")
+       }
+
+       for _, root := range roots {
+               fmt.Printf ("Root device: %s\n", root)
+
+               /* Print basic information about the operating system. */
+               s, _ := g.Inspect_get_product_name (root)
+               fmt.Printf ("  Product name: %s\n", s)
+               major, _ := g.Inspect_get_major_version (root)
+               minor, _ := g.Inspect_get_minor_version (root)
+               fmt.Printf ("  Version:      %d.%d\n", major, minor)
+               s, _ = g.Inspect_get_type (root)
+               fmt.Printf ("  Type:         %s\n", s)
+               s, _ = g.Inspect_get_distro (root)
+               fmt.Printf ("  Distro:       %s\n", s)
+
+               /* XXX Incomplete example.  Sorting the keys by length
+                * is unnecessarily hard in golang.
+                */
+       }
+}
index 483daa20800409bf932f5aa1539c6ef46e1f1824..e79bb07a1048c2bc808e1544a49b2eb4ba0c86b5 100755 (executable)
@@ -18,6 +18,7 @@
 
 set -e
 
-$GOLANG run $srcdir/bindtests.go > bindtests.tmp
-diff -u $srcdir/../bindtests bindtests.tmp
+cd $srcdir/bindtests
+$GOLANG run bindtests.go > bindtests.tmp
+diff -u $srcdir/../../bindtests bindtests.tmp
 rm bindtests.tmp
index 6f01c84800fb2d5290394cbd8d65f694783daf17..997184d93d739a3dd35864c841bed1a1332715e8 100755 (executable)
@@ -18,4 +18,6 @@
 
 set -e
 
-$GOLANG test $pkg
+cd src/$pkg
+
+$GOLANG test
diff --git a/golang/src/libguestfs.org/guestfs/go.mod b/golang/src/libguestfs.org/guestfs/go.mod
new file mode 100644 (file)
index 0000000..31cf37e
--- /dev/null
@@ -0,0 +1,4 @@
+module libguestfs.org/guestfs
+
+// First version of golang with working module support.
+go 1.13
\ No newline at end of file
index d5e6aafa87d0926f0e22732e3fce6361a045aa88..5f011ffa604629d2565ed60f084d002da0744ed9 100644 (file)
@@ -26,14 +26,6 @@ AS_IF([test "x$enable_golang" != "xno"],[
         AC_MSG_CHECKING([if $GOLANG is usable])
         AS_IF([$GOLANG run $srcdir/golang/config-test.go 2>&AS_MESSAGE_LOG_FD],[
             AC_MSG_RESULT([yes])
-
-            # Substitute some golang environment.
-            GOOS=`$GOLANG env GOOS`
-            GOARCH=`$GOLANG env GOARCH`
-            GOROOT=`$GOLANG env GOROOT`
-            AC_SUBST([GOOS])
-            AC_SUBST([GOARCH])
-            AC_SUBST([GOROOT])
         ],[
             AC_MSG_RESULT([no])
             AC_MSG_WARN([golang ($GOLANG) is installed but not usable])
diff --git a/run.in b/run.in
index 10844a65152ff9311168d39bc1a5d4e8ca3fa0b6..3c01ebe13f9c3cde6e0aa5c7741ae8d47c37569c 100755 (executable)
--- a/run.in
+++ b/run.in
@@ -178,8 +178,6 @@ export LUA_CPATH
 
 # For golang.
 export GOLANG="@GOLANG@"
-prepend GOPATH "$b/golang"
-export GOPATH
 if [ -z "$CGO_CFLAGS" ]; then
     CGO_CFLAGS="-I$s/include"
 else