Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Adds gen-proto.sh script to scripts directory
Browse files Browse the repository at this point in the history
gen-proto.sh generators protobuf files in grpc/ directory

Enables `make proto` to generate all protobuf files needed for grpc.
  • Loading branch information
IRCody committed Jun 10, 2016
1 parent ebdd1fb commit 0b8120f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ snap:
install:
cp build/bin/snapd /usr/local/bin/
cp build/bin/snapctl /usr/local/bin/
proto:
cd $(GOPATH); bash -c "./src/github.com/intelsdi-x/snap/scripts/gen-proto.sh"
76 changes: 76 additions & 0 deletions scripts/gen-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash -e

#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2016 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

echo "Checking for proto"
if ! which protoc > /dev/null
then
echo "Error: protoc not installed" >&2
exit 1
fi

if ! protoc --version | grep 'libprotoc 3\.' > /dev/null
then
echo "Error: this project requires protobuf 3" >&2
exit 1
fi

if ! which protoc-gen-go > /dev/null
then
echo "Error: protoc-gen-go not installed. try : go get github.com/golang/protobuf/protoc-gen-go" >&2
exit 1
fi

proto_files=("grpc/controlproxy/rpc/control.proto")
pb_go_files=("grpc/controlproxy/rpc/control.pb.go")

license='/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2016 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'
echo "Generating pb.go files"
common_path="src/github.com/intelsdi-x/snap"
#generate common
echo "Generating common proto files"
protoc --go_out=plugins.grpc:src/ --proto_path=src/ "$common_path"/grpc/common/*.proto
echo "$license" | cat - "$common_path"/grpc/common/common.pb.go > temp && mv temp "$common_path"/grpc/common/common.pb.go
#generate all others

for i in "${!proto_files[@]}"
do
file="${proto_files[$i]}"
pb="${pb_go_files[$i]}"
echo "Generating $pb"
protoc --go_out=plugins=grpc:src/ --proto_path=src/ "$common_path"/"$file"
echo "$license" | cat - "$common_path"/"$pb" > temp && mv temp "$common_path"/"$pb"
done

0 comments on commit 0b8120f

Please sign in to comment.