compile.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # Copyright 2020 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -eu -o pipefail
  16. WORKDIR=$(mktemp -d)
  17. function finish {
  18. rm -rf "$WORKDIR"
  19. }
  20. trap finish EXIT
  21. export GOBIN=${WORKDIR}/bin
  22. export PATH=${GOBIN}:${PATH}
  23. mkdir -p ${GOBIN}
  24. echo "remove existing generated files"
  25. # grpc_testingv3/testv3.pb.go is not re-generated because it was
  26. # intentionally generated by an older version of protoc-gen-go.
  27. rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testingv3/testv3.pb.go')
  28. echo "go install google.golang.org/protobuf/cmd/protoc-gen-go"
  29. (go install google.golang.org/protobuf/cmd/protoc-gen-go)
  30. echo "go install google.golang.org/grpc/cmd/protoc-gen-go-grpc"
  31. (go install google.golang.org/grpc/cmd/protoc-gen-go-grpc)
  32. #echo "go install cmd/protoc-gen-go-grpc"
  33. #(cd cmd/protoc-gen-go-grpc && go install .)
  34. #echo "git clone https://github.com/grpc/grpc-proto"
  35. #git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto
  36. #echo "git clone https://github.com/protocolbuffers/protobuf"
  37. #git clone --quiet https://github.com/protocolbuffers/protobuf ${WORKDIR}/protobuf
  38. SOURCES=(
  39. $(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^\(profiling/proto/service.proto\|reflection/grpc_reflection_v1alpha/reflection.proto\)$')
  40. )
  41. # These options of the form 'Mfoo.proto=bar' instruct the codegen to use an
  42. # import path of 'bar' in the generated code when 'foo.proto' is imported in
  43. # one of the sources.
  44. OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config,Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core
  45. for src in ${SOURCES[@]}; do
  46. echo "protoc ${src}"
  47. mkdir -p ${WORKDIR}/out/${src%.proto}
  48. protoc --go_out=${OPTS}:${WORKDIR}/out/${src%.proto} --go-grpc_out=${OPTS}:${WORKDIR}/out/${src%.proto} ${src}
  49. echo "output: $(ls ${WORKDIR}/out/${src%.proto}/*/*/*)"
  50. cp ${WORKDIR}/out/${src%.proto}/*/*/* ${src%.proto}/
  51. done
  52. #for src in ${LEGACY_SOURCES[@]}; do
  53. # echo "protoc ${src}"
  54. # protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
  55. # -I"." \
  56. # -I${WORKDIR}/grpc-proto \
  57. # -I${WORKDIR}/googleapis \
  58. # -I${WORKDIR}/protobuf/src \
  59. # -I${WORKDIR}/istio \
  60. # ${src}
  61. #done
  62. #find ${WORKDIR}/out/ -name *.pb.go -exec cp "{}" golang \;