check_version_stamps.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash -eu
  2. # This script checks that the runtime version number constant in the compiler
  3. # source and in the runtime source is the same.
  4. #
  5. # A distro can be made of the protobuf sources with only a subset of the
  6. # languages, so if the compiler depended on the Objective C runtime, those
  7. # builds would break. At the same time, we don't want the runtime source
  8. # depending on the compiler sources; so two copies of the constant are needed.
  9. readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  10. readonly ProtoRootDir="${ScriptDir}/../.."
  11. die() {
  12. echo "Error: $1"
  13. exit 1
  14. }
  15. readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
  16. readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
  17. check_constant() {
  18. local ConstantName="$1"
  19. # Collect version from generator sources.
  20. local GeneratorVersion=$( \
  21. cat "${GeneratorSrc}" \
  22. | sed -n -e "s:const int32_t ${ConstantName} = \([0-9]*\);:\1:p"
  23. )
  24. if [[ -z "${GeneratorVersion}" ]] ; then
  25. die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})."
  26. fi
  27. # Collect version from runtime sources.
  28. local RuntimeVersion=$( \
  29. cat "${RuntimeSrc}" \
  30. | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
  31. )
  32. if [[ -z "${RuntimeVersion}" ]] ; then
  33. die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
  34. fi
  35. # Compare them.
  36. if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then
  37. die "${ConstantName} values don't match!
  38. Generator: ${GeneratorVersion} from ${GeneratorSrc}
  39. Runtime: ${RuntimeVersion} from ${RuntimeSrc}
  40. "
  41. fi
  42. }
  43. # Do the check.
  44. check_constant GOOGLE_PROTOBUF_OBJC_VERSION
  45. # Success