forked from googleapis/gax-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateprotos.sh
executable file
·97 lines (79 loc) · 2.84 KB
/
generateprotos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -e
# TODO: Use some appropriate way of determining OS. Ideally, shouldn't need dotnet installed.
#[[ $(dotnet --info | grep "OS Platform" | grep -c Windows) -ne 0 ]] && OS=windows || OS=linux
OS=windows
[[ ${OS} = "windows" ]] && EXE_SUFFIX=.exe || EXE_SUFFIX=
declare -r ROOT=$(realpath $(dirname $0))
cd $ROOT
PROTOBUF_VERSION=3.15.8
GRPC_VERSION=2.36.4
PROTOC=$ROOT/packages/Google.Protobuf.Tools.$PROTOBUF_VERSION/tools/${OS}_x64/protoc${EXE_SUFFIX}
CORE_PROTOS_ROOT=$ROOT/packages/Google.Protobuf.Tools.$PROTOBUF_VERSION/tools
GRPC_PLUGIN=$ROOT/packages/Grpc.Tools.$GRPC_VERSION/tools/windows_x64/grpc_csharp_plugin.exe
# Nuget isn't working nicely for me on Linux...
nuget_install() {
outdir=packages/$1.$2
if [ ! -d "$outdir" ]
then
echo Fetching $1 version $2
mkdir -p $outdir
curl -sSL https://www.nuget.org/api/v2/package/$1/$2 --output tmp.zip
unzip -q -d $outdir tmp.zip
if [ -d "packages/$1.$2/tools" ]
then
chmod +x $(find packages/$1.$2/tools -type f)
fi
rm tmp.zip
fi
}
install_dependencies() {
# Make sure we have all the tools we need.
# Prerequisite: Java already installed so that gradlew will work
nuget_install Google.Protobuf.Tools $PROTOBUF_VERSION
nuget_install Grpc.Tools $GRPC_VERSION
if [ -d "googleapis" ]
then
pushd googleapis > /dev/null
git pull
popd > /dev/null
else
git clone --recursive https://github.com/googleapis/googleapis
fi
}
# Entry point
install_dependencies
declare -r OUTDIR=tmp
declare -r TARGETDIR=Google.Api.CommonProtos
rm -rf $OUTDIR
mkdir $OUTDIR
# Note: not using find for google/api, as it contains
# services, and we don't want those (yet, at least)
$PROTOC \
-I googleapis \
-I $CORE_PROTOS_ROOT \
--csharp_out=$OUTDIR \
--csharp_opt=base_namespace=Google,file_extension=.g.cs \
googleapis/google/api/*.proto \
$(find googleapis/google/rpc -name '*.proto') \
$(find googleapis/google/type -name '*.proto')
for src in $(find tmp -name '*.cs' | sed 's/tmp\///g')
do
if [[ ! -f $TARGETDIR/$src ]]
then
# New file: use this year
cat copyright-header.txt | sed "s/MODIFY-YEAR/$(date +%Y)/g" > $TARGETDIR/$src
cat $OUTDIR/$src >> $TARGETDIR/$src
else
# Assume we've got the same size of copyright as before, and preserve it
head -n $(wc -l < copyright-header.txt) $TARGETDIR/$src > $OUTDIR/header
cat $OUTDIR/header $OUTDIR/$src > $TARGETDIR/$src
fi
done
rm -rf $OUTDIR
(cd Google.Api.Gax.Grpc.IntegrationTests;
$PROTOC --csharp_opt=file_extension=.g.cs --csharp_out=. --grpc_out=. -I. --plugin=protoc-gen-grpc=$GRPC_PLUGIN *.proto)
(cd Google.Api.Gax.Grpc.Tests;
$PROTOC --csharp_opt=file_extension=.g.cs --csharp_out=. --grpc_out=. -I. --plugin=protoc-gen-grpc=$GRPC_PLUGIN *.proto)
(cd Google.Api.Gax.Grpc.Tests/Rest;
$PROTOC --csharp_opt=file_extension=.g.cs --csharp_out=. -I. *.proto)