#!/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 pushd $[dirname $0]/.. # Protocol buffer compiler to use. If the PROTOC variable is set, # use that. Otherwise, probe for expected locations under both # Windows and Unix. if test -z $PROTOC { # TODO(jonskeet): Use an array and a for loop instead? if test -x cmake/build/Debug/protoc.exe { global PROTOC := 'cmake/build/Debug/protoc.exe' } elif test -x cmake/build/Release/protoc.exe { global PROTOC := 'cmake/build/Release/protoc.exe' } elif test -x src/protoc { global PROTOC := 'src/protoc' } else { echo "Unable to find protocol buffer compiler." exit 1 } } # 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 \ 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 # 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 # 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 $PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \ examples/addressbook.proto $PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \ conformance/conformance.proto (CommandList children: [ (C {(set)} {(-ex)}) (C {(pushd)} { (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {($ VSub_Number "$0")})]) left_token: spids: [23 27] ) (/..) } ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$PROTOC"))} {(Lit_Other "]")}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-x)} {(cmake/build/Debug/protoc.exe)} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PROTOC) op: Equal rhs: {(cmake/build/Debug/protoc.exe)} spids: [74] ) ] spids: [74] ) ] spids: [-1 71] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-x)} {(cmake/build/Release/protoc.exe)} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PROTOC) op: Equal rhs: {(cmake/build/Release/protoc.exe)} spids: [92] ) ] spids: [92] ) ] spids: [78 89] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-x)} {(src/protoc)} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PROTOC) op: Equal rhs: {(src/protoc)} spids: [110] ) ] spids: [110] ) ] spids: [96 107] ) ] else_action: [ (C {(echo)} {(DQ ("Unable to find protocol buffer compiler."))}) (C {(exit)} {(1)}) ] spids: [114 129] ) ] spids: [-1 53] ) ] spids: [-1 131] ) (C {($ VSub_Name "$PROTOC")} {(-Isrc)} {(--csharp_out) (Lit_Other "=") (csharp/src/Google.Protobuf)} {(--csharp_opt) (Lit_Other "=") (Lit_VarLike "base_namespace=") (Google.Protobuf)} {(src/google/protobuf/descriptor.proto)} {(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)} ) (C {($ VSub_Name "$PROTOC")} {(-Isrc)} {(--csharp_out) (Lit_Other "=") (csharp/src/Google.Protobuf.Test)} {(--csharp_opt) (Lit_Other "=") (Lit_VarLike "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)} ) (C {($ VSub_Name "$PROTOC")} {(-Icsharp/protos)} {(--csharp_out) (Lit_Other "=") (csharp/src/Google.Protobuf.Test)} {(--csharp_opt) (Lit_Other "=") (Lit_VarLike "base_namespace=") (UnitTest.Issues)} {(csharp/protos/unittest_issues.proto)} ) (C {($ VSub_Name "$PROTOC")} {(-Iexamples)} {(--csharp_out) (Lit_Other "=") (csharp/src/AddressBook)} {(examples/addressbook.proto)} ) (C {($ VSub_Name "$PROTOC")} {(-Iconformance)} {(-Isrc)} {(--csharp_out) (Lit_Other "=") (csharp/src/Google.Protobuf.Conformance)} {(conformance/conformance.proto)} ) ] )