Debian Codegraph @

src/php/bin/generate_proto_php.sh

raw
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
16 set -e
17 cd $(dirname $0)/../../..
18
19 # protoc and grpc_*_plugin binaries can be obtained by running
20 # $ bazel build @com_google_protobuf//:protoc //src/compiler:all
21 PROTOC=bazel-bin/external/com_google_protobuf/protoc
22 PLUGIN=protoc-gen-grpc=bazel-bin/src/compiler/grpc_php_plugin
23
24 $PROTOC --proto_path=src/proto/math \
25 --php_out=src/php/tests/generated_code \
26 --grpc_out=generate_server:src/php/tests/generated_code \
27 --plugin=$PLUGIN \
28 src/proto/math/math.proto
29
30 # replace the Empty message with EmptyMessage
31 # because Empty is a PHP reserved word
32 output_file=$(mktemp)
33 sed 's/message Empty/message EmptyMessage/g' \
34 src/proto/grpc/testing/empty.proto > $output_file
35 mv $output_file ./src/proto/grpc/testing/empty.proto
36 sed 's/grpc\.testing\.Empty/grpc\.testing\.EmptyMessage/g' \
37 src/proto/grpc/testing/test.proto > $output_file
38 mv $output_file ./src/proto/grpc/testing/test.proto
39
40 # interop test protos
41 $PROTOC -I . \
42 -I third_party/protobuf/src \
43 --php_out=src/php/tests/interop \
44 --grpc_out=generate_server:src/php/tests/interop \
45 --plugin=$PLUGIN \
46 src/proto/grpc/testing/messages.proto \
47 src/proto/grpc/testing/empty.proto \
48 src/proto/grpc/testing/test.proto
49
50 # change it back
51 sed 's/message EmptyMessage/message Empty/g' \
52 src/proto/grpc/testing/empty.proto > $output_file
53 mv $output_file ./src/proto/grpc/testing/empty.proto
54 sed 's/grpc\.testing\.EmptyMessage/grpc\.testing\.Empty/g' \
55 src/proto/grpc/testing/test.proto > $output_file
56 mv $output_file ./src/proto/grpc/testing/test.proto