blob: 325b71dd9a296cbd7ac91e5c66cf51f478fdff19 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001#!/bin/bash
2
3# This script checks that the runtime version number constant in the compiler
4# source and in the runtime source is the same.
5#
6# A distro can be made of the protobuf sources with only a subset of the
7# languages, so if the compiler depended on the Objective C runtime, those
8# builds would break. At the same time, we don't want the runtime source
9# depending on the compiler sources; so two copies of the constant are needed.
10
11set -eu
12
13readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
14readonly ProtoRootDir="${ScriptDir}/../.."
15
16die() {
17 echo "Error: $1"
18 exit 1
19}
20
21readonly ConstantName=GOOGLE_PROTOBUF_OBJC_GEN_VERSION
22
23# Collect version from plugin sources.
24
25readonly PluginSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
26readonly PluginVersion=$( \
27 cat "${PluginSrc}" \
28 | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p"
29)
30
31if [[ -z "${PluginVersion}" ]] ; then
32 die "Failed to find ${ConstantName} in the plugin source (${PluginSrc})."
33fi
34
35# Collect version from runtime sources.
36
37readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
38readonly RuntimeVersion=$( \
39 cat "${RuntimeSrc}" \
40 | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
41)
42
43if [[ -z "${RuntimeVersion}" ]] ; then
44 die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
45fi
46
47# Compare them.
48
49if [[ "${PluginVersion}" != "${RuntimeVersion}" ]] ; then
50 die "Versions don't match!
51 Plugin: ${PluginVersion} from ${PluginSrc}
52 Runtime: ${RuntimeVersion} from ${RuntimeSrc}
53"
54fi
55
56# Success