1#!/bin/bash 2 3set -e 4 5# Install the working tree's protoc-gen-gen in a tempdir. 6tmpdir=$(mktemp -d -t regen-wkt.XXXXXX) 7trap 'rm -rf $tmpdir' EXIT 8mkdir -p $tmpdir/bin 9PATH=$tmpdir/bin:$PATH 10GOBIN=$tmpdir/bin go install ./protoc-gen-go 11 12# Public imports require at least Go 1.9. 13supportTypeAliases="" 14if go list -f '{{context.ReleaseTags}}' runtime | grep -q go1.9; then 15 supportTypeAliases=1 16fi 17 18# Generate various test protos. 19PROTO_DIRS=( 20 conformance/internal/conformance_proto 21 jsonpb/jsonpb_test_proto 22 proto 23 protoc-gen-go/testdata 24) 25for dir in ${PROTO_DIRS[@]}; do 26 for p in `find $dir -name "*.proto"`; do 27 if [[ $p == */import_public/* && ! $supportTypeAliases ]]; then 28 echo "# $p (skipped)" 29 continue; 30 fi 31 echo "# $p" 32 protoc -I$dir --go_out=plugins=grpc,paths=source_relative:$dir $p 33 done 34done 35 36# Deriving the location of the source protos from the path to the 37# protoc binary may be a bit odd, but this is what protoc itself does. 38PROTO_INCLUDE=$(dirname $(dirname $(which protoc)))/include 39 40# Well-known types. 41WKT_PROTOS=(any duration empty struct timestamp wrappers) 42for p in ${WKT_PROTOS[@]}; do 43 echo "# google/protobuf/$p.proto" 44 protoc --go_out=paths=source_relative:$tmpdir google/protobuf/$p.proto 45 cp $tmpdir/google/protobuf/$p.pb.go ptypes/$p 46 cp $PROTO_INCLUDE/google/protobuf/$p.proto ptypes/$p 47done 48 49# descriptor.proto. 50echo "# google/protobuf/descriptor.proto" 51protoc --go_out=paths=source_relative:$tmpdir google/protobuf/descriptor.proto 52cp $tmpdir/google/protobuf/descriptor.pb.go protoc-gen-go/descriptor 53cp $PROTO_INCLUDE/google/protobuf/descriptor.proto protoc-gen-go/descriptor 54