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

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

@ -80,6 +80,7 @@ def _proto_gen_impl(ctx):
srcs = ctx.files.srcs srcs = ctx.files.srcs
langs = ctx.attr.langs or [] langs = ctx.attr.langs or []
out_type = ctx.attr.out_type out_type = ctx.attr.out_type
enable_editions = ctx.attr.enable_editions
deps = depset(direct = ctx.files.srcs) deps = depset(direct = ctx.files.srcs)
source_dir = _SourceDir(ctx) source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx).rstrip("/") gen_dir = _GenDir(ctx).rstrip("/")
@ -130,6 +131,8 @@ def _proto_gen_impl(ctx):
generated_files = [] generated_files = []
for src in srcs: for src in srcs:
args = [] args = []
if enable_editions:
args.append("--experimental_editions")
in_gen_dir = src.root.path == gen_dir in_gen_dir = src.root.path == gen_dir
if in_gen_dir: if in_gen_dir:
@ -247,6 +250,7 @@ _proto_gen = rule(
attrs = { attrs = {
"srcs": attr.label_list(allow_files = True), "srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = [ProtoGenInfo]), "deps": attr.label_list(providers = [ProtoGenInfo]),
"enable_editions": attr.bool(),
"includes": attr.string_list(), "includes": attr.string_list(),
"protoc": attr.label( "protoc": attr.label(
cfg = "exec", cfg = "exec",
@ -406,11 +410,11 @@ def internal_objc_proto_library(
includes = ["."], includes = ["."],
default_runtime = Label("//:protobuf_objc"), default_runtime = Label("//:protobuf_objc"),
protoc = Label("//:protoc"), protoc = Label("//:protoc"),
enable_editions = False,
testonly = None, testonly = None,
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
**kwargs): **kwargs):
"""Bazel rule to create a Objective-C protobuf library from proto source """Bazel rule to create a Objective-C protobuf library from proto sources
files
NOTE: the rule is only an internal workaround to generate protos. The 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 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. outs: a list of expected output files.
proto_deps: a list of proto file dependencies that don't have a proto_deps: a list of proto file dependencies that don't have a
objc_proto_library rule. 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 default_runtime: the Objective-C Protobuf runtime
protoc: the label of the protocol compiler to generate the sources. 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: testonly: common rule attribute (see:
https://bazel.build/reference/be/common-definitions#common-attributes) https://bazel.build/reference/be/common-definitions#common-attributes)
visibility: the visibility of the generated files. visibility: the visibility of the generated files.
@ -440,6 +445,7 @@ def internal_objc_proto_library(
testonly = testonly, testonly = testonly,
srcs = proto_deps, srcs = proto_deps,
protoc = protoc, protoc = protoc,
enable_editions = enable_editions,
includes = includes, includes = includes,
) )
full_deps.append(":%s_deps_genproto" % name) full_deps.append(":%s_deps_genproto" % name)
@ -454,6 +460,7 @@ def internal_objc_proto_library(
out_type = "hdrs", out_type = "hdrs",
includes = includes, includes = includes,
protoc = protoc, protoc = protoc,
enable_editions = enable_editions,
testonly = testonly, testonly = testonly,
visibility = visibility, visibility = visibility,
tags = ["manual"], tags = ["manual"],
@ -467,6 +474,7 @@ def internal_objc_proto_library(
out_type = "srcs", out_type = "srcs",
includes = includes, includes = includes,
protoc = protoc, protoc = protoc,
enable_editions = enable_editions,
testonly = testonly, testonly = testonly,
visibility = visibility, visibility = visibility,
tags = ["manual"], 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("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults") load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
load("//:protobuf.bzl", "internal_objc_proto_library")
bzl_library( bzl_library(
name = "defaults", name = "defaults",
@ -100,6 +101,14 @@ cc_proto_library(
deps = [":test_messages_proto2_editions_proto"], 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( py_proto_library(
name = "test_messages_proto2_editions_py_pb2", name = "test_messages_proto2_editions_py_pb2",
testonly = True, testonly = True,
@ -142,6 +151,19 @@ cc_proto_library(
deps = [":test_messages_proto3_editions_proto"], 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( py_proto_library(
name = "test_messages_proto3_editions_py_pb2", name = "test_messages_proto3_editions_py_pb2",
testonly = True, testonly = True,

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

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

Loading…
Cancel
Save