aboutsummaryrefslogtreecommitdiff
path: root/objectivec/DevTools
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-09-15 13:27:17 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-09-15 17:22:51 -0400
commit1aa65000568422f0187d2eb4fef00bcdca0cc125 (patch)
tree0e7a0728d64ef3cdec39ab42c6113ee714eab388 /objectivec/DevTools
parent86fcd879b38505446799b2f2a2929415ddad620a (diff)
downloadprotobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.tar.gz
protobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.tar.bz2
protobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.zip
Update the ObjC version checks to support a min and current version.
- Capture the version used to generated. - Check at compile time and runtime that generated code isn't from a newer version, also check that the min version required is also supported. - Keep the old constants/macros/functions to special case the last version that was working so those generated sources still work until we decide otherwise.
Diffstat (limited to 'objectivec/DevTools')
-rwxr-xr-xobjectivec/DevTools/check_version_stamps.sh67
1 files changed, 33 insertions, 34 deletions
diff --git a/objectivec/DevTools/check_version_stamps.sh b/objectivec/DevTools/check_version_stamps.sh
index 325b71dd..1acbe2a2 100755
--- a/objectivec/DevTools/check_version_stamps.sh
+++ b/objectivec/DevTools/check_version_stamps.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -eu
# This script checks that the runtime version number constant in the compiler
# source and in the runtime source is the same.
@@ -8,8 +8,6 @@
# builds would break. At the same time, we don't want the runtime source
# depending on the compiler sources; so two copies of the constant are needed.
-set -eu
-
readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
readonly ProtoRootDir="${ScriptDir}/../.."
@@ -18,39 +16,40 @@ die() {
exit 1
}
-readonly ConstantName=GOOGLE_PROTOBUF_OBJC_GEN_VERSION
-
-# Collect version from plugin sources.
-
-readonly PluginSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
-readonly PluginVersion=$( \
- cat "${PluginSrc}" \
- | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p"
-)
-
-if [[ -z "${PluginVersion}" ]] ; then
- die "Failed to find ${ConstantName} in the plugin source (${PluginSrc})."
-fi
-
-# Collect version from runtime sources.
-
+readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
-readonly RuntimeVersion=$( \
- cat "${RuntimeSrc}" \
- | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
-)
-
-if [[ -z "${RuntimeVersion}" ]] ; then
- die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
-fi
-
-# Compare them.
-if [[ "${PluginVersion}" != "${RuntimeVersion}" ]] ; then
- die "Versions don't match!
- Plugin: ${PluginVersion} from ${PluginSrc}
- Runtime: ${RuntimeVersion} from ${RuntimeSrc}
+check_constant() {
+ local ConstantName="$1"
+
+ # Collect version from generator sources.
+ local GeneratorVersion=$( \
+ cat "${GeneratorSrc}" \
+ | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p"
+ )
+ if [[ -z "${GeneratorVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})."
+ fi
+
+ # Collect version from runtime sources.
+ local RuntimeVersion=$( \
+ cat "${RuntimeSrc}" \
+ | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
+ )
+ if [[ -z "${RuntimeVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
+ fi
+
+ # Compare them.
+ if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then
+ die "${ConstantName} values don't match!
+ Generator: ${GeneratorVersion} from ${GeneratorSrc}
+ Runtime: ${RuntimeVersion} from ${RuntimeSrc}
"
-fi
+ fi
+}
+
+# Do the check.
+check_constant GOOGLE_PROTOBUF_OBJC_VERSION
# Success