mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-04 02:38:50 +00:00
24ceb2b095
In CL/152020, we checked in pre-generated versions of descriptor and plugin. This CL makes it such that they are generated by protoc-gen-go. We modify protoc-gen-go to avoid reflection support by default since the binary size increase is still an issue to investigate. Reflection support is temporarily enabled by setting a special PROTOC_GEN_GO_ENABLE_REFLECT environment variable. Reflection support is always enabled for descriptor and plugin. Furthermore, we change descriptor to depend on the protoapi package instead of the proto package. The reason we do not switch to protoapi for all generated protos is because we still depend on v1 proto for the table-driven InternalMessageInfo type. Dropping it from descriptor is semantically correct, but does incur slight performance cost. It does not seem appropriate to drop it for all generated messages. We could move InternalMessageInfo to protoapi, but the logic behind that is significant. Change-Id: I5c3fff7f6eab1a5a2399049d42fa6bf42d4c93f9 Reviewed-on: https://go-review.googlesource.com/c/152547 Reviewed-by: Damien Neil <dneil@google.com>
49 lines
1.6 KiB
Bash
Executable File
49 lines
1.6 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
|
|
|
|
# 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
|
|
)
|
|
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
|