Skip to content

Commit

Permalink
THRIFT-5358: Add go.mod file to root directory
Browse files Browse the repository at this point in the history
Client: go

This unblocks the development under go 1.16+, which starts to complain
when there's no go.mod file in any of the directories.

The current approach is certainly not the best solution ever, for
example it does not run the tests under lib/go/test/tests but copy them
into lib/go/test/gopath/src/sometest and run them there instead, but
those improvements can be done in the future in follow up PRs and this
should be a good enough first step to unblock developments.
  • Loading branch information
fishy committed Mar 24, 2021
1 parent 65ea752 commit b71f11e
Show file tree
Hide file tree
Showing 46 changed files with 169 additions and 144 deletions.
2 changes: 1 addition & 1 deletion build/docker/README.md
Expand Up @@ -178,7 +178,7 @@ Last updated: October 1, 2017
| dart | 2.0.0 | 2.4.0 | |
| delphi | | | Not in CI |
| erlang | 18.3 | 22.0 | |
| go | 1.14.14 | 1.15.7 | |
| go | 1.15.10 | 1.16.2 | |
| haxe | 3.2.1 | 3.4.4 | THRIFT-4352: avoid 3.4.2 |
| java | 1.8.0_191 | 11.0.3 | |
| js | Node.js 6.17.1, V8 5.1.281.111, npm 3.10.10 | Node.js 10.18.0, V8 6.8.275.32, npm 6.13.4 | |
Expand Down
4 changes: 2 additions & 2 deletions build/docker/ubuntu-bionic/Dockerfile
Expand Up @@ -140,9 +140,9 @@ RUN apt-get install -y --no-install-recommends \
libglib2.0-dev

# golang
ENV GOLANG_VERSION 1.15.7
ENV GOLANG_VERSION 1.16.2
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 0d142143794721bb63ce6c8a6180c4062bcf8ef4715e7d6d6609f3a8282629b3
ENV GOLANG_DOWNLOAD_SHA256 542e936b19542e62679766194364f45141fde55169db2d8d01046555ca9eb4b8
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
tar -C /usr/local -xzf golang.tar.gz && \
Expand Down
4 changes: 2 additions & 2 deletions build/docker/ubuntu-disco/Dockerfile
Expand Up @@ -140,9 +140,9 @@ RUN apt-get install -y --no-install-recommends \
libglib2.0-dev

# golang
ENV GOLANG_VERSION 1.15.7
ENV GOLANG_VERSION 1.16.2
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 0d142143794721bb63ce6c8a6180c4062bcf8ef4715e7d6d6609f3a8282629b3
ENV GOLANG_DOWNLOAD_SHA256 542e936b19542e62679766194364f45141fde55169db2d8d01046555ca9eb4b8
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
tar -C /usr/local -xzf golang.tar.gz && \
Expand Down
4 changes: 2 additions & 2 deletions build/docker/ubuntu-xenial/Dockerfile
Expand Up @@ -137,9 +137,9 @@ RUN apt-get install -y --no-install-recommends \
libglib2.0-dev

# golang
ENV GOLANG_VERSION 1.14.14
ENV GOLANG_VERSION 1.15.10
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 6f1354c9040d65d1622b451f43c324c1e5197aa9242d00c5a117d0e2625f3e0d
ENV GOLANG_DOWNLOAD_SHA256 4aa1267517df32f2bf1cc3d55dfc27d0c6b2c2b0989449c96dd19273ccca051d
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
tar -C /usr/local -xzf golang.tar.gz && \
Expand Down
5 changes: 5 additions & 0 deletions go.mod
@@ -0,0 +1,5 @@
module github.com/apache/thrift

go 1.15

require github.com/golang/mock v1.5.0
14 changes: 14 additions & 0 deletions go.sum
@@ -0,0 +1,14 @@
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4 changes: 2 additions & 2 deletions lib/go/Makefile.am
Expand Up @@ -31,13 +31,13 @@ install:
@echo '##############################################################'

