protobuf-go/regenerate.bash
Herbie Ong 6e67a1d614 reflect/protoregistry: add Types registry
The first commit of protoregistry only added a registry for files.
However, a separate type of registry is needed to provide a mapping between
protobuf names and actual Go types representing those names.

Additional high-level API:
    var GlobalTypes = new(Types)
    type Type interface{ ... }
    type Types struct{ ... }
        func NewTypes(...Type) *Types
        func (*Types) Register(...Type) error
        func (*Types) FindEnumByName(pref.FullName) (pref.EnumType, error)
        func (*Types) FindMessageByName(pref.FullName) (pref.MessageType, error)
        func (*Types) FindMessageByURL(string) (pref.MessageType, error)
        func (*Types) FindExtensionByName(pref.FullName) (pref.ExtensionType, error)
        func (*Types) FindExtensionByNumber(pref.FullName, pref.FieldNumber) (pref.ExtensionType, error)
        func (*Types) RangeEnums(func(pref.EnumType) bool)
        func (*Types) RangeMessages(func(pref.MessageType) bool)
        func (*Types) RangeExtensions(func(pref.ExtensionType) bool)
        func (*Types) RangeExtensionsByMessage(pref.FullName, func(pref.ExtensionType) bool)

Change-Id: I0d07705801684a1eb5853bcd05fcce12598a0047
Reviewed-on: https://go-review.googlesource.com/c/131345
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-12-28 00:06:31 +00:00

60 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2018 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -e
go generate internal/cmd/generate-types/main.go
# Install the working tree's protoc-gen-gen in a tempdir.
tmpdir=$(mktemp -d -t protobuf-regen.XXXXXX)
trap 'rm -rf $tmpdir' EXIT
mkdir -p $tmpdir/bin
PATH=$tmpdir/bin:$PATH
GOBIN=$tmpdir/bin go install ./cmd/protoc-gen-go
GOBIN=$tmpdir/bin go install ./cmd/protoc-gen-go-grpc
# Generate various test protos.
PROTO_DIRS=(
cmd/protoc-gen-go/testdata
cmd/protoc-gen-go-grpc/testdata
internal/testprotos/test
)
for dir in ${PROTO_DIRS[@]}; do
for p in `find $dir -name "*.proto"`; do
echo "# $p"
PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$dir \
--go_out=paths=source_relative:$dir \
--go-grpc_out=paths=source_relative:$dir \
$p
done
done
# Generate descriptor and plugin.
# TODO: Make this more automated.
echo "# types/descriptor/descriptor.proto"
mkdir -p $tmpdir/src/google/protobuf
cp ./types/descriptor/descriptor.proto $tmpdir/src/google/protobuf/descriptor.proto
PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$tmpdir/src \
--go_out=paths=source_relative:$tmpdir/src \
$tmpdir/src/google/protobuf/descriptor.proto
cp $tmpdir/src/google/protobuf/descriptor.pb.go ./types/descriptor/descriptor.pb.go
echo "# types/plugin/plugin.proto"
mkdir -p $tmpdir/src/google/protobuf/compiler
cp ./types/plugin/plugin.proto $tmpdir/src/google/protobuf/compiler/plugin.proto
PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$tmpdir/src \
--go_out=paths=source_relative:$tmpdir/src \
$tmpdir/src/google/protobuf/compiler/plugin.proto
cp $tmpdir/src/google/protobuf/compiler/plugin.pb.go ./types/plugin/plugin.pb.go
echo "# encoding/textpb/testprotos/pb?/test.proto"
PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc --go_out=paths=source_relative:. \
encoding/textpb/testprotos/pb?/test.proto
echo "# reflect/protoregistry/testprotos/test.proto"
PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc --go_out=paths=source_relative:. \
reflect/protoregistry/testprotos/test.proto