Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 1 | #!/bin/bash -eu |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 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 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 11 | readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") |
| 12 | readonly ProtoRootDir="${ScriptDir}/../.." |
| 13 | |
| 14 | die() { |
| 15 | echo "Error: $1" |
| 16 | exit 1 |
| 17 | } |
| 18 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 19 | readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 20 | readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 21 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 22 | check_constant() { |
| 23 | local ConstantName="$1" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 24 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 25 | # Collect version from generator sources. |
| 26 | local GeneratorVersion=$( \ |
| 27 | cat "${GeneratorSrc}" \ |
| 28 | | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p" |
| 29 | ) |
| 30 | if [[ -z "${GeneratorVersion}" ]] ; then |
| 31 | die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})." |
| 32 | fi |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 33 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 34 | # Collect version from runtime sources. |
| 35 | local RuntimeVersion=$( \ |
| 36 | cat "${RuntimeSrc}" \ |
| 37 | | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p" |
| 38 | ) |
| 39 | if [[ -z "${RuntimeVersion}" ]] ; then |
| 40 | die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})." |
| 41 | fi |
| 42 | |
| 43 | # Compare them. |
| 44 | if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then |
| 45 | die "${ConstantName} values don't match! |
| 46 | Generator: ${GeneratorVersion} from ${GeneratorSrc} |
| 47 | Runtime: ${RuntimeVersion} from ${RuntimeSrc} |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 48 | " |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 49 | fi |
| 50 | } |
| 51 | |
| 52 | # Do the check. |
| 53 | check_constant GOOGLE_PROTOBUF_OBJC_VERSION |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 54 | |
| 55 | # Success |