xref: /aosp_15_r20/external/protobuf/csharp/generate_protos.sh (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1*1b3f573fSAndroid Build Coastguard Worker#!/bin/bash
2*1b3f573fSAndroid Build Coastguard Worker# Generates C# source files from .proto files.
3*1b3f573fSAndroid Build Coastguard Worker# You first need to make sure protoc has been built (see instructions on
4*1b3f573fSAndroid Build Coastguard Worker# building protoc in root of this repository)
5*1b3f573fSAndroid Build Coastguard Worker
6*1b3f573fSAndroid Build Coastguard Workerset -e
7*1b3f573fSAndroid Build Coastguard Worker
8*1b3f573fSAndroid Build Coastguard Worker# cd to repository root
9*1b3f573fSAndroid Build Coastguard Workerpushd $(dirname $0)/..
10*1b3f573fSAndroid Build Coastguard Worker
11*1b3f573fSAndroid Build Coastguard Worker# Protocol buffer compiler to use. If the PROTOC variable is set,
12*1b3f573fSAndroid Build Coastguard Worker# use that. Otherwise, probe for expected locations under both
13*1b3f573fSAndroid Build Coastguard Worker# Windows and Unix.
14*1b3f573fSAndroid Build Coastguard Workerif [ -z "$PROTOC" ]; then
15*1b3f573fSAndroid Build Coastguard Worker  # TODO(jonskeet): Use an array and a for loop instead?
16*1b3f573fSAndroid Build Coastguard Worker  if [ -x solution/Debug/protoc.exe ]; then
17*1b3f573fSAndroid Build Coastguard Worker    PROTOC=solution/Debug/protoc.exe
18*1b3f573fSAndroid Build Coastguard Worker  elif [ -x cmake/build/Debug/protoc.exe ]; then
19*1b3f573fSAndroid Build Coastguard Worker    PROTOC=cmake/build/Debug/protoc.exe
20*1b3f573fSAndroid Build Coastguard Worker  elif [ -x cmake/build/Release/protoc.exe ]; then
21*1b3f573fSAndroid Build Coastguard Worker    PROTOC=cmake/build/Release/protoc.exe
22*1b3f573fSAndroid Build Coastguard Worker  elif [ -x src/protoc ]; then
23*1b3f573fSAndroid Build Coastguard Worker    PROTOC=src/protoc
24*1b3f573fSAndroid Build Coastguard Worker  else
25*1b3f573fSAndroid Build Coastguard Worker    echo "Unable to find protocol buffer compiler."
26*1b3f573fSAndroid Build Coastguard Worker    exit 1
27*1b3f573fSAndroid Build Coastguard Worker  fi
28*1b3f573fSAndroid Build Coastguard Workerfi
29*1b3f573fSAndroid Build Coastguard Worker
30*1b3f573fSAndroid Build Coastguard Worker# descriptor.proto and well-known types
31*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
32*1b3f573fSAndroid Build Coastguard Worker    --csharp_opt=base_namespace=Google.Protobuf \
33*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/descriptor.proto \
34*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/any.proto \
35*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/api.proto \
36*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/duration.proto \
37*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/empty.proto \
38*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/field_mask.proto \
39*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/source_context.proto \
40*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/struct.proto \
41*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/timestamp.proto \
42*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/type.proto \
43*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/wrappers.proto
44*1b3f573fSAndroid Build Coastguard Worker
45*1b3f573fSAndroid Build Coastguard Worker# Test protos
46*1b3f573fSAndroid Build Coastguard Worker# Note that this deliberately does *not* include old_extensions1.proto
47*1b3f573fSAndroid Build Coastguard Worker# and old_extensions2.proto, which are generated with an older version
48*1b3f573fSAndroid Build Coastguard Worker# of protoc.
49*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Isrc -Icsharp/protos \
50*1b3f573fSAndroid Build Coastguard Worker    --experimental_allow_proto3_optional \
51*1b3f573fSAndroid Build Coastguard Worker    --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \
52*1b3f573fSAndroid Build Coastguard Worker    --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \
53*1b3f573fSAndroid Build Coastguard Worker    --include_source_info \
54*1b3f573fSAndroid Build Coastguard Worker    --include_imports \
55*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/map_unittest_proto3.proto \
56*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_issues.proto \
57*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_custom_options_proto3.proto \
58*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_proto3.proto \
59*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_import_proto3.proto \
60*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_import_public_proto3.proto \
61*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest.proto \
62*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_import.proto \
63*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_import_public.proto \
64*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_issue6936_a.proto \
65*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_issue6936_b.proto \
66*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_issue6936_c.proto \
67*1b3f573fSAndroid Build Coastguard Worker    csharp/protos/unittest_selfreferential_options.proto \
68*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/unittest_well_known_types.proto \
69*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/test_messages_proto3.proto \
70*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/test_messages_proto2.proto \
71*1b3f573fSAndroid Build Coastguard Worker    src/google/protobuf/unittest_proto3_optional.proto
72*1b3f573fSAndroid Build Coastguard Worker
73*1b3f573fSAndroid Build Coastguard Worker# AddressBook sample protos
74*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \
75*1b3f573fSAndroid Build Coastguard Worker    examples/addressbook.proto
76*1b3f573fSAndroid Build Coastguard Worker
77*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \
78*1b3f573fSAndroid Build Coastguard Worker    conformance/conformance.proto
79*1b3f573fSAndroid Build Coastguard Worker
80*1b3f573fSAndroid Build Coastguard Worker# Benchmark protos
81*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Ibenchmarks \
82*1b3f573fSAndroid Build Coastguard Worker  benchmarks/datasets/google_message1/proto3/*.proto \
83*1b3f573fSAndroid Build Coastguard Worker  benchmarks/benchmarks.proto \
84*1b3f573fSAndroid Build Coastguard Worker  --csharp_out=csharp/src/Google.Protobuf.Benchmarks
85*1b3f573fSAndroid Build Coastguard Worker
86*1b3f573fSAndroid Build Coastguard Worker# C# only benchmark protos
87*1b3f573fSAndroid Build Coastguard Worker$PROTOC -Isrc -Icsharp/src/Google.Protobuf.Benchmarks \
88*1b3f573fSAndroid Build Coastguard Worker  csharp/src/Google.Protobuf.Benchmarks/*.proto \
89*1b3f573fSAndroid Build Coastguard Worker  --csharp_out=csharp/src/Google.Protobuf.Benchmarks
90