generate_protos.sh 2.49 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/bash
# Generates C# source files from .proto files.
# You first need to make sure protoc has been built (see instructions on
# building protoc in root of this repository)

set -ex

# cd to repository root
9
pushd $(dirname $0)/..
10

11 12 13 14 15
# Protocol buffer compiler to use. If the PROTOC variable is set,
# use that. Otherwise, probe for expected locations under both
# Windows and Unix.
if [ -z "$PROTOC" ]; then
  # TODO(jonskeet): Use an array and a for loop instead?
16 17 18 19
  if [ -x cmake/build/Debug/protoc.exe ]; then
    PROTOC=cmake/build/Debug/protoc.exe
  elif [ -x cmake/build/Release/protoc.exe ]; then
    PROTOC=cmake/build/Release/protoc.exe
20 21 22 23 24 25 26
  elif [ -x src/protoc ]; then
    PROTOC=src/protoc
  else
    echo "Unable to find protocol buffer compiler."
    exit 1
  fi
fi
27

28 29 30 31
# descriptor.proto and well-known types
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
    --csharp_opt=base_namespace=Google.Protobuf \
    src/google/protobuf/descriptor.proto \
32 33 34 35 36 37 38 39 40 41 42
    src/google/protobuf/any.proto \
    src/google/protobuf/api.proto \
    src/google/protobuf/duration.proto \
    src/google/protobuf/empty.proto \
    src/google/protobuf/field_mask.proto \
    src/google/protobuf/source_context.proto \
    src/google/protobuf/struct.proto \
    src/google/protobuf/timestamp.proto \
    src/google/protobuf/type.proto \
    src/google/protobuf/wrappers.proto

43 44 45
# Test protos where the namespace matches the target location
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test \
    --csharp_opt=base_namespace=Google.Protobuf \
46
    src/google/protobuf/map_unittest_proto3.proto \
47 48
    src/google/protobuf/unittest_proto3.proto \
    src/google/protobuf/unittest_import_proto3.proto \
49 50
    src/google/protobuf/unittest_import_public_proto3.proto \
    src/google/protobuf/unittest_well_known_types.proto
51

52
# Different base namespace to the protos above
53
$PROTOC -Isrc -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test \
54
    --csharp_opt=base_namespace=UnitTest.Issues \
55 56
    csharp/protos/unittest_issues.proto \
    csharp/protos/unittest_custom_options_proto3.proto
57

58 59 60 61 62
# Don't specify a base namespace at all; we just want to make sure the
# results end up in TestProtos.
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \
    src/google/protobuf/test_messages_proto3.proto

63 64 65
# AddressBook sample protos
$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
    examples/addressbook.proto
66

67
$PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \
68
    conformance/conformance.proto