@@ -102,9 +102,18 @@ download_gapic_generator_pom_parent() {
102
102
download_generator_artifact " ${gapic_generator_version} " " gapic-generator-java-pom-parent-${gapic_generator_version} .pom" " gapic-generator-java-pom-parent"
103
103
}
104
104
105
+ # This function returns the version of the grpc plugin to generate the libraries. If
106
+ # DOCKER_GRPC_VERSION is set, this will be the version. Otherwise, it will be
107
+ # computed from the gapic-generator-pom-parent artifact at the specified
108
+ # gapic_generator_version.
105
109
get_grpc_version () {
106
110
local gapic_generator_version=$1
107
111
local grpc_version
112
+ if [[ -n " ${DOCKER_GRPC_VERSION} " ]]; then
113
+ >&2 echo " Using grpc version baked into the container: ${DOCKER_GRPC_VERSION} "
114
+ echo " ${DOCKER_GRPC_VERSION} "
115
+ return
116
+ fi
108
117
pushd " ${output_folder} " > /dev/null
109
118
# get grpc version from gapic-generator-java-pom-parent/pom.xml
110
119
download_gapic_generator_pom_parent " ${gapic_generator_version} "
@@ -113,6 +122,10 @@ get_grpc_version() {
113
122
echo " ${grpc_version} "
114
123
}
115
124
125
+ # This function returns the version of protoc to generate the libraries. If
126
+ # DOCKER_PROTOC_VERSION is set, this will be the version. Otherwise, it will be
127
+ # computed from the gapic-generator-pom-parent artifact at the specified
128
+ # gapic_generator_version.
116
129
get_protoc_version () {
117
130
local gapic_generator_version=$1
118
131
local protoc_version
@@ -129,6 +142,16 @@ get_protoc_version() {
129
142
echo " ${protoc_version} "
130
143
}
131
144
145
+ # Given the versions of the gapic generator, protoc and the protoc-grpc plugin,
146
+ # this function will download each one of the tools and create the environment
147
+ # variables "protoc_path" and "grpc_path" which are expected upstream. Note that
148
+ # if the specified versions of protoc and grpc match DOCKER_PROTOC_VERSION and
149
+ # DOCKER_GRPC_VERSION respectively, this function will instead set "protoc_path"
150
+ # and "grpc_path" to DOCKER_PROTOC_PATH and DOCKER_GRPC_PATH respectively (no
151
+ # download), since the docker image will have downloaded these tools beforehand.
152
+ # For the case of gapic-generator-java, no env var will be exported for the
153
+ # upstream flow, but instead it will be assigned a default filename that will be
154
+ # referenced by the file `library_generation/gapic-generator-java-wrapper`.
132
155
download_tools () {
133
156
local gapic_generator_version=$1
134
157
local protoc_version=$2
@@ -147,7 +170,15 @@ download_tools() {
147
170
export protoc_path=$( download_protoc " ${protoc_version} " " ${os_architecture} " )
148
171
fi
149
172
150
- download_grpc_plugin " ${grpc_version} " " ${os_architecture} "
173
+ # similar case with grpc
174
+ if [[ " ${DOCKER_GRPC_VERSION} " == " ${grpc_version} " ]]; then
175
+ # if the specified grpc_version matches the one baked in the docker
176
+ # container, we just point grpc_path to its location.
177
+ export grpc_path=" ${DOCKER_GRPC_LOCATION} "
178
+ else
179
+ export grpc_path=$( download_grpc_plugin " ${grpc_version} " " ${os_architecture} " )
180
+ fi
181
+
151
182
popd
152
183
}
153
184
@@ -198,13 +229,15 @@ download_protoc() {
198
229
download_grpc_plugin () {
199
230
local grpc_version=$1
200
231
local os_architecture=$2
201
- if [ ! -f " protoc-gen-grpc-java-${grpc_version} -${os_architecture} .exe" ]; then
232
+ grpc_filename=" protoc-gen-grpc-java-${grpc_version} -${os_architecture} .exe"
233
+ if [ ! -f " ${grpc_filename} " ]; then
202
234
# download protoc-gen-grpc-java plugin from Google maven central mirror.
203
235
download_from \
204
- " https://maven-central.storage-download.googleapis.com/maven2/io/grpc/protoc-gen-grpc-java/${grpc_version} /protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe " \
205
- " protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe "
206
- chmod +x " protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe "
236
+ " https://maven-central.storage-download.googleapis.com/maven2/io/grpc/protoc-gen-grpc-java/${grpc_version} /${grpc_filename} " \
237
+ " ${grpc_filename} "
238
+ chmod +x " ${grpc_filename} "
207
239
fi
240
+ echo " $( pwd) /${grpc_filename} "
208
241
}
209
242
210
243
download_from () {
@@ -282,7 +315,7 @@ get_proto_path_from_preprocessed_sources() {
282
315
pushd " ${sources} " > /dev/null
283
316
local proto_library=$( find . -maxdepth 1 -type d -name ' proto-*' | sed ' s/\.\///' )
284
317
local found_libraries=$( echo " ${proto_library} " | wc -l)
285
- if [ -z ${proto_library} ]; then
318
+ if [[ -z ${proto_library} ] ]; then
286
319
echo " no proto libraries found in the supplied sources path"
287
320
exit 1
288
321
elif [ ${found_libraries} -gt 1 ]; then
0 commit comments