From 1aa65000568422f0187d2eb4fef00bcdca0cc125 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 15 Sep 2016 13:27:17 -0400 Subject: 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. --- objectivec/DevTools/check_version_stamps.sh | 67 ++++++++++++++--------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'objectivec/DevTools') 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 -- cgit v1.2.3