NO-JIRA: go wrappers re-generated to be compatible with proton-c 0.10

Some new definitions had creeped into the wrappers_gen.go that would fail to
build with older versions of proton-c.

Updated genwrap.go:
- -include option generates from installed headers instead of git source
- explicitly include the intended minimum C version
- fail attempts to generate from newer headers

Added test-versions.sh, takes a list of install prefixes where proton is
installed and runs go test on the git go sources against each one.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c94301d5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c94301d5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c94301d5

Branch: refs/heads/go1
Commit: c94301d59ce0a9a8863d3bd71919c1acfebce533
Parents: c87b23e
Author: Alan Conway <acon...@redhat.com>
Authored: Thu Feb 23 16:39:14 2017 -0500
Committer: Alan Conway <acon...@redhat.com>
Committed: Thu Feb 23 17:10:22 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/go/genwrap.go                 | 77 ++++++++++++++++----
 .../go/src/qpid.apache.org/amqp/version.go      |  8 +-
 .../src/qpid.apache.org/proton/wrappers_gen.go  | 39 +---------
 proton-c/bindings/go/test-versions.sh           | 50 +++++++++++++
 4 files changed, 125 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c94301d5/proton-c/bindings/go/genwrap.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/genwrap.go b/proton-c/bindings/go/genwrap.go
index 6885b74..0bf13fa 100644
--- a/proton-c/bindings/go/genwrap.go
+++ b/proton-c/bindings/go/genwrap.go
@@ -22,6 +22,12 @@ under the License.
 // Not run automatically, generated sources are checked in. To update the
 // generated sources run `go run genwrap.go` in this directory.
 //
