1#!/bin/bash
2# Copyright 2019 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -ex
17
18cd `dirname $0`/../..
19
20# get the version of protobuf in /third_party/protobuf
21pushd third_party/protobuf
22
23version1=$(git describe --tags | cut -f 1 -d'-')
24v1=${version1:1}
25# Protobuf has recently changed the versioning of the release branches/tags
26# and the same release commit can be tagged with mutliple tag names
27# (e.g. v3.21.12 is also tagged as v21.12), which ultimately confuses
28# the output of "git describe --tags" and makes it non-deterministic.
29# The hack below converts the version number to always become 3.x.y
30# regardless of what tag name we get back from "git describe --tags".
31# Hack: In case we got a 2-part "x.y" version number from the tag,
32# convert it to version number in "3.x.y" format.
33# TODO(jtattermusch): find a better workaround for this.
34v1=$(echo "$v1" | sed 's/^\([0-9]*\)\.\([0-9]*\)$/3.\1.\2/')
35
36popd
37
38# get the version of protobuf in /src/objective-c/!ProtoCompiler.podspec
39v2=$(cat src/objective-c/\!ProtoCompiler.podspec | egrep "v = " | cut -f 2 -d"'")
40
41# get the version of protobuf in /src/objective-c/!ProtoCompiler-gRPCPlugin.podspec
42v3=$(cat src/objective-c/\!ProtoCompiler-gRPCPlugin.podspec | egrep 'dependency.*!ProtoCompiler' | cut -f 4 -d"'")
43
44# compare and emit error
45ret=0
46if [ "$v1" != "$v2" ]; then
47  echo 'Protobuf version in src/objective-c/!ProtoCompiler.podspec does not match protobuf version in third_party/protobuf.'
48  ret=1
49fi
50
51if [ "$v1" != "$v3" ]; then
52  echo 'Protobuf version in src/objective-c/!ProtoCompiler-gRPCPlugin.podspec does not match protobuf version in third_party/protobuf.'
53  ret=1
54fi
55
56exit $ret
57