aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/objectivec/objectivec_file.cc
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-09-15 13:27:17 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-09-15 17:22:51 -0400
commit1aa65000568422f0187d2eb4fef00bcdca0cc125 (patch)
tree0e7a0728d64ef3cdec39ab42c6113ee714eab388 /src/google/protobuf/compiler/objectivec/objectivec_file.cc
parent86fcd879b38505446799b2f2a2929415ddad620a (diff)
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.
Diffstat (limited to 'src/google/protobuf/compiler/objectivec/objectivec_file.cc')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_file.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
index 878a3743..7ad127bb 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
@@ -51,10 +51,8 @@ namespace objectivec {
namespace {
-// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
-// is the version check done to ensure generated code works with the current
-// runtime being used.
-const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30002;
+// This is also found in GPBBootstrap.h, and needs to be kept in sync.
+const int32 GOOGLE_PROTOBUF_OBJC_VERSION = 30002;
const char* kHeaderExtension = ".pbobjc.h";
@@ -192,13 +190,19 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
// Add some verification that the generated code matches the source the
// code is being compiled with.
+ // NOTE: This captures the raw numeric values at the time the generator was
+ // compiled, since that will be the versions for the ObjC runtime at that
+ // time. The constants in the generated code will then get their values at
+ // at compile time (so checking against the headers being used to compile).
printer->Print(
- "#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != $protoc_gen_objc_version$\n"
- "#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.\n"
+ "#if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$\n"
+ "#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.\n"
+ "#endif\n"
+ "#if $google_protobuf_objc_version$ < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION\n"
+ "#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.\n"
"#endif\n"
"\n",
- "protoc_gen_objc_version",
- SimpleItoa(GOOGLE_PROTOBUF_OBJC_GEN_VERSION));
+ "google_protobuf_objc_version", SimpleItoa(GOOGLE_PROTOBUF_OBJC_VERSION));
// #import any headers for "public imports" in the proto file.
{
@@ -392,7 +396,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety and initialization of registry.\n"
" static GPBExtensionRegistry* registry = nil;\n"
" if (!registry) {\n"
- " GPBDebugCheckRuntimeVersion();\n"
+ " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"
" registry = [[GPBExtensionRegistry alloc] init];\n");
printer->Indent();
@@ -487,7 +491,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety of the singleton.\n"
" static GPBFileDescriptor *descriptor = NULL;\n"
" if (!descriptor) {\n"
- " GPBDebugCheckRuntimeVersion();\n");
+ " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n");
if (vars["objc_prefix"].size() > 0) {
printer->Print(
vars,