check-local:
GOPATH=`pwd` $(GO) test -race ./thrift
$(GO) test -mod=mod -race ./thrift

clean-local:
$(RM) -rf pkg

all-local:
GOPATH=`pwd` $(GO) build ./thrift
$(GO) build -mod=mod ./thrift

EXTRA_DIST = \
thrift \
Expand Down
47 changes: 22 additions & 25 deletions lib/go/test/Makefile.am
Expand Up @@ -17,7 +17,7 @@
# under the License.
#

THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTARGS = -out gopath/src/ --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift,package_prefix=github.com/apache/thrift/lib/go/test/gopath/src/$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift

# Thrift for GO has problems with complex map keys: THRIFT-2063
Expand Down Expand Up @@ -77,40 +77,37 @@ gopath: $(THRIFT) $(THRIFTTEST) \
$(THRIFT) $(THRIFTARGS) -r DuplicateImportsTest.thrift
$(THRIFT) $(THRIFTARGS) EqualsTest.thrift
$(THRIFT) $(THRIFTARGS) ConflictArgNamesTest.thrift
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock || true
sed -i 's/\"context\"/\"golang.org\/x\/net\/context\"/g' gopath/src/github.com/golang/mock/gomock/controller.go || true
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock
ln -nfs ../../../thrift gopath/src/thrift
ln -nfs ../../tests gopath/src/tests
cp -r ./dontexportrwtest gopath/src
touch gopath

check: gopath
GOPATH=`pwd`/gopath $(GO) build \
includestest \
binarykeytest \
servicestest \
typedeffieldtest \
refannotationfieldstest \
errortest \
namestest \
initialismstest \
dontexportrwtest \
ignoreinitialismstest \
unionbinarytest \
conflictnamespacetestsuperthing \
conflict/context/conflict_service-remote \
servicestest/container_test-remote \
duplicateimportstest \
equalstest \
conflictargnamestest
GOPATH=`pwd`/gopath $(GO) test thrift tests dontexportrwtest
$(GO) build -mod=mod \
./gopath/src/includestest \
./gopath/src/binarykeytest \
./gopath/src/servicestest \
./gopath/src/typedeffieldtest \
./gopath/src/refannotationfieldstest \
./gopath/src/errortest \
./gopath/src/namestest \
./gopath/src/initialismstest \
./gopath/src/dontexportrwtest \
./gopath/src/ignoreinitialismstest \
./gopath/src/unionbinarytest \
./gopath/src/conflictnamespacetestsuperthing \
./gopath/src/conflict/context/conflict_service-remote \
./gopath/src/servicestest/container_test-remote \
./gopath/src/duplicateimportstest \
./gopath/src/equalstest \
./gopath/src/conflictargnamestest
$(GO) test -mod=mod github.com/apache/thrift/lib/go/thrift
$(GO) test -mod=mod ./gopath/src/tests ./gopath/src/dontexportrwtest

clean-local:
$(RM) -r gopath ThriftTest.thrift gen-go

client: stubs
$(GO) run TestClient.go
$(GO) run -mod=mod TestClient.go

EXTRA_DIST = \
dontexportrwtest \
Expand Down
12 changes: 2 additions & 10 deletions lib/go/test/fuzz/Makefile.am
Expand Up @@ -18,19 +18,11 @@
#

gopathfuzz: $(THRIFT) fuzz.go
$(THRIFT) -r --gen go ../../../../tutorial/tutorial.thrift
GO111MODULE=on go mod init fuzz
GO111MODULE=on cd gen-go/shared && go mod init shared
GO111MODULE=on cd gen-go/tutorial && go mod init tutorial
GO111MODULE=on go mod edit -replace shared=./gen-go/shared
GO111MODULE=on go mod edit -replace tutorial=./gen-go/tutorial
GO111MODULE=on cd ../../../../lib/go/thrift && go mod init github.com/apache/thrift/lib/go/thrift
GO111MODULE=on go mod edit -replace github.com/apache/thrift/lib/go/thrift=../../../../lib/go/thrift
GO111MODULE=on go mod tidy
$(THRIFT) -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift,package_prefix=github.com/apache/thrift/lib/go/test/fuzz/gen-go/$(COMPILER_EXTRAFLAG) ../../../../tutorial/tutorial.thrift
touch gopathfuzz

