diff options
author | Jon Skeet <jonskeet@google.com> | 2015-09-01 15:05:03 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-09-01 15:05:03 +0100 |
commit | 5eb1fac9831676526ed9df4641b9740f977eaf4e (patch) | |
tree | 583b67b99a32318c6b671c024290f97701bdb09a /csharp | |
parent | 0101a59b62f5cc36c99bbe3bae6dbaa8db8e4f26 (diff) | |
download | protobuf-5eb1fac9831676526ed9df4641b9740f977eaf4e.tar.gz protobuf-5eb1fac9831676526ed9df4641b9740f977eaf4e.tar.bz2 protobuf-5eb1fac9831676526ed9df4641b9740f977eaf4e.zip |
Generate a directory hierarchy based on namespace (C#)
This introduces a new C# option, base_namespace.
If the option is not specified, the behaviour is as before: no directories are generated.
If the option *is* specified, all C# namespaces must be relative to the base namespace, and the directories are generated relative to that namespace.
Example:
- Any.proto declares csharp_namespace = "Google.Protobuf.WellKnownTypes"
- We build with --csharp_out=Google.Protobuf --csharp_opt=base_namespace=Google.Protobuf
- The Any.cs file is generated in Google.Protobuf/WellKnownTypes (where it currently lives)
We need a change to descriptor.proto before this will all work (it wasn't in the right C# namespace) but that needs the other descriptors to be regenerated too. See next commit...
Diffstat (limited to 'csharp')
-rwxr-xr-x | csharp/generate_protos.sh | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index 0d217a9d..3a556b0e 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -35,11 +35,10 @@ if [ -z "$PROTOC" ]; then fi fi -# Descriptor proto -$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/Reflection \ - src/google/protobuf/descriptor.proto - -$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \ +# 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 \ src/google/protobuf/any.proto \ src/google/protobuf/api.proto \ src/google/protobuf/duration.proto \ @@ -51,15 +50,18 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \ src/google/protobuf/type.proto \ src/google/protobuf/wrappers.proto -$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \ +# Test protos where the namespace matches the target location +$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test \ + --csharp_opt=base_namespace=Google.Protobuf \ src/google/protobuf/map_unittest_proto3.proto \ src/google/protobuf/unittest_proto3.proto \ src/google/protobuf/unittest_import_proto3.proto \ src/google/protobuf/unittest_import_public_proto3.proto \ src/google/protobuf/unittest_well_known_types.proto - -$PROTOC -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \ +# Different base namespace to the protos above +$PROTOC -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test \ + --csharp_opt=base_namespace=UnitTest.Issues \ csharp/protos/unittest_issues.proto # AddressBook sample protos |