+// WARNING: generating code from the wrong proton header file versions
+// will break compatibility guarantees. This program will attempt to detect
+// such errors. If you are deliberately changing the compatibility requirements
+// update the variable minVersion below.
+//
+
 package main
 
 import (
@@ -37,12 +43,61 @@ import (
        "text/template"
 )
 
-var includeProton = "../../include/proton"
-var outpath = "src/qpid.apache.org/proton/wrappers_gen.go"
+var minVersion = "0.10" // The minimum version of proton-c that the Go binding 
can use
+var include = flag.String("include", "../../include", "Directory containing 
proton/*.h include files")
+
+var versionH = regexp.MustCompile("(?s:PN_VERSION_MAJOR 
([0-9]+).*PN_VERSION_MINOR ([0-9]+))")
+var versionTxt = regexp.MustCompile("^[0-9]+\\.[0-9]+")
 
 func main() {
        flag.Parse()
-       out, err := os.Create(outpath)
+       genVersion()
+       genWrappers()
+}
+
+func getVersion() string {
+       _, err := ioutil.ReadFile(path.Join(*include, "proton/version.h.in"))
+       if err == nil {
+               // We are using the headers in git sources, get the version.txt
+               vt, err := ioutil.ReadFile(path.Join(*include, 
"../../version.txt"))
+               panicIf(err)
+               return versionTxt.FindString(string(vt))
+       }
+       vh, err := ioutil.ReadFile(path.Join(*include, "proton/version.h"))
+       if err == nil {
+               // We are using installed headers
+               return 
strings.Join(versionH.FindStringSubmatch(string(vh))[1:], ".")
+       }
+       panic(err)
+}
+
+func genVersion() {
+       version := getVersion()
+       if minVersion != version {
+               panic(fmt.Errorf("Generating from wrong version %v, expected 
%v", version, minVersion))
+       }
+       out, err := os.Create("src/qpid.apache.org/amqp/version.go")
+       panicIf(err)
+       defer out.Close()
+       splitVersion := strings.Split(minVersion, ".")
+       fmt.Fprintf(out, copyright+`
+
+package amqp
+
+// Version check for proton library.
+// Done here because this is the lowest-level dependency for all the proton Go 
packages.
+
+// #include <proton/version.h>
+// #if PN_VERSION_MAJOR == %s && PN_VERSION_MINOR < %s
+// #error packages qpid.apache.org/... require Proton-C library version 0.10 
or greater
+// #endif
+import "C"
+`, splitVersion[0], splitVersion[1])
+}
+
+func genWrappers() {
+       outPath := "src/qpid.apache.org/proton/wrappers_gen.go"
+       out, err := os.Create(outPath)
        panicIf(err)
        defer out.Close()
 
@@ -56,11 +111,13 @@ import (
   "unsafe"
 )
 
-// #include <proton/types.h>
-// #include <proton/error.h>
 // #include <proton/condition.h>
+// #include <proton/error.h>
 // #include <proton/event.h>
+// #include <proton/types.h>
 // #include <stdlib.h>
+import "C"
+
 `)
        for _, api := range apis {
                fmt.Fprintf(out, "// #include <proton/%s.h>\n", api)
@@ -79,13 +136,7 @@ import (
                apiWrapFns(api, header, out)
        }
        out.Close()
-
-       // Run gofmt.
-       cmd := exec.Command("gofmt", "-w", outpath)
-       cmd.Stdout = os.Stdout
-       cmd.Stderr = os.Stderr
-       err = cmd.Run()
-       if err != nil {
+       if err := exec.Command("gofmt", "-w", outPath).Run(); err != nil {
                fmt.Fprintf(os.Stderr, "gofmt: %s", err)
                os.Exit(1)
        }
@@ -161,7 +212,7 @@ func panicIf(err error) {
 }
 
 func readHeader(name string) string {
-       s, err := ioutil.ReadFile(path.Join(includeProton, name+".h"))
+       s, err := ioutil.ReadFile(path.Join(*include, "proton", name+".h"))
        panicIf(err)
        return string(s)
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c94301d5/proton-c/bindings/go/src/qpid.apache.org/amqp/version.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/version.go 
b/proton-c/bindings/go/src/qpid.apache.org/amqp/version.go
index cefa904..bf33d2b 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/version.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/version.go
@@ -17,13 +17,19 @@ specific language governing permissions and limitations
 under the License.
 */
 
+//
+// NOTE: DO NOT EDIT. This file was generated by genwrap.go from the proton 
header files.
+// Update the generator and re-run if you need to modify this code.
+//
+
+
 package amqp
 
 // Version check for proton library.
 // Done here because this is the lowest-level dependency for all the proton Go 
packages.
 
 // #include <proton/version.h>
-// #if PN_VERSION_MINOR < 10
+// #if PN_VERSION_MAJOR == 0 && PN_VERSION_MINOR < 10
 // #error packages qpid.apache.org/... require Proton-C library version 0.10 
or greater
 // #endif
 import "C"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c94301d5/proton-c/bindings/go/src/qpid.apache.org/proton/wrappers_gen.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/proton/wrappers_gen.go 
b/proton-c/bindings/go/src/qpid.apache.org/proton/wrappers_gen.go
index a6c6635..0db04c8 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/proton/wrappers_gen.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/proton/wrappers_gen.go
@@ -29,11 +29,13 @@ import (
        "unsafe"
 )
 
-// #include <proton/types.h>
-// #include <proton/error.h>
 // #include <proton/condition.h>
+// #include <proton/error.h>
 // #include <proton/event.h>
+// #include <proton/types.h>
 // #include <stdlib.h>
+import "C"
+
 // #include <proton/session.h>
 // #include <proton/link.h>
 // #include <proton/delivery.h>
@@ -78,13 +80,6 @@ const (
        ETransportHeadClosed    EventType = C.PN_TRANSPORT_HEAD_CLOSED
        ETransportTailClosed    EventType = C.PN_TRANSPORT_TAIL_CLOSED
        ETransportClosed        EventType = C.PN_TRANSPORT_CLOSED
-       EConnectionWake         EventType = C.PN_CONNECTION_WAKE
-       EListenerAccept         EventType = C.PN_LISTENER_ACCEPT
-       EListenerClose          EventType = C.PN_LISTENER_CLOSE
-       EProactorInterrupt      EventType = C.PN_PROACTOR_INTERRUPT
-       EProactorTimeout        EventType = C.PN_PROACTOR_TIMEOUT
-       EProactorInactive       EventType = C.PN_PROACTOR_INACTIVE
-       EListenerOpen           EventType = C.PN_LISTENER_OPEN
 )
 
 func (e EventType) String() string {
@@ -150,20 +145,6 @@ func (e EventType) String() string {
                return "TransportTailClosed"
        case C.PN_TRANSPORT_CLOSED:
                return "TransportClosed"
-       case C.PN_CONNECTION_WAKE:
-               return "ConnectionWake"
-       case C.PN_LISTENER_ACCEPT:
-               return "ListenerAccept"
-       case C.PN_LISTENER_CLOSE:
-               return "ListenerClose"
-       case C.PN_PROACTOR_INTERRUPT:
-               return "ProactorInterrupt"
-       case C.PN_PROACTOR_TIMEOUT:
-               return "ProactorTimeout"
-       case C.PN_PROACTOR_INACTIVE:
-               return "ProactorInactive"
-       case C.PN_LISTENER_OPEN:
-               return "ListenerOpen"
        }
        return "Unknown"
 }
@@ -373,15 +354,6 @@ func (l Link) SetDrain(drain bool) {
 func (l Link) Draining() bool {
        return bool(C.pn_link_draining(l.pn))
 }
-func (l Link) MaxMessageSize() uint64 {
-       return uint64(C.pn_link_max_message_size(l.pn))
-}
-func (l Link) SetMaxMessageSize(size uint64) {
-       C.pn_link_set_max_message_size(l.pn, C.uint64_t(size))
-}
-func (l Link) RemoteMaxMessageSize() uint64 {
-       return uint64(C.pn_link_remote_max_message_size(l.pn))
-}
 
 // Wrappers for declarations in delivery.h
 
@@ -529,9 +501,6 @@ func (c Condition) RedirectHost() string {
 func (c Condition) RedirectPort() int {
        return int(C.pn_condition_redirect_port(c.pn))
 }
-func (c Condition) Copy(src Condition) int {
-       return int(C.pn_condition_copy(c.pn, src.pn))
-}
 
 // Wrappers for declarations in terminus.h
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c94301d5/proton-c/bindings/go/test-versions.sh
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/test-versions.sh 
b/proton-c/bindings/go/test-versions.sh
new file mode 100755
index 0000000..0022ce3
--- /dev/null
+++ b/proton-c/bindings/go/test-versions.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# Takes a list of install prefixes and tests the go source under the current 
directory
+# against the proton install in each prefix.
+#
+# NOTE: This script will fail if it finds proton headers or libraries 
installed in standard
+# places or on the existing paths, to avoid possible confusion.
+#
+
+for VAR in LD_LIBRARY_PATH LIBRARY_PATH C_INCLUDE_PATH; do
+    declare OLD_${VAR}=${!VAR};
+done
+
+prefix() {
+    prefix=$1
+    export LD_LIBRARY_PATH="$prefix/lib64:$prefix/lib:$OLD_LD_LIBRARY_PATH"
+    export LIBRARY_PATH="$prefix/lib64:$prefix/lib:$OLD_LIBRARY_PATH"
+    export C_INCLUDE_PATH="$prefix/include:$OLD_C_INCLUDE_PATH"
+}
+
+TEMP=$(mktemp -d)
+trap "rm -rf $TEMP"  EXIT
+set -o pipefail
+
+cat > $TEMP/test.c  <<EOF
+#include <proton/connection.h>
+int main(int c, char **a) { return 0; }
+EOF
+cc $TEMP/test.c 2> /dev/null && {
+    echo "cc found proton in include path"; cc -E | grep proton/connection.h | 
head -n1; exit 1; } 1>&2
+
+cat > $TEMP/test.c  <<EOF
+int main(int c, char **a) { return 0; }
+EOF
+cc -lqpid-proton $TEMPC 2>/dev/null && { echo "cc found proton in library 
path" 1>&2 ; exit 1; }
+
+for P in "$@"; do
+    (
+        case $P in
+            /*) ;;
+            *) P=$PWD/$P;;
+        esac
+        test -d $P || { echo "no such directory: $P"; continue; }
+        echo ==== $P
+        prefix $P
+        export GOPATH=$PWD
+        git clean -dfx
+        go test qpid.apache.org/...
+    )
+done


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to