github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/scripts/compile_protos.sh (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 9 set -eux 10 11 # To set a proto root for a set of protos, create a .protoroot file in one of the parent directories 12 # which you wish to use as the proto root. If no .protoroot file exists within fabric/.../<your_proto> 13 # then the proto root for that proto is inferred to be its containing directory. 14 15 # Find explicit proto roots 16 PROTO_ROOT_FILES="$(find . -name ".protoroot" -exec readlink -f {} \;)" 17 PROTO_ROOT_DIRS="$(dirname $PROTO_ROOT_FILES)" 18 19 20 # Find all proto files to be compiled, excluding any which are in a proto root or in the vendor folder, as well as the gotools dir 21 ROOTLESS_PROTO_FILES="$(find $PWD \ 22 $(for dir in $PROTO_ROOT_DIRS ; do echo "-path $dir -prune -o " ; done) \ 23 -path $PWD/vendor -prune -o \ 24 -path $PWD/gotools -prune -o \ 25 -path $PWD/build -prune -o \ 26 -path $PWD/core/chaincode/shim/java -prune -o \ 27 -name "*.proto" -exec readlink -f {} \;)" 28 ROOTLESS_PROTO_DIRS="$(dirname $ROOTLESS_PROTO_FILES | sort | uniq)" 29 30 for dir in $ROOTLESS_PROTO_DIRS $PROTO_ROOT_DIRS; do 31 echo Working on dir $dir 32 # As this is a proto root, and there may be subdirectories with protos, compile the protos for each sub-directory which contains them 33 for protos in $(find "$dir" -name '*.proto' -exec dirname {} \; | sort | uniq) ; do 34 protoc --proto_path="$dir" --go_out=plugins=grpc:$GOPATH/src "$protos"/*.proto 35 done 36 done