generate_proto_php.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # Copyright 2015 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 -e
  16. cd $(dirname $0)/../../..
  17. # protoc and grpc_*_plugin binaries can be obtained by running
  18. # $ bazel build @com_google_protobuf//:protoc //src/compiler:all
  19. PROTOC=bazel-bin/external/com_google_protobuf/protoc
  20. PLUGIN=protoc-gen-grpc=bazel-bin/src/compiler/grpc_php_plugin
  21. $PROTOC --proto_path=src/proto/math \
  22. --php_out=src/php/tests/generated_code \
  23. --grpc_out=src/php/tests/generated_code \
  24. --plugin=$PLUGIN \
  25. src/proto/math/math.proto
  26. # replace the Empty message with EmptyMessage
  27. # because Empty is a PHP reserved word
  28. output_file=$(mktemp)
  29. sed 's/message Empty/message EmptyMessage/g' \
  30. src/proto/grpc/testing/empty.proto > $output_file
  31. mv $output_file ./src/proto/grpc/testing/empty.proto
  32. sed 's/grpc\.testing\.Empty/grpc\.testing\.EmptyMessage/g' \
  33. src/proto/grpc/testing/test.proto > $output_file
  34. mv $output_file ./src/proto/grpc/testing/test.proto
  35. # interop test protos
  36. $PROTOC --proto_path=. \
  37. --php_out=src/php/tests/interop \
  38. --grpc_out=src/php/tests/interop \
  39. --plugin=$PLUGIN \
  40. src/proto/grpc/testing/messages.proto \
  41. src/proto/grpc/testing/empty.proto \
  42. src/proto/grpc/testing/test.proto
  43. # change it back
  44. sed 's/message EmptyMessage/message Empty/g' \
  45. src/proto/grpc/testing/empty.proto > $output_file
  46. mv $output_file ./src/proto/grpc/testing/empty.proto
  47. sed 's/grpc\.testing\.EmptyMessage/grpc\.testing\.Empty/g' \
  48. src/proto/grpc/testing/test.proto > $output_file
  49. mv $output_file ./src/proto/grpc/testing/test.proto
  50. # Hack for xDS interop: need this to be a separate file in the correct namespace.
  51. # To be removed when grpc_php_plugin generates service stubs.
  52. echo '<?php
  53. // DO NOT EDIT
  54. namespace Grpc\Testing;
  55. class LoadBalancerStatsServiceStub {
  56. }
  57. ' > ./src/php/tests/interop/Grpc/Testing/LoadBalancerStatsServiceStub.php