Skip to content

Commit ea81024

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Refactor editions infrastructure to a top-level directory.
The only public target here is the edition defaults helper macro, which can be used by external runtimes and plugins. None of this code is C++-specific though, and should be organized higher up. Appropriate aliases are also placed at the top level for public targets PiperOrigin-RevId: 625392504
1 parent 57772cd commit ea81024

File tree

73 files changed

+142
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+142
-118
lines changed

BUILD.bazel

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ alias(
168168
# Built-in runtime protos: these are part of protobuf's internal
169169
# implementation, but are not Well-Known Types.
170170

171-
alias(
172-
name = "cpp_features_proto",
173-
actual = "//src/google/protobuf:cpp_features_proto", # proto_library
174-
visibility = ["//visibility:public"],
175-
)
176-
177171
alias(
178172
name = "descriptor_proto",
179173
actual = "//src/google/protobuf:descriptor_proto", # proto_library
@@ -334,6 +328,12 @@ alias(
334328
visibility = ["//visibility:public"],
335329
)
336330

331+
alias(
332+
name = "cpp_features_proto",
333+
actual = "//src/google/protobuf:cpp_features_proto", # proto_library
334+
visibility = ["//visibility:public"],
335+
)
336+
337337
################################################################################
338338
# Java support
339339
################################################################################
@@ -368,6 +368,12 @@ alias(
368368
visibility = ["//visibility:public"],
369369
)
370370

371+
alias(
372+
name = "java_features_proto",
373+
actual = "//java/core:java_features_proto", # proto_library
374+
visibility = ["//visibility:public"],
375+
)
376+
371377
################################################################################
372378
# Python support
373379
################################################################################

cmake/conformance.cmake

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ add_custom_command(
3030
--cpp_out=${protobuf_BINARY_DIR}
3131
)
3232

33+
34+
add_custom_command(
35+
OUTPUT
36+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.h
37+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.cc
38+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.h
39+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.cc
40+
DEPENDS ${protobuf_PROTOC_EXE}
41+
${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto3_editions.proto
42+
${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto2_editions.proto
43+
COMMAND ${protobuf_PROTOC_EXE}
44+
${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto3_editions.proto
45+
${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto2_editions.proto
46+
--proto_path=${protobuf_SOURCE_DIR}
47+
--proto_path=${protobuf_SOURCE_DIR}/src
48+
--cpp_out=${protobuf_BINARY_DIR}
49+
)
50+
3351
file(MAKE_DIRECTORY ${protobuf_BINARY_DIR}/src)
3452

3553
add_custom_command(
@@ -38,20 +56,12 @@ add_custom_command(
3856
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.cc
3957
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.h
4058
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.cc
41-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.pb.h
42-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.pb.cc
43-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.pb.h
44-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.pb.cc
4559
DEPENDS ${protobuf_PROTOC_EXE}
4660
${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto
4761
${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto
48-
${protobuf_SOURCE_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto
49-
${protobuf_SOURCE_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
5062
COMMAND ${protobuf_PROTOC_EXE}
5163
${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto
5264
${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto
53-
${protobuf_SOURCE_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto
54-
${protobuf_SOURCE_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
5565
--proto_path=${protobuf_SOURCE_DIR}/src
5666
--cpp_out=${protobuf_BINARY_DIR}/src
5767
)
@@ -61,14 +71,14 @@ add_library(libconformance_common STATIC
6171
${protobuf_BINARY_DIR}/conformance/conformance.pb.cc
6272
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h
6373
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc
74+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.h
75+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.cc
76+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.h
77+
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.cc
6478
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.h
6579
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.cc
6680
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.h
6781
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.cc
68-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.pb.h
69-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto3_editions.pb.cc
70-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.pb.h
71-
${protobuf_BINARY_DIR}/src/google/protobuf/editions/golden/test_messages_proto2_editions.pb.cc
7282
)
7383
target_link_libraries(libconformance_common
7484
${protobuf_LIB_PROTOBUF}

conformance/BUILD.bazel

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ load(
88
"strip_prefix",
99
)
1010
load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
11-
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")
11+
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
1212
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
1313
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
1414
load("//ruby:defs.bzl", "internal_ruby_proto_library")
@@ -167,10 +167,10 @@ cc_library(
167167
":test_messages_proto2_proto_cc",
168168
":test_messages_proto3_proto_cc",
169169
"//conformance/test_protos:test_messages_edition2023_cc_proto",
170+
"//editions:test_messages_proto2_editions_cc_proto",
171+
"//editions:test_messages_proto3_editions_cc_proto",
170172
"//src/google/protobuf",
171173
"//src/google/protobuf:protobuf_lite",
172-
"//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto",
173-
"//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto",
174174
"//src/google/protobuf/json",
175175
"//src/google/protobuf/util:type_resolver",
176176
"@com_google_absl//absl/log:absl_check",
@@ -192,9 +192,9 @@ cc_library(
192192
":test_messages_proto2_proto_cc",
193193
":test_messages_proto3_proto_cc",
194194
"//conformance/test_protos:test_messages_edition2023_cc_proto",
195+
"//editions:test_messages_proto2_editions_cc_proto",
196+
"//editions:test_messages_proto3_editions_cc_proto",
195197
"//src/google/protobuf",
196-
"//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto",
197-
"//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto",
198198
"@com_google_absl//absl/log:absl_log",
199199
"@com_google_absl//absl/log:die_if_null",
200200
"@com_google_absl//absl/strings",
@@ -226,11 +226,11 @@ cc_binary(
226226
"//:test_messages_proto2_cc_proto",
227227
"//:test_messages_proto3_cc_proto",
228228
"//conformance/test_protos:test_messages_edition2023_cc_proto",
229+
"//editions:test_messages_proto2_editions_cc_proto",
230+
"//editions:test_messages_proto3_editions_cc_proto",
229231
"//src/google/protobuf",
230232
"//src/google/protobuf:port",
231233
"//src/google/protobuf:protobuf_lite",
232-
"//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto",
233-
"//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto",
234234
"//src/google/protobuf/stubs",
235235
"//src/google/protobuf/util:json_util",
236236
"//src/google/protobuf/util:type_resolver",
@@ -257,8 +257,8 @@ java_binary(
257257
"//:test_messages_proto2_java_proto",
258258
"//:test_messages_proto3_java_proto",
259259
"//conformance/test_protos:test_messages_edition2023_java_proto",
260-
"//src/google/protobuf/editions:test_messages_proto2_editions_java_proto",
261-
"//src/google/protobuf/editions:test_messages_proto3_editions_java_proto",
260+
"//editions:test_messages_proto2_editions_java_proto",
261+
"//editions:test_messages_proto3_editions_java_proto",
262262
],
263263
)
264264

@@ -277,8 +277,8 @@ java_binary(
277277
"//:test_messages_proto2_java_proto_lite",
278278
"//:test_messages_proto3_java_proto_lite",
279279
"//conformance/test_protos:test_messages_edition2023_java_proto_lite",
280-
"//src/google/protobuf/editions:test_messages_proto2_editions_java_proto_lite",
281-
"//src/google/protobuf/editions:test_messages_proto3_editions_java_proto_lite",
280+
"//editions:test_messages_proto2_editions_java_proto_lite",
281+
"//editions:test_messages_proto3_editions_java_proto_lite",
282282
],
283283
)
284284

@@ -296,6 +296,8 @@ py_binary(
296296
":conformance_py_proto",
297297
"//:protobuf_python",
298298
"//conformance/test_protos:test_messages_edition2023_py_proto",
299+
"//editions:test_messages_proto2_editions_py_pb2",
300+
"//editions:test_messages_proto3_editions_py_pb2",
299301
"//python:_message", # Make upb visible if we need it.
300302
"//python:conformance_test_py_proto",
301303
],
@@ -363,8 +365,8 @@ objc_library(
363365
"//:test_messages_proto2_objc_proto",
364366
"//:test_messages_proto3_objc_proto",
365367
"//conformance/test_protos:test_messages_edition2023_objc_proto",
366-
"//src/google/protobuf/editions:test_messages_proto2_editions_objc_proto",
367-
"//src/google/protobuf/editions:test_messages_proto3_editions_objc_proto",
368+
"//editions:test_messages_proto2_editions_objc_proto",
369+
"//editions:test_messages_proto3_editions_objc_proto",
368370
],
369371
)
370372

@@ -385,6 +387,7 @@ ruby_binary(
385387
deps = [
386388
":conformance_ruby_proto",
387389
"//conformance/test_protos:test_messages_edition2023_ruby_proto",
390+
"//ruby:conformance_editions_test_ruby_proto",
388391
"//ruby:conformance_test_ruby_proto",
389392
"//ruby:protobuf",
390393
],

conformance/binary_json_conformance_suite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include "conformance/conformance.pb.h"
2828
#include "conformance_test.h"
2929
#include "conformance/test_protos/test_messages_edition2023.pb.h"
30-
#include "google/protobuf/editions/golden/test_messages_proto2_editions.pb.h"
31-
#include "google/protobuf/editions/golden/test_messages_proto3_editions.pb.h"
30+
#include "editions/golden/test_messages_proto2_editions.pb.h"
31+
#include "editions/golden/test_messages_proto3_editions.pb.h"
3232
#include "google/protobuf/endian.h"
3333
#include "google/protobuf/json/json.h"
3434
#include "google/protobuf/test_messages_proto2.pb.h"

conformance/conformance_cpp.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "conformance/conformance.pb.h"
2525
#include "conformance/conformance.pb.h"
2626
#include "conformance/test_protos/test_messages_edition2023.pb.h"
27-
#include "google/protobuf/editions/golden/test_messages_proto2_editions.pb.h"
28-
#include "google/protobuf/editions/golden/test_messages_proto3_editions.pb.h"
27+
#include "editions/golden/test_messages_proto2_editions.pb.h"
28+
#include "editions/golden/test_messages_proto3_editions.pb.h"
2929
#include "google/protobuf/endian.h"
3030
#include "google/protobuf/message.h"
3131
#include "google/protobuf/test_messages_proto2.pb.h"

conformance/conformance_objc.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#import <Foundation/Foundation.h>
99

1010
#import "Conformance.pbobjc.h"
11+
#import "editions/golden/TestMessagesProto2Editions.pbobjc.h"
12+
#import "editions/golden/TestMessagesProto3Editions.pbobjc.h"
1113
#import "google/protobuf/TestMessagesProto2.pbobjc.h"
1214
#import "google/protobuf/TestMessagesProto3.pbobjc.h"
13-
#import "google/protobuf/editions/golden/TestMessagesProto2Editions.pbobjc.h"
14-
#import "google/protobuf/editions/golden/TestMessagesProto3Editions.pbobjc.h"
1515
#import "test_protos/TestMessagesEdition2023.pbobjc.h"
1616

1717
static void Die(NSString *format, ...) __dead2;

conformance/conformance_python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from google.protobuf import test_messages_proto3_pb2
2121
from conformance import conformance_pb2
2222
from conformance.test_protos import test_messages_edition2023_pb2
23-
from google.protobuf.editions.golden import test_messages_proto2_editions_pb2
24-
from google.protobuf.editions.golden import test_messages_proto3_editions_pb2
23+
from editions.golden import test_messages_proto2_editions_pb2
24+
from editions.golden import test_messages_proto3_editions_pb2
2525

2626
test_count = 0
2727
verbose = False

conformance/conformance_ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
require 'google/protobuf'
1313
require 'google/protobuf/test_messages_proto3_pb'
1414
require 'google/protobuf/test_messages_proto2_pb'
15-
require 'google/protobuf/editions/golden/test_messages_proto2_editions_pb'
16-
require 'google/protobuf/editions/golden/test_messages_proto3_editions_pb'
15+
require 'test_messages_proto2_editions_pb'
16+
require 'test_messages_proto3_editions_pb'
1717

1818
$test_count = 0
1919
$verbose = false

conformance/text_format_conformance_suite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include "absl/strings/str_format.h"
1818
#include "conformance_test.h"
1919
#include "conformance/test_protos/test_messages_edition2023.pb.h"
20-
#include "google/protobuf/editions/golden/test_messages_proto2_editions.pb.h"
21-
#include "google/protobuf/editions/golden/test_messages_proto3_editions.pb.h"
20+
#include "editions/golden/test_messages_proto2_editions.pb.h"
21+
#include "editions/golden/test_messages_proto3_editions.pb.h"
2222
#include "google/protobuf/test_messages_proto2.pb.h"
2323
#include "google/protobuf/test_messages_proto3.pb.h"
2424
#include "google/protobuf/text_format.h"

csharp/generate_protos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ $PROTOC -Isrc -I. \
7272
csharp/protos/unittest_issue6936_b.proto \
7373
csharp/protos/unittest_issue6936_c.proto \
7474
csharp/protos/unittest_selfreferential_options.proto \
75-
src/google/protobuf/editions/golden/test_messages_proto3_editions.proto \
76-
src/google/protobuf/editions/golden/test_messages_proto2_editions.proto \
75+
editions/golden/test_messages_proto3_editions.proto \
76+
editions/golden/test_messages_proto2_editions.proto \
7777
src/google/protobuf/unittest_well_known_types.proto \
7878
src/google/protobuf/test_messages_proto3.proto \
7979
src/google/protobuf/test_messages_proto2.proto \

src/google/protobuf/editions/BUILD renamed to editions/BUILD

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2-
load("@rules_python//python:proto.bzl", "py_proto_library")
3-
load("//:protobuf.bzl", "internal_objc_proto_library")
2+
load("//:protobuf.bzl", "internal_objc_proto_library", "internal_py_proto_library")
43
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
54
load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library")
65
load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
@@ -74,7 +73,6 @@ cc_library(
7473
"defaults_test_embedded.h",
7574
"defaults_test_embedded_base64.h",
7675
],
77-
strip_include_prefix = "/src",
7876
)
7977

8078
cc_test(
@@ -108,7 +106,6 @@ proto_library(
108106
name = "test_messages_proto2_editions_proto",
109107
testonly = True,
110108
srcs = ["golden/test_messages_proto2_editions.proto"],
111-
strip_import_prefix = "/src",
112109
)
113110

114111
cc_proto_library(
@@ -139,11 +136,14 @@ java_lite_proto_library(
139136
deps = [":test_messages_proto2_editions_proto"],
140137
)
141138

142-
py_proto_library(
139+
internal_py_proto_library(
143140
name = "test_messages_proto2_editions_py_pb2",
144141
testonly = True,
145-
visibility = ["//conformance:__pkg__"],
146-
deps = [":test_messages_proto2_editions_proto"],
142+
srcs = ["golden/test_messages_proto2_editions.proto"],
143+
srcs_version = "PY2AND3",
144+
visibility = [
145+
"//conformance:__pkg__",
146+
],
147147
)
148148

149149
upb_c_proto_library(
@@ -163,7 +163,6 @@ proto_library(
163163
name = "test_messages_proto3_editions_proto",
164164
testonly = True,
165165
srcs = ["golden/test_messages_proto3_editions.proto"],
166-
strip_import_prefix = "/src",
167166
deps = [
168167
"//:any_proto",
169168
"//:duration_proto",
@@ -207,11 +206,15 @@ java_lite_proto_library(
207206
deps = [":test_messages_proto3_editions_proto"],
208207
)
209208

210-
py_proto_library(
209+
internal_py_proto_library(
211210
name = "test_messages_proto3_editions_py_pb2",
212211
testonly = True,
213-
visibility = ["//conformance:__pkg__"],
214-
deps = [":test_messages_proto3_editions_proto"],
212+
srcs = ["golden/test_messages_proto3_editions.proto"],
213+
srcs_version = "PY2AND3",
214+
visibility = [
215+
"//conformance:__pkg__",
216+
],
217+
deps = ["//python:well_known_types_py_pb2"],
215218
)
216219

217220
upb_c_proto_library(
@@ -227,14 +230,13 @@ upb_proto_reflection_library(
227230
deps = ["test_messages_proto3_editions_proto"],
228231
)
229232

230-
# Export these for conformance tests until we support py_proto_library.
233+
# Export these for conformance tests for ruby codegen.
231234
exports_files(
232235
[
233236
"golden/test_messages_proto2_editions.proto",
234237
"golden/test_messages_proto3_editions.proto",
235238
],
236239
visibility = [
237-
"//python:__pkg__",
238240
"//ruby:__pkg__",
239241
],
240242
)
@@ -243,7 +245,6 @@ proto_library(
243245
name = "test_editions_default_features_proto",
244246
testonly = True,
245247
srcs = ["proto/test_editions_default_features.proto"],
246-
strip_import_prefix = "/src",
247248
)
248249

249250
cc_proto_library(
@@ -275,3 +276,6 @@ cc_test(
275276
"@com_google_googletest//:gtest_main",
276277
],
277278
)
279+
280+
# Define a test suite to allow us to trigger these tests from //src expansions.
281+
test_suite(name = "all_tests")

0 commit comments

Comments
 (0)