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