Przeglądaj źródła

go.mod: rely on go get support for modules instead of local paths

In CL 136736, we renamed the import path as github.com/golang/protobuf/v2
so that it can be fetched as a module with "go get". Use that mechanism to
introduce the dependency on v2 instead of using the replace feature to point
at a local checkout.

While we are at it, also fix Travis:
* The test.bash script is now an exact copy of the one in v2,
except that we do not run "./internal/cmd/generate-types".
* The .travis.yml config is now an exact copy of the one in the v2
where it simply delegates dependency management and testing to test.bash.

The v2 dependency can be updated to use the latest by running:
	go get github.com/golang/protobuf/v2@api-v2

Change-Id: I2284d0bae82afc5306c91977aa44d09f7e5a41cc
Reviewed-on: https://go-review.googlesource.com/136737
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai 7 lat temu
rodzic
commit
a4da01d008
5 zmienionych plików z 62 dodań i 63 usunięć
  1. 4 30
      .travis.yml
  2. 1 3
      go.mod
  3. 2 0
      go.sum
  4. 1 1
      proto/lib.go
  5. 54 29
      test.bash

+ 4 - 30
.travis.yml

@@ -1,31 +1,5 @@
-sudo: false
-language: go
-go:
-- 1.6.x
-- 1.10.x
-- 1.x
-
-install:
-  - go get -v -d google.golang.org/grpc
-  - go get -v -d -t github.com/golang/protobuf/...
-  - curl -L https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip -o /tmp/protoc.zip
-  - unzip /tmp/protoc.zip -d "$HOME"/protoc
-  - mkdir -p "$HOME"/src && ln -s "$HOME"/protoc "$HOME"/src/protobuf
-
-env:
-  - PATH=$HOME/protoc/bin:$PATH
-
 script:
-  - make all
-  - make regenerate
-  # TODO(tamird): When https://github.com/travis-ci/gimme/pull/130 is
-  # released, make this look for "1.x".
-  - if [[ "$TRAVIS_GO_VERSION" == 1.10* ]]; then
-      if [[ "$(git status --porcelain 2>&1)" != "" ]]; then
-        git status >&2;
-        git diff -a >&2;
-        exit 1;
-      fi;
-      echo "git status is clean.";
-    fi;
-  - make test
+  - ./test.bash
+cache:
+  directories:
+  - .cache

+ 1 - 3
go.mod

@@ -1,10 +1,8 @@
 module github.com/golang/protobuf
 
 require (
+	github.com/golang/protobuf/v2 v2.0.0-20180924161150-01ab29648ebc
 	golang.org/x/net v0.0.0-20180906233101-161cd47e91fd // indirect
 	golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
 	google.golang.org/genproto v0.0.0-20180831171423-11092d34479b
-	google.golang.org/proto v0.0.0
 )
-
-replace google.golang.org/proto => ./.cache/go-protobuf-v2

+ 2 - 0
go.sum

@@ -1,4 +1,6 @@
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf/v2 v2.0.0-20180924161150-01ab29648ebc h1:F2G3fOGA3Jscrr7lwzx8EbcX/KKvPHDWUL1LQO+EsXE=
+github.com/golang/protobuf/v2 v2.0.0-20180924161150-01ab29648ebc/go.mod h1:pUFc/zvPj/qlI5nj8gEgsCPCTpICLT32W2c/kQ1v5HU=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 golang.org/x/net v0.0.0-20180821023952-922f4815f713/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=

+ 1 - 1
proto/lib.go

