check_version_stamps.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  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. set -eu
  10. readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  11. readonly ProtoRootDir="${ScriptDir}/../.."
  12. die() {
  13. echo "Error: $1"
  14. exit 1
  15. }
  16. readonly ConstantName=GOOGLE_PROTOBUF_OBJC_GEN_VERSION
  17. # Collect version from plugin sources.
  18. readonly PluginSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
  19. readonly PluginVersion=$( \
  20. cat "${PluginSrc}" \
  21. | sed -n -e "s:const int32_t ${ConstantName} = \([0-9]*\);:\1:p"
  22. )
  23. if [[ -z "${PluginVersion}" ]] ; then
  24. die "Failed to fine ${ConstantName} in the plugin source (${PluginSrc})."
  25. fi
  26. # Collect version from runtime sources.
  27. readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
  28. readonly 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 fine ${ConstantName} in the runtime source (${RuntimeSrc})."
  34. fi
  35. # Compare them.
  36. if [[ "${PluginVersion}" != "${RuntimeVersion}" ]] ; then
  37. die "Versions don't match!
  38. Plugin: ${PluginVersion} from ${PluginSrc}
  39. Runtime: ${RuntimeVersion} from ${RuntimeSrc}
  40. "
  41. fi
  42. # Success