Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Protobuf Dependency #338

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.0
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ jobs:
working_directory: ~/.go_workspace/src/github.com/envoyproxy/protoc-gen-validate/java
environment:
MAVEN_OPTS: -Xms512m -Xmx1024m # Customize the JVM maximum heap limit
GO111MODULE: "on"
CI_GO_VERSION: 1.14.3
steps:
- checkout:
path: ~/.go_workspace/src/github.com/envoyproxy/protoc-gen-validate
- run: sudo rm -rf /usr/local/go && curl -O https://dl.google.com/go/go${CI_GO_VERSION}.linux-amd64.tar.gz && sudo tar -C /usr/local -xzf go${CI_GO_VERSION}.linux-amd64.tar.gz && rm go${CI_GO_VERSION}.linux-amd64.tar.gz && go version
- run: mvn -B verify
- add_ssh_keys:
fingerprints:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bazel-*

/tests/harness/cases/**/*.cc
/tests/harness/cases/**/*.h
/tests/harness-bin

/java/.idea
/java/**/.project
Expand Down
10 changes: 4 additions & 6 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

gazelle(
name = "gazelle",
external = "vendored",
)
# gazelle:prefix github.com/envoyproxy/protoc-gen-validate
gazelle(name = "gazelle")

go_binary(
name = "protoc-gen-validate",
Expand All @@ -20,7 +18,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//module:go_default_library",
"//vendor/github.com/lyft/protoc-gen-star:go_default_library",
"//vendor/github.com/lyft/protoc-gen-star/lang/go:go_default_library",
"@com_github_lyft_protoc_gen_star//:go_default_library",
"@com_github_lyft_protoc_gen_star//lang/go:go_default_library",
],
)
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:xenial

# apt packages
ENV INSTALL_DEPS \
bazel \
build-essential \
ca-certificates \
git \
make \
Expand All @@ -15,16 +15,14 @@ ENV INSTALL_DEPS \
python
RUN apt-get update \
&& apt-get install -y -q --no-install-recommends curl openjdk-8-jdk \
&& echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \
&& curl https://bazel.build/bazel-release.pub.gpg | apt-key add - \
&& apt-get update \
&& apt-get install -y -q --no-install-recommends ${INSTALL_DEPS} \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# protoc
ENV PROTOC_VER=3.6.1
ENV PROTOC_VER=3.12.0
ENV PROTOC_REL=protoc-"${PROTOC_VER}"-linux-x86_64.zip
RUN wget https://github.com/google/protobuf/releases/download/v"${PROTOC_VER}/${PROTOC_REL}" \
&& unzip ${PROTOC_REL} -d protoc \
Expand All @@ -36,7 +34,7 @@ RUN wget https://github.com/google/protobuf/releases/download/v"${PROTOC_VER}/${
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
ENV GORELEASE go1.13.9.linux-amd64.tar.gz
ENV GORELEASE go1.14.3.linux-amd64.tar.gz
RUN wget -q https://dl.google.com/go/$GORELEASE \
&& tar -C $(dirname $GOROOT) -xzf $GORELEASE \
&& rm $GORELEASE \
Expand All @@ -45,7 +43,7 @@ RUN wget -q https://dl.google.com/go/$GORELEASE \
# protoc-gen-go
ENV PGG_PKG "github.com/golang/protobuf/protoc-gen-go"
ENV PGG_PATH "${GOPATH}/src/${PGG_PKG}"
ENV PGG_VER=v1.3.1
ENV PGG_VER=v1.4.2
RUN go get -d ${PGG_PKG} \
&& cd ${PGG_PATH} \
&& git checkout ${PGG_VER} \
Expand All @@ -58,6 +56,7 @@ RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

# buildozer
RUN go get github.com/bazelbuild/buildtools/buildozer
RUN go get github.com/bazelbuild/bazelisk && mv $(go env GOPATH)/bin/bazelisk $(go env GOPATH)/bin/bazel && export PATH=$PATH:$(go env GOPATH)/bin

WORKDIR ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate
COPY . .
Expand Down
107 changes: 0 additions & 107 deletions Gopkg.lock

This file was deleted.

19 changes: 0 additions & 19 deletions Gopkg.toml

This file was deleted.

84 changes: 18 additions & 66 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ GO_IMPORT_SPACES := ${VALIDATE_IMPORT},\
Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,\
Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers,\
Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,\
Mgogoproto/gogo.proto=${PACKAGE}/gogoproto
GO_IMPORT:=$(subst $(space),,$(GO_IMPORT_SPACES))

# protoc-gen-gogo parameters
GOGO_IMPORT_SPACES := ${VALIDATE_IMPORT},\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/types,\
Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto
GOGO_IMPORT:=$(subst $(space),,$(GOGO_IMPORT_SPACES))

.PHONY: build
build: validate/validate.pb.go
# generates the PGV binary and installs it into $$GOPATH/bin
Expand All @@ -40,93 +28,63 @@ build_generation_tests:
bazel build //tests/generation/...

.PHONY: gazelle
gazelle: vendor
gazelle:
# runs gazelle against the codebase to generate Bazel BUILD files
bazel run //:gazelle -- -go_prefix=github.com/envoyproxy/protoc-gen-validate
buildozer 'replace deps //vendor/github.com/golang/protobuf/proto:go_default_library @com_github_golang_protobuf//proto:go_default_library' '//...:%go_library'
buildozer 'replace deps @com_github_golang_protobuf//ptypes:go_default_library_gen @com_github_golang_protobuf//ptypes:go_default_library' '//...:%go_library'
buildozer 'replace deps @io_bazel_rules_go//proto/wkt:duration_go_proto @com_github_golang_protobuf//ptypes/duration:go_default_library' '//...:%go_library'
buildozer 'replace deps @io_bazel_rules_go//proto/wkt:timestamp_go_proto @com_github_golang_protobuf//ptypes/timestamp:go_default_library' '//...:%go_library'
buildozer 'replace deps //vendor/github.com/gogo/protobuf/proto:go_default_library @com_github_gogo_protobuf//proto:go_default_library' '//...:%go_library'
buildozer 'replace deps //vendor/github.com/gogo/protobuf/types:go_default_library @com_github_gogo_protobuf//types:go_default_library' '//...:%go_library'

