Files
matchbox/scripts/codegen
Dalton Hubble 05da923fc3 Makefile, scripts: Add make codegen target
* Get/build protoc and protoc-gen-go binaries under tools
so they do not interfere with any user installations
* Ensure protoc and protoc-gen-go versions are pinned
2016-08-05 12:07:19 -07:00

31 lines
805 B
Bash
Executable File

#!/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