Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Generates C# source files from .proto files. |
| 3 | # You first need to make sure protoc has been built (see instructions on |
| 4 | # building protoc in root of this repository) |
| 5 | |
Jon Skeet | b1a395c | 2015-05-15 14:36:07 +0100 | [diff] [blame] | 6 | # This script performs a few fix-ups as part of generation. These are: |
| 7 | # - descriptor.proto is renamed to descriptor_proto_file.proto before |
| 8 | # generation, to avoid the naming collision between the class for the file |
| 9 | # descriptor and its Descriptor property |
| 10 | # - This change also impacts UnittestCustomOptions, which expects to |
| 11 | # use a class of Descriptor when it's actually been renamed to |
| 12 | # DescriptorProtoFile. |
| 13 | # - Issue 307 (codegen for double-nested types) breaks Unittest.proto and |
| 14 | # its lite equivalents. |
| 15 | |
Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 16 | set -ex |
| 17 | |
| 18 | # cd to repository root |
| 19 | cd $(dirname $0)/.. |
| 20 | |
Jon Skeet | 734393d | 2015-05-14 09:11:57 +0100 | [diff] [blame] | 21 | # Protocol buffer compiler to use. If the PROTOC variable is set, |
| 22 | # use that. Otherwise, probe for expected locations under both |
| 23 | # Windows and Unix. |
| 24 | if [ -z "$PROTOC" ]; then |
| 25 | # TODO(jonskeet): Use an array and a for loop instead? |
| 26 | if [ -x vsprojects/Debug/protoc.exe ]; then |
| 27 | PROTOC=vsprojects/Debug/protoc.exe |
| 28 | elif [ -x vsprojects/Release/protoc.exe ]; then |
| 29 | PROTOC=vsprojects/Release/protoc.exe |
| 30 | elif [ -x src/protoc ]; then |
| 31 | PROTOC=src/protoc |
| 32 | else |
| 33 | echo "Unable to find protocol buffer compiler." |
| 34 | exit 1 |
| 35 | fi |
| 36 | fi |
Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 37 | |
| 38 | # Descriptor proto |
Jon Skeet | b1a395c | 2015-05-15 14:36:07 +0100 | [diff] [blame] | 39 | # TODO(jonskeet): Remove fixup |
| 40 | cp src/google/protobuf/descriptor.proto src/google/protobuf/descriptor_proto_file.proto |
| 41 | $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers/DescriptorProtos \ |
| 42 | src/google/protobuf/descriptor_proto_file.proto |
| 43 | rm src/google/protobuf/descriptor_proto_file.proto |
| 44 | |
Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 45 | $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \ |
Jon Skeet | eb70bd0 | 2015-06-12 09:53:44 +0100 | [diff] [blame^] | 46 | src/google/protobuf/unittest_proto3.proto \ |
| 47 | src/google/protobuf/unittest_import_proto3.proto \ |
| 48 | src/google/protobuf/unittest_import_public_proto3.proto |
Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 49 | |
| 50 | $PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \ |
Jan Tattermusch | dfefe9a | 2015-05-12 20:52:28 -0700 | [diff] [blame] | 51 | csharp/protos/extest/unittest_issues.proto |
| 52 | |
Jon Skeet | 734393d | 2015-05-14 09:11:57 +0100 | [diff] [blame] | 53 | # AddressBook sample protos |
| 54 | $PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \ |
| 55 | examples/addressbook.proto |