@@ -274,7 +274,7 @@ import (
 
 	// Add a bogus dependency on the v2 API to ensure the Go toolchain does not
 	// remove our dependency from the go.mod file.
-	_ "google.golang.org/proto/reflect/protoreflect"
+	_ "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
 // RequiredNotSetError is an error type returned by either Marshal or Unmarshal.

+ 54 - 29
test.bash

@@ -31,51 +31,76 @@ if [ ! -d $PROTOBUF_DIR ]; then
 fi
 register_binary conformance-test-runner $PROTOBUF_DIR/conformance/conformance-test-runner
 register_binary protoc $PROTOBUF_DIR/src/protoc
+# Allow protoc to find google/protobuf/*.proto.
+rm -rf $PROTOBUF_DIR/src/include
+mkdir -p $PROTOBUF_DIR/src/include
+ln -s ../google $PROTOBUF_DIR/src/include/google
 
-# Download and update the v2 golang/protobuf code.
-if [ ! -d go-protobuf-v2 ]; then
-	print "download v2 golang/protobuf"
-	git clone https://go.googlesource.com/protobuf go-protobuf-v2
-fi
-print "update v2 golang/protobuf"
-(cd go-protobuf-v2 && git fetch && git pull)
-
-# Download the Go toolchain.
-GO_VERSION=go1.11
-if [ ! -d $GO_VERSION ]; then
-	print "download $GO_VERSION"
-	GOOS=$(uname | tr '[:upper:]' '[:lower:]')
-	(mkdir $GO_VERSION && curl -s -L https://dl.google.com/go/$GO_VERSION.$GOOS-amd64.tar.gz | tar -zxf - -C $GO_VERSION --strip-components 1) || exit 1
-fi
-register_binary go $GO_VERSION/bin/go
-register_binary gofmt $GO_VERSION/bin/gofmt
+# Download each Go toolchain version.
+GO_LATEST=go1.11
+GO_VERSIONS=(go1.9.7 go1.10.3 $GO_LATEST)
+for GO_VERSION in ${GO_VERSIONS[@]}; do
+	if [ ! -d $GO_VERSION ]; then
+		print "download $GO_VERSION"
+		GOOS=$(uname | tr '[:upper:]' '[:lower:]')
+		(mkdir $GO_VERSION && curl -s -L https://dl.google.com/go/$GO_VERSION.$GOOS-amd64.tar.gz | tar -zxf - -C $GO_VERSION --strip-components 1) || exit 1
+	fi
+	register_binary $GO_VERSION $GO_VERSION/bin/go
+done
+register_binary go $GO_LATEST/bin/go
+register_binary gofmt $GO_LATEST/bin/gofmt
 
 # Travis-CI sets GOROOT, which confuses later invocations of the Go toolchains.
 # Explicitly clear GOROOT, so each toolchain uses their default GOROOT.
 unset GOROOT
 
 # Setup GOPATH for pre-module support.
+export GOPATH=$TEST_DIR/gopath
 MODULE_PATH=$(cd $REPO_ROOT && go list -m -f "{{.Path}}")
-rm -f gopath/src/$MODULE_PATH # best-effort delete
+rm -rf gopath/src # best-effort delete
 mkdir -p gopath/src/$(dirname $MODULE_PATH)
 (cd gopath/src/$(dirname $MODULE_PATH) && ln -s $REPO_ROOT $(basename $MODULE_PATH))
-export GOPATH=$TEST_DIR/gopath
 
 # Download dependencies using modules.
 # For pre-module support, dump the dependencies in a vendor directory.
 (cd $REPO_ROOT && go mod tidy && go mod vendor) || exit 1
 
-# Build and run all targets
+# Run tests across every supported version of Go.
+LABELS=()
+PIDS=()
+OUTS=()
+function cleanup() { for OUT in ${OUTS[@]}; do rm $OUT; done; }
+trap cleanup EXIT
+for GO_VERSION in ${GO_VERSIONS[@]}; do
+	# Run the go command in a background process.
+	function go() {
+		# Use a per-version Go cache to work around bugs in Go build caching.
+		# See https://golang.org/issue/26883
+		GO_CACHE="$TEST_DIR/cache.$GO_VERSION"
+		LABELS+=("$(echo "$GO_VERSION $@")")
+		OUT=$(mktemp)
+		(cd $GOPATH/src/$MODULE_PATH && GOCACHE=$GO_CACHE $GO_VERSION "$@" &> $OUT) &
+		PIDS+=($!)
+		OUTS+=($OUT)
+	}
+
+	go build ./...
+	go test -race ./...
+	go test -race -tags purego ./...
+	go test -race -tags proto1_legacy ./...
+
+	unset go # to avoid confusing later invocations of "go"
+done
+
+# Wait for all processes to finish.
 RET=0
-function go() {
-	print "$GO_VERSION $@"
-	# Use a per-version Go cache to work around bugs in Go build caching.
-	# See https://golang.org/issue/26883
-	GO_CACHE="$TEST_DIR/cache.$GO_VERSION"
-	(cd $GOPATH/src/$MODULE_PATH && GOCACHE=$GO_CACHE $GO_VERSION "$@") || RET=1
-}
-go build ./...
-go test ./...
+for I in ${!PIDS[@]}; do
+	print "${LABELS[$I]}"
+	if ! wait ${PIDS[$I]}; then
+		cat ${OUTS[$I]} # only output upon error
+		RET=1
+	fi
+done
 
 # Run commands that produce output when there is a failure.
 function check() {