1#!/bin/bash -eu 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# We don't really want the generator sources directly referencing the runtime 7# or the reverse, so they both have the same constant defined, and this script 8# is used in a test to ensure the values stay in sync. 9 10die() { 11 echo "Error: $1" 12 exit 1 13} 14 15readonly GeneratorSrc="src/google/protobuf/compiler/objectivec/file.cc" 16readonly RuntimeSrc="objectivec/GPBBootstrap.h" 17 18if [[ ! -e "${GeneratorSrc}" ]] ; then 19 die "Failed to find generator file: ${GeneratorSrc}" 20fi 21if [[ ! -e "${RuntimeSrc}" ]] ; then 22 die "Failed to find runtime file: ${RuntimeSrc}" 23fi 24 25check_constant() { 26 local ConstantName="$1" 27 28 # Collect version from generator sources. 29 local GeneratorVersion=$( \ 30 cat "${GeneratorSrc}" \ 31 | sed -n -e "s:const int32_t ${ConstantName} = \([0-9]*\);:\1:p" 32 ) 33 if [[ -z "${GeneratorVersion}" ]] ; then 34 die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})." 35 fi 36 37 # Collect version from runtime sources. 38 local RuntimeVersion=$( \ 39 cat "${RuntimeSrc}" \ 40 | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p" 41 ) 42 if [[ -z "${RuntimeVersion}" ]] ; then 43 die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})." 44 fi 45 46 # Compare them. 47 if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then 48 die "${ConstantName} values don't match! 49 Generator: ${GeneratorVersion} from ${GeneratorSrc} 50 Runtime: ${RuntimeVersion} from ${RuntimeSrc} 51" 52 fi 53} 54 55# Do the check. 56check_constant GOOGLE_PROTOBUF_OBJC_VERSION 57 58# Success 59