vendor:
dep ensure -v -update
# Note: this requires manual update afterwards, see: https://github.com/envoyproxy/protoc-gen-validate/issues/267
bazel run :gazelle -- update-repos -from_file=go.mod -to_macro=bazel/go_repos.bzl%go_third_party -prune
bazel run :gazelle

.PHONY: lint
lint:
# lints the package for common code smells
which golint || go get -u golang.org/x/lint/golint
which shadow || go get -u golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
which golint || go get golang.org/x/lint/golint
which shadow || go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
test -z "$(gofmt -d -s ./*.go)" || (gofmt -d -s ./*.go && exit 1)
# golint -set_exit_status
# check for variable shadowing
go vet -vettool=$(which shadow) *.go
go vet -vettool=$(which shadow) ./...

gogofast:
go build -o $@ vendor/github.com/gogo/protobuf/protoc-gen-gogofast/main.go
tests/harness-bin: tests/harness/executor/*.go
cd tests && go build -o harness-bin ./harness/executor/*.go

.PHONY: harness
harness: testcases tests/harness/go/harness.pb.go tests/harness/gogo/harness.pb.go tests/harness/go/main/go-harness tests/harness/gogo/main/go-harness tests/harness/cc/cc-harness
harness: testcases tests/harness/go/harness.pb.go tests/harness/go/main/go-harness tests/harness/cc/cc-harness tests/harness-bin
# runs the test harness, validating a series of test cases in all supported languages
go run ./tests/harness/executor/*.go -go -gogo -cc
./tests/harness-bin -go -cc

.PHONY: bazel-harness
bazel-harness:
# runs the test harness via bazel
bazel run //tests/harness/executor:executor --incompatible_new_actions_api=false -- -go -gogo -cc -java -python
bazel run //tests/harness/executor:executor --incompatible_new_actions_api=false -- -go -cc -java -python

.PHONY: testcases
testcases: gogofast
testcases:
# generate the test harness case protos
rm -r tests/harness/cases/go || true
mkdir tests/harness/cases/go
rm -r tests/harness/cases/other_package/go || true
mkdir tests/harness/cases/other_package/go
rm -r tests/harness/cases/gogo || true
mkdir tests/harness/cases/gogo
rm -r tests/harness/cases/other_package/gogo || true
mkdir tests/harness/cases/other_package/gogo
# protoc-gen-go makes us go a package at a time
cd tests/harness/cases/other_package && \
protoc \
cd tests/harness/cases/other_package && protoc \
-I . \
-I ../../../.. \
--go_out="${GO_IMPORT}:./go" \
--plugin=protoc-gen-gogofast=$(shell pwd)/gogofast \
--gogofast_out="${GOGO_IMPORT}:./gogo" \
--validate_out="lang=go:./go" \
--validate_out="lang=gogo:./gogo" \
./*.proto
cd tests/harness/cases && \
protoc \
cd tests/harness/cases && protoc \
-I . \
-I ../../.. \
--go_out="Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/go,${GO_IMPORT}:./go" \
--plugin=protoc-gen-gogofast=$(shell pwd)/gogofast \
--gogofast_out="Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/gogo,${GOGO_IMPORT}:./gogo" \
--validate_out="lang=go,Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/go:./go" \
--validate_out="lang=gogo,Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/gogo:./gogo" \
./*.proto

tests/harness/go/harness.pb.go:
# generates the test harness protos
cd tests/harness && protoc -I . \
--go_out="${GO_IMPORT}:./go" harness.proto

tests/harness/gogo/harness.pb.go: gogofast
# generates the test harness protos
cd tests/harness && protoc -I . \
--plugin=protoc-gen-gogofast=$(shell pwd)/gogofast \
--gogofast_out="${GOGO_IMPORT}:./gogo" harness.proto
cd tests/harness && protoc -I . --go_out="${GO_IMPORT}:./go" harness.proto

tests/harness/go/main/go-harness:
# generates the go-specific test harness
go build -o ./tests/harness/go/main/go-harness ./tests/harness/go/main

tests/harness/gogo/main/go-harness:
# generates the gogo-specific test harness
go build -o ./tests/harness/gogo/main/go-harness ./tests/harness/gogo/main
cd tests && go build -o ./harness/go/main/go-harness ./harness/go/main

tests/harness/cc/cc-harness: tests/harness/cc/harness.cc
# generates the C++-specific test harness
Expand All @@ -146,15 +104,9 @@ ci: lint bazel testcases bazel-harness build_generation_tests
clean:
(which bazel && bazel clean) || true
rm -f \
gogofast \
tests/harness/cc/cc-harness \
tests/harness/go/main/go-harness \
tests/harness/gogo/main/go-harness \
tests/harness/gogo/harness.pb.go \
tests/harness/gogo/harness.pb.go \
tests/harness/go/harness.pb.go
rm -rf \
tests/harness/cases/go \
tests/harness/cases/other_package/go \
tests/harness/cases/gogo \
tests/harness/cases/other_package/gogo \
tests/harness/cases/other_package/go
Loading