forked from googleapis/google-cloud-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
toolversions.sh
executable file
·131 lines (113 loc) · 4.24 KB
/
toolversions.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# This is intended to be imported using the "source" function from
# any scripts that use tools.
# TODO: Make all of this work under Linux too, if it's useful
# Note: versions of dotnet tools (e.g. docfx) are under
# .config/dotnet-tools.json
declare -r REPO_ROOT=$(readlink -f $(dirname ${BASH_SOURCE}))
declare -r TOOL_PACKAGES=$REPO_ROOT/packages
declare -r PROTOC_VERSION=3.25.2
declare -r GRPC_VERSION=2.60.0
if [[ $GAPIC_GENERATOR_VERSION == "" ]]
then
declare -r GAPIC_GENERATOR_VERSION=v1.4.32
else
echo "Using GAPIC generator override: ${GAPIC_GENERATOR_VERSION}"
fi
declare -r PROTOBUF_TOOLS_ROOT=$TOOL_PACKAGES/Google.Protobuf.Tools.$PROTOC_VERSION
# Cross-platform tools
case "$OSTYPE" in
linux*)
declare -r PROTOC=$PROTOBUF_TOOLS_ROOT/tools/linux_x64/protoc
declare -r GRPC_PLUGIN=packages/Grpc.Tools.$GRPC_VERSION/tools/linux_x64/grpc_csharp_plugin
;;
darwin*)
declare -r PROTOC=$PROTOBUF_TOOLS_ROOT/tools/macosx_x64/protoc
declare -r GRPC_PLUGIN=packages/Grpc.Tools.$GRPC_VERSION/tools/macosx_x64/grpc_csharp_plugin
;;
win* | msys* | cygwin*)
declare -r PROTOC=$PROTOBUF_TOOLS_ROOT/tools/windows_x64/protoc.exe
declare -r GRPC_PLUGIN=packages/Grpc.Tools.$GRPC_VERSION/tools/windows_x64/grpc_csharp_plugin.exe
;;
*)
echo "Unknown OSTYPE: $OSTYPE"
exit 1
esac
# The nuget command line tool is annoying to get installed on Linux/Mac.
# We only need to be able to install tool packages, so let's just fake that by fetching with curl and unzipping.
# Arguments:
# - Package name
# - Version
install_nuget_package() {
local output=$TOOL_PACKAGES/$1.$2
# Assume that if the directory exists, it's already installed correctly.
if [[ -d $output ]]; then return 0; fi
(mkdir -p $output;
cd $output;
curl -sSL https://www.nuget.org/api/v2/package/$1/$2 --output tmp.zip;
unzip -q tmp.zip;
rm tmp.zip)
}
# Installation functions, all of which should be unconditionally called
# when required. (They handle the case where the tool is already installed.)
install_protoc() {
install_nuget_package Google.Protobuf.Tools $PROTOC_VERSION
# Temporary fix for a broken proto in the protobuf tools package
sed -i 's/--)/-- )/g' $PROTOBUF_TOOLS_ROOT/tools/google/protobuf/timestamp.proto
chmod +x $PROTOC
}
install_microgenerator() {
case "$OSTYPE" in
linux*)
declare -r RUNTIME=linux-x64
declare -r EXTENSION=
;;
darwin*)
echo "Microgenerator not currently supported on MacOSX. Ask jonskeet@ for help."
exit 1
;;
win* | msys* | cygwin*)
declare -r RUNTIME=win-x64
declare -r EXTENSION=.exe
;;
*)
echo "Unknown OSTYPE: $OSTYPE"
exit 1
esac
# If the CSHARP_GENERATOR_DIR env variable is set
# we use that as the generator root dir.
if [[ "$CSHARP_GENERATOR_DIR" != "" ]]
then
declare -r GENERATOR_ROOT=$CSHARP_GENERATOR_DIR
else
declare -r GENERATOR_ROOT=$REPO_ROOT/gapic-generator-csharp
fi
export GAPIC_PLUGIN=$GENERATOR_ROOT/Google.Api.Generator/bin/Release/net6.0/$RUNTIME/publish/Google.Api.Generator$EXTENSION
if [[ "$CSHARP_GENERATOR_DIR" != "" ]]
then
echo "Skipping microgenerator fetch: an existing directory for the generator has been specified"
elif [ -d $GENERATOR_ROOT ]
then
git -C $GENERATOR_ROOT fetch -q --tags
git -C $GENERATOR_ROOT checkout -q $GAPIC_GENERATOR_VERSION
else
git clone https://github.com/googleapis/gapic-generator-csharp $GENERATOR_ROOT -q
git -C $GENERATOR_ROOT checkout -q $GAPIC_GENERATOR_VERSION
fi
# The dotnet restore step isn't generally required when cloning from elsewhere,
# but helps when running a local generator. (It does no harm even when not required.)
(cd $GENERATOR_ROOT; \
dotnet restore -v quiet; \
dotnet publish -v quiet -nologo -clp:NoSummary -c Release --self-contained --runtime=$RUNTIME Google.Api.Generator)
}
install_grpc() {
install_nuget_package Grpc.Tools $GRPC_VERSION
chmod +x $GRPC_PLUGIN
}
# Logs to both stdout and a build timing log, allowing
# post-processing to see how long each part of the build takes.
# The console log is in magenta to stand out, and doesn't include the
# timing part.
log_build_action() {
echo -e "\e[1;35m$1\e[0m"
echo "$(date -u -Iseconds) $1" >> $REPO_ROOT/build_timing_log.txt
}