From e4d70bba01c72367bcd37c4159bb69b3caa69d69 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Feb 2023 10:17:46 -0800 Subject: [PATCH] [ObjC] Include the version checks in generated impl files. There's always the chance someone will mix these, so play it safe and have checks in both. PiperOrigin-RevId: 508114797 --- objectivec/GPBAny.pbobjc.m | 7 ++++ objectivec/GPBApi.pbobjc.m | 7 ++++ objectivec/GPBDuration.pbobjc.m | 7 ++++ objectivec/GPBEmpty.pbobjc.m | 7 ++++ objectivec/GPBFieldMask.pbobjc.m | 7 ++++ objectivec/GPBSourceContext.pbobjc.m | 7 ++++ objectivec/GPBStruct.pbobjc.m | 7 ++++ objectivec/GPBTimestamp.pbobjc.m | 7 ++++ objectivec/GPBType.pbobjc.m | 7 ++++ objectivec/GPBWrappers.pbobjc.m | 7 ++++ .../protobuf/compiler/objectivec/file.cc | 38 +++++++++---------- 11 files changed, 88 insertions(+), 20 deletions(-) diff --git a/objectivec/GPBAny.pbobjc.m b/objectivec/GPBAny.pbobjc.m index 00b7fe2fa2..1e1b07a235 100644 --- a/objectivec/GPBAny.pbobjc.m +++ b/objectivec/GPBAny.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBAny.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBApi.pbobjc.m b/objectivec/GPBApi.pbobjc.m index 06c5314869..1bc539adf4 100644 --- a/objectivec/GPBApi.pbobjc.m +++ b/objectivec/GPBApi.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBApi.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBDuration.pbobjc.m b/objectivec/GPBDuration.pbobjc.m index 497ceca548..06018bf29d 100644 --- a/objectivec/GPBDuration.pbobjc.m +++ b/objectivec/GPBDuration.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBDuration.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBEmpty.pbobjc.m b/objectivec/GPBEmpty.pbobjc.m index fffb986a5f..6bb9e9c706 100644 --- a/objectivec/GPBEmpty.pbobjc.m +++ b/objectivec/GPBEmpty.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBEmpty.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBFieldMask.pbobjc.m b/objectivec/GPBFieldMask.pbobjc.m index 1c17442c2f..873ccce1d6 100644 --- a/objectivec/GPBFieldMask.pbobjc.m +++ b/objectivec/GPBFieldMask.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBFieldMask.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBSourceContext.pbobjc.m b/objectivec/GPBSourceContext.pbobjc.m index 9ddd2969fa..9db01979f7 100644 --- a/objectivec/GPBSourceContext.pbobjc.m +++ b/objectivec/GPBSourceContext.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBSourceContext.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBStruct.pbobjc.m b/objectivec/GPBStruct.pbobjc.m index aff707809b..7a53de335d 100644 --- a/objectivec/GPBStruct.pbobjc.m +++ b/objectivec/GPBStruct.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBStruct.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + #import // @@protoc_insertion_point(imports) diff --git a/objectivec/GPBTimestamp.pbobjc.m b/objectivec/GPBTimestamp.pbobjc.m index 15b494f59e..bb43aec65c 100644 --- a/objectivec/GPBTimestamp.pbobjc.m +++ b/objectivec/GPBTimestamp.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBTimestamp.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBType.pbobjc.m b/objectivec/GPBType.pbobjc.m index 566b3a9fdd..c4211177f9 100644 --- a/objectivec/GPBType.pbobjc.m +++ b/objectivec/GPBType.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBType.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + #import // @@protoc_insertion_point(imports) diff --git a/objectivec/GPBWrappers.pbobjc.m b/objectivec/GPBWrappers.pbobjc.m index fd3f9785d1..0e87e6ca2b 100644 --- a/objectivec/GPBWrappers.pbobjc.m +++ b/objectivec/GPBWrappers.pbobjc.m @@ -5,6 +5,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #import "GPBWrappers.pbobjc.h" +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index 5de626fda0..b389701729 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -530,26 +530,24 @@ void FileGenerator::GenerateFile( p->Print("\n"); - if (file_type == GeneratedFileType::kHeader) { - // 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). - p->Print( - // clang-format off - "#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", - // clang-format on - "google_protobuf_objc_version", - absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); - } + // 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 + // compile time (so checking against the headers being used to compile). + p->Print( + // clang-format off + "#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", + // clang-format on + "google_protobuf_objc_version", + absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); // Enum implementation uses atomic in the generated code, so add // the system import as needed.