diff --git a/README b/README deleted file mode 100644 index 91af79e..0000000 --- a/README +++ /dev/null @@ -1,52 +0,0 @@ -The contents of this repository are now part of Apache Thrift as of version 0.7 or commit revision 1072478 (https://issues.apache.org/jira/browse/THRIFT-625). - -This project will continued to be maintained for any further developments for Thrift for Go as needed. - -Add this git repository to your thrift checkout. It will overwrite a few files to add options for Go. - -Currently generates code for the following protocols: -1) Binary Protocol (with test cases) -2) Fast Binary Protocol (with test cases) -3) Standard Thrift JSON Protocol (with test cases) -4) A (custom) simple JSON Protocol (with test cases) -5) Services (compiles and runs against Java, assumed to work elsewhere) - -Tested on Mac OS X 10.6 (Snow Leopard) - -To install in your Go Repository do: -goinstall github.com/pomack/thrift4go/lib/go/thrift -goinstall -a -log - -4 files for thrift compiler (last tested on February 17, 2010): -1) configure.ac -2) lib/Makefile.am -3) compiler/cpp/Makefile.am -4) compiler/cpp/src/generate/t_go_generator.cc - -A tutorial has been created in the thrift4go/tutorial/go/src directory -To use this tutorial, run - thrift -r --gen go --gen java /tutorial/tutorial.thrift -Build the files in the gen-go/ directory using gomake install -Build the files in the /tutorial/go directory using gomake install -Run the server from /tutorial/go/TutorialServerClient and run the client from either /tutorial/go/TutorialServerClient or gen-go/tutorial/Calculator/Calculator-remote -Make sure you specify the same protocol for both the server and client - -Here's a basic walkthrough: - - thrift --gen go --gen java /test/ThriftTest.thrift - - this will create gen-go/thrift/test/*.go and associated files/directories - - * gen-go/thrift/test/ThriftTest.go shows a service and client base implementation with the associated interfaces and the ability to send/receive or serialize/deserialize as necessary. - - * ThriftTestClient is a client library designed to access the ThriftTest service. No changes would need to be made here. - - * A ThriftTest/ThriftTest-remote.go and associated Makefile is also made available so you can access a remote service implementing the ThriftTest interface and see how the client side works under the covers. The command-line arguments use the custom JSON parser, so you can just pass in JSON strings as arguments when you need to populate a struct, which I find better than any other alternative. - - * ThriftTestProcessor implements the server side and you would want to implement the server handlers using the function: NewThriftTestProcessor() - - * You just pass in your handler that implements the IThriftTest interface and make sure you import the appropriate package. Package directories/names are shown in the relevant Makefile. - - * One unique thing about Go is that to have a publicly available function/variable, the first letter has to be capitalized, so all exportable functions/variables have the first letter capitalized, but since the thrift files normally don't, they assume any serialization uses the capitalization found in the thrift file itself. - - diff --git a/README.md b/README.md new file mode 100644 index 0000000..44b3c37 --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +The contents of this repository were originally incorporated into Apache Thrift +as of version 0.7 or commit revision 1072478.* However, unfortunately upstream +development ceased and necessitated continued development here; thusly, these +files have been rebased against Thrift revision 1362341 at +http://svn.apache.org/repos/asf/thrift/tags/thrift-0.8.0. + +This project will continued to be maintained for any further developments for +Thrift for Go as needed (e.g., Go Version 1 compatibility). + +Add this Git repository to your Thrift checkout. It will overwrite a few files +to add options for Go. + +Currently generates code for the following protocols: + +1. Binary Protocol (with test cases) +2. Fast Binary Protocol (with test cases) +3. Standard Thrift JSON Protocol (with test cases) +4. A (custom) simple JSON Protocol (with test cases) +5. Services (compiles and runs against Java, assumed to work elsewhere) + +Tested on Mac OS X 10.6 (Snow Leopard) and Linux ca. 2010 derivatives. + +To install locally, perform the following: + ```go get github.com/pomack/thrift4go/lib/go/thrift``` + +5 files for thrift compiler (last tested on July 18, 2012): + +1. ```configure.ac``` +2. ```lib/Makefile.am``` +3. ```lib/go/Makefile.am``` +4. ```compiler/cpp/Makefile.am``` +5. ```compiler/cpp/src/generate/t_go_generator.cc``` + +A tutorial has been created in the thrift4go/tutorial/go/src directory. + +To use this tutorial, run the following: + ```thrift -r --gen go /tutorial/tutorial.thrift``` +Build the files in the ```gen-go``` directory using ```go install``` as +appropriate. +Build the files in the ```/tutorial/go``` directory with +```go install``` as appropriate. +Run the server from ```/tutorial/go/TutorialServerClient``` and +run the client from either +```/tutorial/go/TutorialServerClient``` or +```gen-go/tutorial/Calculator/Calculator-remote```. + +Make sure you specify the same protocol for both the server and client. + +# Basic Walkthrough + +```thrift --gen go /test/ThriftTest.thrift``` + +This will create ```gen-go/thrift/test/*.go``` and associated files/directories. + +- ```gen-go/thrift/test/ThriftTest.go``` shows a service and client base +implementation with the associated interfaces and the ability to send/receive +or serialize/deserialize as necessary. + +- ThriftTestClient is a client library designed to access the ThriftTest +service. No changes would need to be made here. + +- A ```ThriftTest/ThriftTest-remote.go``` and associated Makefile is also made +available so you can access a remote service implementing the ThriftTest +interface and see how the client side works under the covers. The command-line +arguments use the custom JSON parser, so you can just pass in JSON strings as +arguments when you need to populate a struct, which I find better than any +other alternative. + +- ThriftTestProcessor implements the server side and you would want to implement +the server handlers using ```NewThriftTestProcessor()```. + +- You just pass in your handler that implements the ```IThriftTest``` interface +and make sure you import the appropriate package. Package directories/names +are shown in the relevant Makefile. + +- One unique thing about Go is that to have a publicly available +function/variable, the first letter has to be capitalized, so all exportable +functions/variables have the first letter capitalized, but since the Thrift +files normally don't, they assume any serialization uses the capitalization +found in the Thrift interface definition file itself. + +# Areas for Future Assistance + +- Providing qualification tests that automatically build against Thrift stable +as well as HEAD. + +- Improving idiomaticness of generated Thrift. + +- Generating Go interface code that would comply with ```gofmt``` tool. + +# Continuous Integration + +[![Build Status](https://secure.travis-ci.org/pomack/thrift4go.png?branch=master)](http://travis-ci.org/pomack/thrift4go) + + +[*] - See https://issues.apache.org/jira/browse/THRIFT-625. diff --git a/configure.ac b/configure.ac index 0f05854..7b112fa 100644 --- a/configure.ac +++ b/configure.ac @@ -17,13 +17,13 @@ # under the License. # -AC_PREREQ(2.61) +AC_PREREQ(2.65) -AC_INIT([thrift], [0.7.0-dev]) +AC_INIT([thrift], [0.8.0]) AC_CONFIG_AUX_DIR([.]) -AM_INIT_AUTOMAKE +AM_INIT_AUTOMAKE([1.9 tar-ustar]) PKG_PROG_PKG_CONFIG AC_ARG_VAR([PY_PREFIX], [Prefix for installing Python modules. @@ -56,9 +56,16 @@ AC_ARG_VAR([PHP_CONFIG_PREFIX], Default = "/etc/php.d"]) AS_IF([test "x$PHP_CONFIG_PREFIX" = x], [PHP_CONFIG_PREFIX="/etc/php.d"]) +AC_ARG_VAR([INSTALLDIRS], [When installing Perl modules, specifies which + of the sets of installation directories + to choose: perl, site or vendor. + Default = "vendor"]) +AS_IF([test "x$INSTALLDIRS" = x], [INSTALLDIRS="vendor"]) + AC_ARG_VAR([PERL_PREFIX], [Prefix for installing Perl modules. (Normal --prefix is ignored for Perl because Perl has different conventions.) + Ignored, when INSTALLDIRS set to site or vendor. Default = "/usr/local/lib"]) AS_IF([test "x$PERL_PREFIX" = x], [PERL_PREFIX="/usr/local"]) @@ -71,16 +78,8 @@ AC_SUBST(CABAL_CONFIGURE_FLAGS) AC_ARG_VAR([GOROOT], [Prefix for the Go source directory. (Normal --prefix is ignored for Go because Go has different conventions.) - Default = "/usr/local/share/go"]) -AS_IF([test "x$GOROOT" = x], [GOROOT="/usr/local/share/go"]) - -AC_ARG_VAR([GOARCH], [Architecture default for Go. - Default = "amd64"]) -AS_IF([test "x$GOARCH" = x], [GOARCH="amd64"]) - -AC_ARG_VAR([GOBIN], [Binary directory for Go. - Default = "/usr/local/bin"]) -AS_IF([test "x$GOBIN" = x], [GOBIN="/usr/local/bin"]) + Default = "/usr/local/go"]) +AS_IF([test "x$GOROOT" = x], [GOROOT="/usr/local/go"]) AC_PROG_CC AC_PROG_CPP @@ -102,7 +101,7 @@ AX_THRIFT_LIB(cpp, [C++], yes) have_cpp=no if test "$with_cpp" = "yes"; then AX_BOOST_BASE([1.33.1]) - if test "x$succeeded" == "xyes" ; then + if test "x$succeeded" = "xyes" ; then have_cpp="yes" fi @@ -141,15 +140,7 @@ AX_THRIFT_LIB(java, [Java], yes) if test "$with_java" = "yes"; then AX_JAVAC_AND_JAVA AC_PATH_PROG([ANT], [ant]) - AX_CHECK_JAVA_CLASS(org.slf4j.Logger) - have_slf4j="$success" - AX_CHECK_JAVA_CLASS(org.slf4j.impl.SimpleLogger) - have_slf4j_simple="$success" - AX_CHECK_JAVA_CLASS(org.apache.commons.lang.builder.HashCodeBuilder) - have_hashcode="$success" - if test "x$have_slf4j_simple" = "xyes" && test "x$have_slf4j" = "xyes" && test "x$have_hashcode" = "xyes" ; then - ANT_FLAGS="$ANT_FLAGS -Dnoivy=" - fi + AX_CHECK_ANT_VERSION($ANT, 1.7) AC_SUBST(CLASSPATH) AC_SUBST(ANT_FLAGS) if test "x$JAVAC" != "x" && test "x$JAVAC" != "x" && test "x$ANT" != "x" ; then @@ -221,13 +212,14 @@ AX_THRIFT_LIB(ruby, [Ruby], yes) have_ruby=no if test "$with_ruby" = "yes"; then AC_PATH_PROG([RUBY], [ruby]) - AC_PATH_PROG([RSPEC], [spec]) - if test "x$RUBY" != "x" ; then + AC_PATH_PROG([RAKE], [rake]) + AC_PATH_PROG([BUNDLER], [bundle]) + if test "x$RUBY" != "x" -a "x$RAKE" != "x"; then have_ruby="yes" fi fi AM_CONDITIONAL(WITH_RUBY, [test "$have_ruby" = "yes"]) -AM_CONDITIONAL(HAVE_RSPEC, [test "x$RSPEC" != "x"]) +AM_CONDITIONAL(HAVE_BUNDLER, [test "x$BUNDLER" != "x"]) AX_THRIFT_LIB(haskell, [Haskell], yes) have_haskell=no @@ -249,34 +241,20 @@ AM_CONDITIONAL(WITH_HASKELL, [test "$have_haskell" = "yes"]) AX_THRIFT_LIB(go, [Go], yes) if test "$with_go" = "yes"; then - case X"$GOARCH" in - Xamd64) - GOARCH_NUM=6 - ;; - X386) - GOARCH_NUM=8 - ;; - Xarm) - GOARCH_NUM=5 - ;; - *) - GOARCH_NUM=6 - ;; - esac - GO_C=${GOBIN}/${GOARCH_NUM}g - GO_L=${GOBIN}/${GOARCH_NUM}l - GOMAKE=${GOBIN}/gomake - GOINSTALL=${GOBIN}/goinstall - AC_PATH_PROG([GO_C], [${GOARCH_NUM}g]) - AC_PATH_PROG([GO_L], [${GOARCH_NUM}l]) - AC_PATH_PROG([GOMAKE], [gomake]) - AC_PATH_PROG([GOINSTALL], [goinstall]) - if [[ -x "$GO_C" -a -x "$GO_L" -a -x "$GOMAKE" -a -x "$GOINSTALL" ]] ; then + GO=${GOROOT}/bin/go + AC_PATH_PROG([GO], [${GO}]) + if [[ -x "$GO" ]] ; then have_go="yes" fi fi AM_CONDITIONAL(WITH_GO, [test "$have_go" = "yes"]) +have_tests=yes +if test "$with_tests" = "no"; then + have_tests="no" +fi +AM_CONDITIONAL(WITH_TESTS, [test "$have_tests" = "yes"]) + AC_C_CONST AC_C_INLINE AC_C_VOLATILE @@ -298,9 +276,15 @@ AC_CHECK_HEADERS([stddef.h]) AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([sys/time.h]) +AC_CHECK_HEADERS([sys/un.h]) +AC_CHECK_HEADERS([sys/poll.h]) +AC_CHECK_HEADERS([sys/resource.h]) AC_CHECK_HEADERS([unistd.h]) AC_CHECK_HEADERS([libintl.h]) AC_CHECK_HEADERS([malloc.h]) +AC_CHECK_HEADERS([openssl/ssl.h]) +AC_CHECK_HEADERS([openssl/rand.h]) +AC_CHECK_HEADERS([openssl/x509v3.h]) AC_CHECK_LIB(pthread, pthread_create) dnl NOTE(dreiss): I haven't been able to find any really solid docs @@ -311,6 +295,21 @@ dnl and we haven't yet found a system where this is a problem. AC_CHECK_LIB(rt, clock_gettime) AC_CHECK_LIB(socket, setsockopt) +if test "$have_cpp" = "yes" ; then +# mingw toolchain used to build "Thrift Compiler for Windows" +# does not support libcrypto, so we just check if we building the cpp library +AC_CHECK_LIB(crypto, + BN_init, + [AC_CHECK_LIB(ssl, + SSL_ctrl, + [LIBS="-lssl -lcrypto $LIBS"], + [AC_MSG_ERROR(["Error: libssl required"])], + -lcrypto + )], + [AC_MSG_ERROR(["Error: libcrypto required."])] +) +fi + AC_TYPE_INT16_T AC_TYPE_INT32_T AC_TYPE_INT64_T @@ -382,45 +381,6 @@ if false ; then AC_FUNC_ERROR_AT_LINE fi -AX_THRIFT_GEN(cpp, [C++], yes) -AM_CONDITIONAL([THRIFT_GEN_cpp], [test "$ax_thrift_gen_cpp" = "yes"]) -AX_THRIFT_GEN(c_glib, [C (GLib)], yes) -AM_CONDITIONAL([THRIFT_GEN_c_glib], [test "$ax_thrift_gen_c_glib" = "yes"]) -AX_THRIFT_GEN(java, [Java], yes) -AM_CONDITIONAL([THRIFT_GEN_java], [test "$ax_thrift_gen_java" = "yes"]) -AX_THRIFT_GEN(as3, [AS3], yes) -AM_CONDITIONAL([THRIFT_GEN_as3], [test "$ax_thrift_gen_as3" = "yes"]) -AX_THRIFT_GEN(csharp, [C#], yes) -AM_CONDITIONAL([THRIFT_GEN_csharp], [test "$ax_thrift_gen_csharp" = "yes"]) -AX_THRIFT_GEN(py, [Python], yes) -AM_CONDITIONAL([THRIFT_GEN_py], [test "$ax_thrift_gen_py" = "yes"]) -AX_THRIFT_GEN(rb, [Ruby], yes) -AM_CONDITIONAL([THRIFT_GEN_rb], [test "$ax_thrift_gen_rb" = "yes"]) -AX_THRIFT_GEN(perl, [Perl], yes) -AM_CONDITIONAL([THRIFT_GEN_perl], [test "$ax_thrift_gen_perl" = "yes"]) -AX_THRIFT_GEN(php, [PHP], yes) -AM_CONDITIONAL([THRIFT_GEN_php], [test "$ax_thrift_gen_php" = "yes"]) -AX_THRIFT_GEN(erl, [Erlang], yes) -AM_CONDITIONAL([THRIFT_GEN_erl], [test "$ax_thrift_gen_erl" = "yes"]) -AX_THRIFT_GEN(cocoa, [Cocoa], yes) -AM_CONDITIONAL([THRIFT_GEN_cocoa], [test "$ax_thrift_gen_cocoa" = "yes"]) -AX_THRIFT_GEN(st, [Smalltalk], yes) -AM_CONDITIONAL([THRIFT_GEN_st], [test "$ax_thrift_gen_st" = "yes"]) -AX_THRIFT_GEN(ocaml, [OCaml], yes) -AM_CONDITIONAL([THRIFT_GEN_ocaml], [test "$ax_thrift_gen_ocaml" = "yes"]) -AX_THRIFT_GEN(hs, [Haskell], yes) -AM_CONDITIONAL([THRIFT_GEN_hs], [test "$ax_thrift_gen_hs" = "yes"]) -AX_THRIFT_GEN(xsd, [XSD], yes) -AM_CONDITIONAL([THRIFT_GEN_xsd], [test "$ax_thrift_gen_xsd" = "yes"]) -AX_THRIFT_GEN(html, [HTML], yes) -AM_CONDITIONAL([THRIFT_GEN_html], [test "$ax_thrift_gen_html" = "yes"]) -AX_THRIFT_GEN(js, [JavaScript], yes) -AM_CONDITIONAL([THRIFT_GEN_js], [test "$ax_thrift_gen_js" = "yes"]) -AX_THRIFT_GEN(javame, [JavaME], yes) -AM_CONDITIONAL([THRIFT_GEN_javame], [test "$ax_thrift_gen_javame" = "yes"]) -AX_THRIFT_GEN(go, [GO_C], yes) -AM_CONDITIONAL([THRIFT_GEN_go], [test "$ax_thrift_gen_go" = "yes"]) - # --- Coverage hooks --- AC_ARG_ENABLE(coverage, @@ -444,6 +404,24 @@ AC_SUBST(GCOV_CFLAGS) AC_SUBST(GCOV_CXXFLAGS) AC_SUBST(GCOV_LDFLAGS) +AC_ARG_ENABLE(boostthreads, + [ --enable-boostthreads use boost threads, instead of POSIX pthread (experimental) ], + [case "${enableval}" in + yes) ENABLE_BOOSTTHREADS=1 ;; + no) ENABLE_BOOSTTHREADS=0 ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-cov) ;; + esac], + [ENABLE_BOOSTTHREADS=2]) + + +if test "x[$]ENABLE_BOOSTTHREADS" = "x1"; then + AC_MSG_WARN(enable boostthreads) + AC_DEFINE([USE_BOOST_THREAD], [1], [experimental --enable-boostthreads that replaces POSIX pthread by boost::thread]) + LIBS="-lboost_thread $LIBS" +fi + +AM_CONDITIONAL([WITH_BOOSTTHREADS], [test "x[$]ENABLE_BOOSTTHREADS" = "x1"]) + AC_CONFIG_HEADERS(config.h:config.hin) AC_CONFIG_FILES([ @@ -461,15 +439,18 @@ AC_CONFIG_FILES([ lib/c_glib/test/Makefile lib/csharp/Makefile lib/erl/Makefile - lib/erl/src/Makefile + lib/erl/src/thrift.app.src + lib/go/Makefile lib/hs/Makefile lib/java/Makefile + lib/js/test/Makefile lib/perl/Makefile lib/perl/test/Makefile lib/php/Makefile lib/py/Makefile lib/rb/Makefile test/Makefile + test/cpp/Makefile test/hs/Makefile test/py/Makefile test/py.twisted/Makefile @@ -521,7 +502,6 @@ fi if test "$have_ruby" = "yes" ; then echo echo "Using Ruby ................... : $RUBY" - echo "Using rspec .................. : $RSPEC" fi if test "$have_haskell" = "yes" ; then echo @@ -539,10 +519,6 @@ fi if test "$have_go" = "yes" ; then echo echo "Using GOROOT.................. : $GOROOT" - echo "Using GOBIN................... : $GOBIN" - echo "Using GOARCH.................. : $GOARCH" - echo "Using GO Compiler............. : $GO_C" - echo "Using GO Linker............... : $GO_L" fi echo echo "If something is missing that you think should be present," diff --git a/lib/Makefile.am b/lib/Makefile.am index 8538afa..9c9b515 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -33,6 +33,9 @@ endif if WITH_JAVA SUBDIRS += java +# JavaScript unit test depends on java +# so test only if java, ant & co is available +SUBDIRS += js/test endif if WITH_PYTHON @@ -59,12 +62,18 @@ if WITH_PHP SUBDIRS += php endif +if WITH_GO +SUBDIRS += go +endif + # All of the libs that don't use Automake need to go in here # so they will end up in our release tarballs. EXTRA_DIST = \ - cocoa \ - ocaml \ - js \ - as3 \ - st \ - go + as3 \ + cocoa \ + delphi \ + javame \ + js \ + nodejs \ + ocaml \ + st diff --git a/lib/go/Makefile b/lib/go/Makefile.am similarity index 55% rename from lib/go/Makefile rename to lib/go/Makefile.am index 640fc83..66cc5a6 100644 --- a/lib/go/Makefile +++ b/lib/go/Makefile.am @@ -17,26 +17,33 @@ # under the License. # +# N.B.(matttproud): The flag assumptions of this makefile could be improved to +# potentially be more cross-platform compatible. For +# instance, I think the »-t« flag for »cp« may be invalid on +# BSD and Darwin systems. all: install -GOPATH:=$(GOPATH):`pwd` +export GOPATH = $(PWD) +SOURCE = $(GOPATH)/{pkg,src} +DESTINATION = $(DESTDIR)/$(GOROOT) -clean: - GOPATH=$(GOPATH) go clean thrift -install: - GOPATH=$(GOPATH) go install thrift - -/bin/cp -f pkg/$(GOOS)_$(GOARCH)/thrift.* $(GOROOT)/pkg/$(GOOS)_$(GOARCH)/ +clean-local: + go clean thrift -nuke: - GOPATH=$(GOPATH) go clean -i thrift - /bin/rm -rf pkg bin +nuke-local: + go clean -i -r -x thrift + $(RM) -rf bin pkg -test: - GOPATH=$(GOPATH) go test thrift +install-exec-local: test + go install -a -v -x thrift + mkdir -vp "$(DESTINATION)" + cp -av $(SOURCE) -t "$(DESTINATION)" -check: - GOPATH=$(GOPATH) go build thrift +test: check + go test -a -v -x thrift +check-local: + go build -a -v -x thrift