#!/usr/bin/env bash # Generate Go protocol buffer code from proto definitions set -eu # Add tools to the PATH so binaries are the correct version export PATH=$PWD/tools:$PATH # Check location and tools if ! [[ "$0" =~ "scripts/codegen" ]]; then echo "must be run from repository root" exit 255 fi if ! [[ $(protoc --version) =~ "3.0.0" ]]; then echo "could not find protoc 3.0.0" exit 255 fi # protobuf subpackages end in "pb" PBUFS=$(go list ./... | grep -v /vendor | grep 'pb$') # change into each protobuf directory for pkg in $PBUFS ; do abs_path=${GOPATH}/src/${pkg} echo Generating $abs_path pushd ${abs_path} > /dev/null # generate protocol buffers, make other .proto files available to import protoc --go_out=plugins=grpc:. -I=.:"${GOPATH}/src/" *.proto popd > /dev/null done