check: gopathfuzz
go test -tags gofuzz
go test -mod=mod -tags gofuzz

clean-local:
$(RM) -r gopathfuzz gen-go
Expand Down
4 changes: 2 additions & 2 deletions lib/go/test/fuzz/fuzz.go
Expand Up @@ -24,10 +24,10 @@ package fuzz
import (
"context"
"fmt"
"shared"
"strconv"
"tutorial"

"github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/tutorial"
"github.com/apache/thrift/lib/go/thrift"
)

Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/binary_key_test.go
Expand Up @@ -20,8 +20,9 @@
package tests

import (
"binarykeytest"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/binarykeytest"
)

func TestBinaryMapKeyGeneratesString(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions lib/go/test/tests/client_error_test.go
Expand Up @@ -22,11 +22,12 @@ package tests
import (
"context"
"errors"
"errortest"
"testing"
"thrift"

"github.com/golang/mock/gomock"

"github.com/apache/thrift/lib/go/test/gopath/src/errortest"
"github.com/apache/thrift/lib/go/thrift"
)

// TestCase: Comprehensive call and reply workflow in the client.
Expand Down
2 changes: 1 addition & 1 deletion lib/go/test/tests/conflict_arg_names_test.go
Expand Up @@ -20,7 +20,7 @@
package tests

import (
"conflictargnamestest"
"github.com/apache/thrift/lib/go/test/gopath/src/conflictargnamestest"
)

// We just want to make sure that the conflictargnamestest package compiles.
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/encoding_json_test.go
Expand Up @@ -23,7 +23,8 @@ import (
"encoding"
"encoding/json"
"testing"
"thrifttest"

"github.com/apache/thrift/lib/go/test/gopath/src/thrifttest"
)

func TestEnumIsTextMarshaller(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/equals_test.go
Expand Up @@ -20,9 +20,10 @@
package tests

import (
"equalstest"
"strconv"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/equalstest"
)

func TestEquals(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/gotag_test.go
Expand Up @@ -20,9 +20,10 @@
package tests

import (
"gotagtest"
"reflect"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/gotagtest"
)

func TestDefaultTag(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/ignoreinitialisms_test.go
Expand Up @@ -20,9 +20,10 @@
package tests

import (
"ignoreinitialismstest"
"reflect"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/ignoreinitialismstest"
)

func TestIgnoreInitialismsFlagIsHonoured(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/initialisms_test.go
Expand Up @@ -20,9 +20,10 @@
package tests

import (
"initialismstest"
"reflect"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/initialismstest"
)

func TestThatCommonInitialismsAreFixed(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions lib/go/test/tests/multiplexed_protocol_test.go
Expand Up @@ -21,11 +21,12 @@ package tests

import (
"context"
"multiplexedprotocoltest"
"net"
"testing"
"thrift"
"time"

"github.com/apache/thrift/lib/go/test/gopath/src/multiplexedprotocoltest"
"github.com/apache/thrift/lib/go/thrift"
)

func FindAvailableTCPServerPort() net.Addr {
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/names_test.go
Expand Up @@ -20,9 +20,10 @@
package tests

import (
"namestest"
"reflect"
"testing"

"github.com/apache/thrift/lib/go/test/gopath/src/namestest"
)

func TestThatAttributeNameSubstituionDoesNotOccur(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions lib/go/test/tests/one_way_test.go
Expand Up @@ -23,10 +23,11 @@ import (
"context"
"fmt"
"net"
"onewaytest"
"testing"
"thrift"
"time"

"github.com/apache/thrift/lib/go/test/gopath/src/onewaytest"
"github.com/apache/thrift/lib/go/thrift"
)

func findPort() net.Addr {
Expand Down
8 changes: 5 additions & 3 deletions lib/go/test/tests/optional_fields_test.go
Expand Up @@ -22,10 +22,12 @@ package tests
import (
"bytes"
"context"
gomock "github.com/golang/mock/gomock"
"optionalfieldstest"
"testing"
"thrift"

"github.com/golang/mock/gomock"

"github.com/apache/thrift/lib/go/test/gopath/src/optionalfieldstest"
"github.com/apache/thrift/lib/go/thrift"
)

func TestIsSetReturnFalseOnCreation(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/go/test/tests/protocol_mock.go
Expand Up @@ -24,7 +24,7 @@ package tests

import (
"context"
thrift "thrift"
thrift "github.com/apache/thrift/lib/go/thrift"

gomock "github.com/golang/mock/gomock"
)
Expand Down
5 changes: 3 additions & 2 deletions lib/go/test/tests/protocols_test.go
Expand Up @@ -21,8 +21,9 @@ package tests

import (
"testing"
"thrift"
"thrifttest"

"github.com/apache/thrift/lib/go/test/gopath/src/thrifttest"
"github.com/apache/thrift/lib/go/thrift"
)

func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
Expand Down
10 changes: 6 additions & 4 deletions lib/go/test/tests/required_fields_test.go
Expand Up @@ -21,11 +21,13 @@ package tests

import (
"context"
"github.com/golang/mock/gomock"
"optionalfieldstest"
"requiredfieldtest"
"testing"
"thrift"

"github.com/golang/mock/gomock"

"github.com/apache/thrift/lib/go/test/gopath/src/optionalfieldstest"
"github.com/apache/thrift/lib/go/test/gopath/src/requiredfieldtest"
"github.com/apache/thrift/lib/go/thrift"
)

func TestRequiredField_SucecssWhenSet(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/go/test/tests/struct_args_rets_test.go
Expand Up @@ -20,7 +20,7 @@
package tests

import (
st "servicestest"
st "github.com/apache/thrift/lib/go/test/gopath/src/servicestest"
)

//this function is never called, it will fail to compile if check is failed
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/tests/thrifttest_driver.go
Expand Up @@ -22,7 +22,8 @@ package tests
import (
"reflect"
"testing"
"thrifttest"

"github.com/apache/thrift/lib/go/test/gopath/src/thrifttest"
)

type ThriftTestDriver struct {
Expand Down

3 comments on commit b71f11e

@taelerwatkins-tcn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result of this change, I have had to add a replace directive to our go.mod to avoid the following issue:

go get all: ambiguous import: found package github.com/apache/thrift/lib/go/thrift in multiple modules: github.com/apache/thrift v0.13.0 (~/go/pkg/mod/github.com/apache/thrift@v0.13.0/lib/go/thrift) github.com/apache/thrift/lib/go/thrift v0.0.0-20210120171102-e27e82c46ba4 (~/go/pkg/mod/github.com/apache/thrift/lib/go/thrift@v0.0.0-20210120171102-e27e82c46ba4)

Sort of fixed by adding in go.mod:

replace github.com/apache/thrift v0.13.0 => github.com/apache/thrift/lib/go/thrift v0.0.0-20210120171102-e27e82c46ba4

After which:

go: github.com/apache/thrift/lib/go/thrift@v0.0.0-20210120171102-e27e82c46ba4 used for two different module paths (github.com/apache/thrift and github.com/apache/thrift/lib/go/thrift)

@fishy
Copy link
Member Author

@fishy fishy commented on b71f11e May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taelerwatkins-tcn e27e82c46ba4 is the wrong version to use. It added go.mod to lib/go/thrift (instead of root), the next commit to it, d9fcdd3, removed that.

@taelerwatkins-tcn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, much appreciated. The dep was added to our go.mod file as an //indirect, so it ended up with that commit locked in. Thanks.

Please sign in to comment.