[ObjC] Enable editions conformance tests.

PiperOrigin-RevId: 590328722
pull/15053/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent ddc5406170
commit 6c7c5a5d2a
  1. 2
      conformance/BUILD.bazel
  2. 29
      conformance/conformance_objc.m
  3. 1
      objectivec/BUILD.bazel
  4. 14
      protobuf.bzl
  5. 22
      src/google/protobuf/editions/BUILD
  6. 2
      src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
  7. 2
      src/google/protobuf/editions/golden/test_messages_proto3_editions.proto

@ -328,6 +328,8 @@ objc_library(
":conformance_objc_proto",
"//:test_messages_proto2_objc_proto",
"//:test_messages_proto3_objc_proto",
"//src/google/protobuf/editions:test_messages_proto2_editions_objc_proto",
"//src/google/protobuf/editions:test_messages_proto3_editions_objc_proto",
],
)

@ -10,6 +10,8 @@
#import "Conformance.pbobjc.h"
#import "google/protobuf/TestMessagesProto2.pbobjc.h"
#import "google/protobuf/TestMessagesProto3.pbobjc.h"
#import "google/protobuf/editions/golden/TestMessagesProto2Editions.pbobjc.h"
#import "google/protobuf/editions/golden/TestMessagesProto3Editions.pbobjc.h"
static void Die(NSString *format, ...) __dead2;
@ -49,22 +51,25 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) {
break;
case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: {
Class msgClass = nil;
if ([request.messageType isEqual:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) {
msgClass = [Proto3TestAllTypesProto3 class];
} else if ([request.messageType
isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) {
msgClass = [Proto2TestAllTypesProto2 class];
NSDictionary *mappings = @{
@"protobuf_test_messages.proto2.TestAllTypesProto2" : [Proto2TestAllTypesProto2 class],
@"protobuf_test_messages.proto3.TestAllTypesProto3" : [Proto3TestAllTypesProto3 class],
@"protobuf_test_messages.editions.proto2.TestAllTypesProto2" :
[EditionsProto2TestAllTypesProto2 class],
@"protobuf_test_messages.editions.proto3.TestAllTypesProto3" :
[EditionsProto3TestAllTypesProto3 class],
};
Class msgClass = mappings[request.messageType];
if (msgClass) {
NSError *error = nil;
testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
if (!testMessage) {
response.parseError = [NSString stringWithFormat:@"Parse error: %@", error];
}
} else {
response.runtimeError =
[NSString stringWithFormat:@"Protobuf request had an unknown message_type: %@",
request.messageType];
break;
}
NSError *error = nil;
testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
if (!testMessage) {
response.parseError = [NSString stringWithFormat:@"Parse error: %@", error];
}
break;
}

@ -160,6 +160,7 @@ objc_library(
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_objc.txt",
maximum_edition = "2023",
target_compatible_with = ["@platforms//os:macos"],
testee = "//conformance:conformance_objc",
)

@ -80,6 +80,7 @@ def _proto_gen_impl(ctx):
srcs = ctx.files.srcs
langs = ctx.attr.langs or []
out_type = ctx.attr.out_type
enable_editions = ctx.attr.enable_editions
deps = depset(direct = ctx.files.srcs)
source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx).rstrip("/")
@ -130,6 +131,8 @@ def _proto_gen_impl(ctx):
generated_files = []
for src in srcs:
args = []
if enable_editions:
args.append("--experimental_editions")
in_gen_dir = src.root.path == gen_dir
if in_gen_dir:
@ -247,6 +250,7 @@ _proto_gen = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = [ProtoGenInfo]),
"enable_editions": attr.bool(),
"includes": attr.string_list(),
"protoc": attr.label(
cfg = "exec",
@ -406,11 +410,11 @@ def internal_objc_proto_library(
includes = ["."],
default_runtime = Label("//:protobuf_objc"),
protoc = Label("//:protoc"),
enable_editions = False,
testonly = None,
visibility = ["//visibility:public"],
**kwargs):
"""Bazel rule to create a Objective-C protobuf library from proto source
files
"""Bazel rule to create a Objective-C protobuf library from proto sources
NOTE: the rule is only an internal workaround to generate protos. The
interface may change and the rule may be removed when bazel has introduced
@ -423,9 +427,10 @@ def internal_objc_proto_library(
outs: a list of expected output files.
proto_deps: a list of proto file dependencies that don't have a
objc_proto_library rule.
include: a string indicating the include path of the .proto files.
includes: a string indicating the include path of the .proto files.
default_runtime: the Objective-C Protobuf runtime
protoc: the label of the protocol compiler to generate the sources.
enable_editions: if editions should be enabled while invoking the compiler.
testonly: common rule attribute (see:
https://bazel.build/reference/be/common-definitions#common-attributes)
visibility: the visibility of the generated files.
@ -440,6 +445,7 @@ def internal_objc_proto_library(
testonly = testonly,
srcs = proto_deps,
protoc = protoc,
enable_editions = enable_editions,
includes = includes,
)
full_deps.append(":%s_deps_genproto" % name)
@ -454,6 +460,7 @@ def internal_objc_proto_library(
out_type = "hdrs",
includes = includes,
protoc = protoc,
enable_editions = enable_editions,
testonly = testonly,
visibility = visibility,
tags = ["manual"],
@ -467,6 +474,7 @@ def internal_objc_proto_library(
out_type = "srcs",
includes = includes,
protoc = protoc,
enable_editions = enable_editions,
testonly = testonly,
visibility = visibility,
tags = ["manual"],

@ -3,6 +3,7 @@ load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflecti
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
load("//:protobuf.bzl", "internal_objc_proto_library")
bzl_library(
name = "defaults",
@ -100,6 +101,14 @@ cc_proto_library(
deps = [":test_messages_proto2_editions_proto"],
)
internal_objc_proto_library(
name = "test_messages_proto2_editions_objc_proto",
testonly = True,
srcs = ["golden/test_messages_proto2_editions.proto"],
enable_editions = True,
visibility = ["//conformance:__pkg__"],
)
py_proto_library(
name = "test_messages_proto2_editions_py_pb2",
testonly = True,
@ -142,6 +151,19 @@ cc_proto_library(
deps = [":test_messages_proto3_editions_proto"],
)
internal_objc_proto_library(
name = "test_messages_proto3_editions_objc_proto",
testonly = True,
srcs = ["golden/test_messages_proto3_editions.proto"],
enable_editions = True,
includes = [
".",
"src",
],
proto_deps = ["//:well_known_type_protos"],
visibility = ["//conformance:__pkg__"],
)
py_proto_library(
name = "test_messages_proto3_editions_py_pb2",
testonly = True,

@ -19,7 +19,7 @@ option features.enum_type = CLOSED;
option features.repeated_field_encoding = EXPANDED;
option features.utf8_validation = NONE;
option java_package = "com.google.protobuf_test_messages.editions.proto2";
option objc_class_prefix = "Proto2";
option objc_class_prefix = "EditionsProto2";
// This is the default, but we specify it here explicitly.
option optimize_for = SPEED;

@ -24,7 +24,7 @@ import "google/protobuf/wrappers.proto";
option features.field_presence = IMPLICIT;
option java_package = "com.google.protobuf_test_messages.editions.proto3";
option objc_class_prefix = "Proto3";
option objc_class_prefix = "EditionsProto3";
// This is the default, but we specify it here explicitly.
option optimize_for = SPEED;

Loading…
Cancel
Save