Skip to content

Commit cdd3cf7

Browse files
thomasvlcopybara-github
authored andcommitted
[ObjC] Make debug runtime tell developers to update their generated code.
Migrate some internals of the library off the older apis. Also mark some of the old apis as deprecated, but the old generated code suppressed warnings broadly to support protobuf deprecations. PiperOrigin-RevId: 668003974
1 parent 9d73796 commit cdd3cf7

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

objectivec/GPBDescriptor_PackagePrivate.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,18 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
215215
fields:(void *)fieldDescriptions
216216
fieldCount:(uint32_t)fieldCount
217217
storageSize:(uint32_t)storageSize
218-
flags:(GPBDescriptorInitializationFlags)flags;
218+
flags:(GPBDescriptorInitializationFlags)flags
219+
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
220+
"Support for this version will go away in the future.")));
219221
+ (instancetype)allocDescriptorForClass:(Class)messageClass
220222
rootClass:(Class)rootClass
221223
file:(GPBFileDescriptor *)file
222224
fields:(void *)fieldDescriptions
223225
fieldCount:(uint32_t)fieldCount
224226
storageSize:(uint32_t)storageSize
225-
flags:(GPBDescriptorInitializationFlags)flags;
227+
flags:(GPBDescriptorInitializationFlags)flags
228+
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
229+
"Support for this version will go away in the future.")));
226230
- (void)setupContainingMessageClassName:(const char *)msgClassName;
227231
- (void)setupMessageClassNameSuffix:(NSString *)suffix;
228232

@@ -282,13 +286,17 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
282286
valueNames:(const char *)valueNames
283287
values:(const int32_t *)values
284288
count:(uint32_t)valueCount
285-
enumVerifier:(GPBEnumValidationFunc)enumVerifier;
289+
enumVerifier:(GPBEnumValidationFunc)enumVerifier
290+
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
291+
"Support for this version will go away in the future.")));
286292
+ (instancetype)allocDescriptorForName:(NSString *)name
287293
valueNames:(const char *)valueNames
288294
values:(const int32_t *)values
289295
count:(uint32_t)valueCount
290296
enumVerifier:(GPBEnumValidationFunc)enumVerifier
291-
extraTextFormatInfo:(const char *)extraTextFormatInfo;
297+
extraTextFormatInfo:(const char *)extraTextFormatInfo
298+
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
299+
"Support for this version will go away in the future.")));
292300
@end
293301

294302
@interface GPBExtensionDescriptor () {
@@ -307,7 +315,9 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
307315
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
308316
usesClassRefs:(BOOL)usesClassRefs;
309317
// Deprecated. Calls above with `usesClassRefs = NO`
310-
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc;
318+
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
319+
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
320+
"Support for this version will go away in the future.")));
311321

312322
- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
313323
@end

objectivec/GPBMessage.m

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,18 +1196,19 @@ + (instancetype)alloc {
11961196
+ (GPBDescriptor *)descriptor {
11971197
// This is thread safe because it is called from +initialize.
11981198
static GPBDescriptor *descriptor = NULL;
1199-
static GPBFileDescriptor *fileDescriptor = NULL;
1199+
static GPBFileDescription fileDescription = {
1200+
.package = "internal", .prefix = "", .syntax = GPBFileSyntaxProto2};
12001201
if (!descriptor) {
1201-
fileDescriptor = [[GPBFileDescriptor alloc] initWithPackage:@"internal"
1202-
syntax:GPBFileSyntaxProto2];
1203-
1204-
descriptor = [GPBDescriptor allocDescriptorForClass:[GPBMessage class]
1205-
rootClass:Nil
1206-
file:fileDescriptor
1207-
fields:NULL
1208-
fieldCount:0
1209-
storageSize:0
1210-
flags:0];
1202+
descriptor = [GPBDescriptor
1203+
allocDescriptorForClass:[GPBMessage class]
1204+
messageName:@"GPBMessage"
1205+
fileDescription:&fileDescription
1206+
fields:NULL
1207+
fieldCount:0
1208+
storageSize:0
1209+
flags:(GPBDescriptorInitializationFlag_UsesClassRefs |
1210+
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
1211+
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
12111212
}
12121213
return descriptor;
12131214
}

objectivec/GPBUtilities.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
206206
@" supports back to %d!",
207207
objcRuntimeVersion, GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
208208
}
209+
#if defined(DEBUG) && DEBUG
210+
if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_VERSION) {
211+
// This is a version we haven't generated for yet.
212+
NSLog(@"WARNING: Code from generated Objective-C proto from an older version of the library is "
213+
@"being used. Please regenerate with the current version as the code will stop working "
214+
@"in a future release.");
215+
}
216+
#endif
209217
}
210218

211219
void GPBRuntimeMatchFailure(void) {

objectivec/Tests/GPBMessageTests+ClassNames.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#import "GPBMessage.h"
1515
#import "GPBRootObject_PackagePrivate.h"
1616

17+
#pragma clang diagnostic push
18+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
19+
1720
// Support classes for tests using old class name (vs classrefs) interfaces.
1821
GPB_FINAL @interface MessageLackingClazzRoot : GPBRootObject
1922
@end
@@ -107,6 +110,8 @@ + (GPBExtensionRegistry *)extensionRegistry {
107110
}
108111
@end
109112

113+
#pragma clang diagnostic pop
114+
110115
@interface MessageClassNameTests : GPBTestCase
111116
@end
112117

0 commit comments

Comments
 (0)