• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Conformance testing for Protobuf.
2
3load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "objc_library")
4load(
5    "@rules_pkg//pkg:mappings.bzl",
6    "pkg_filegroup",
7    "pkg_files",
8    "strip_prefix",
9)
10load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
11load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
12load("//bazel:cc_proto_library.bzl", "cc_proto_library")
13load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
14load("//bazel:java_proto_library.bzl", "java_proto_library")
15load("//bazel:proto_library.bzl", "proto_library")
16load("//build_defs:internal_shell.bzl", "inline_sh_binary")
17load("//ruby:defs.bzl", "internal_ruby_proto_library")
18
19exports_files([
20    "bazel_conformance_test_runner.sh",
21    "failure_list_cpp.txt",
22    "failure_list_csharp.txt",
23    "failure_list_java.txt",
24    "failure_list_java_lite.txt",
25    "failure_list_objc.txt",
26    "failure_list_php.txt",
27    "failure_list_php_c.txt",
28    "failure_list_python.txt",
29    "failure_list_python_cpp.txt",
30    "failure_list_python_upb.txt",
31    "failure_list_ruby.txt",
32    "failure_list_jruby.txt",
33    "failure_list_jruby_ffi.txt",
34    "text_format_failure_list_cpp.txt",
35    "text_format_failure_list_java.txt",
36    "text_format_failure_list_java_lite.txt",
37    "text_format_failure_list_php.txt",
38    "text_format_failure_list_php_c.txt",
39    "text_format_failure_list_python.txt",
40    "text_format_failure_list_python_cpp.txt",
41    "text_format_failure_list_python_upb.txt",
42])
43
44cc_proto_library(
45    name = "test_messages_proto2_proto_cc",
46    deps = ["//src/google/protobuf:test_messages_proto2_proto"],
47)
48
49cc_proto_library(
50    name = "test_messages_proto3_proto_cc",
51    deps = ["//src/google/protobuf:test_messages_proto3_proto"],
52)
53
54proto_library(
55    name = "conformance_proto",
56    srcs = ["conformance.proto"],
57    visibility = ["//visibility:public"],
58)
59
60cc_proto_library(
61    name = "conformance_cc_proto",
62    deps = [":conformance_proto"],
63)
64
65internal_csharp_proto_library(
66    name = "conformance_csharp_proto",
67    srcs = ["conformance.proto"],
68    visibility = [
69        "//csharp:__subpackages__",
70    ],
71)
72
73java_proto_library(
74    name = "conformance_java_proto",
75    visibility = [
76        "//java:__subpackages__",
77    ],
78    deps = [":conformance_proto"],
79)
80
81java_lite_proto_library(
82    name = "conformance_java_proto_lite",
83    visibility = [
84        "//java:__subpackages__",
85    ],
86    deps = [":conformance_proto"],
87)
88
89internal_objc_proto_library(
90    name = "conformance_objc_proto",
91    srcs = ["conformance.proto"],
92    visibility = [
93        "//conformance:__pkg__",
94        "//objc:__pkg__",
95    ],
96)
97
98internal_py_proto_library(
99    name = "conformance_py_proto",
100    srcs = ["conformance.proto"],
101    srcs_version = "PY2AND3",
102    visibility = [
103        "//python:__subpackages__",
104    ],
105)
106
107internal_php_proto_library(
108    name = "conformance_php_proto",
109    srcs = ["conformance.proto"],
110    outs = [
111        "Conformance/ConformanceRequest.php",
112        "Conformance/ConformanceResponse.php",
113        "Conformance/FailureSet.php",
114        "Conformance/JspbEncodingConfig.php",
115        "Conformance/TestCategory.php",
116        "Conformance/WireFormat.php",
117        "GPBMetadata/Conformance.php",
118    ],
119    visibility = [
120        "//conformance:__pkg__",
121        "//php:__pkg__",
122    ],
123)
124
125internal_ruby_proto_library(
126    name = "conformance_ruby_proto",
127    srcs = ["conformance.proto"],
128    visibility = [
129        "//conformance:__pkg__",
130        "//ruby:__pkg__",
131    ],
132)
133
134cc_library(
135    name = "conformance_test",
136    testonly = 1,
137    srcs = [
138        "conformance_test.cc",
139        "conformance_test_runner.cc",
140        "failure_list_trie_node.cc",
141    ],
142    hdrs = [
143        "conformance_test.h",
144        "failure_list_trie_node.h",
145    ],
146    includes = ["."],
147    deps = [
148        ":conformance_cc_proto",
149        "//src/google/protobuf",
150        "//src/google/protobuf:descriptor_legacy",
151        "//src/google/protobuf:endian",
152        "//src/google/protobuf:protobuf_lite",
153        "//src/google/protobuf/util:differencer",
154        "//src/google/protobuf/util:json_util",
155        "//src/google/protobuf/util:type_resolver",
156        "@com_google_absl//absl/container:btree",
157        "@com_google_absl//absl/container:flat_hash_set",
158        "@com_google_absl//absl/log:absl_check",
159        "@com_google_absl//absl/log:absl_log",
160        "@com_google_absl//absl/status",
161        "@com_google_absl//absl/strings",
162        "@com_google_absl//absl/strings:str_format",
163        "@com_google_absl//absl/types:optional",
164    ],
165)
166
167cc_test(
168    name = "failure_list_trie_node_test",
169    srcs = ["failure_list_trie_node_test.cc"],
170    deps = [
171        ":conformance_test",
172        "@com_google_absl//absl/status",
173        "@com_google_absl//absl/status:statusor",
174        "@com_google_absl//absl/strings",
175        "@com_google_absl//absl/types:optional",
176        "@com_google_googletest//:gtest",
177        "@com_google_googletest//:gtest_main",
178    ],
179)
180
181# Add more meta-testing here. This is not to be confused with a conformance test itself.
182test_suite(
183    name = "conformance_framework_tests",
184    tests = ["failure_list_trie_node_test"],
185)
186
187cc_library(
188    name = "binary_json_conformance_suite",
189    testonly = 1,
190    srcs = ["binary_json_conformance_suite.cc"],
191    hdrs = ["binary_json_conformance_suite.h"],
192    deps = [
193        ":conformance_cc_proto",
194        ":conformance_test",
195        ":test_messages_proto2_proto_cc",
196        ":test_messages_proto3_proto_cc",
197        "//conformance/test_protos:test_messages_edition2023_cc_proto",
198        "//editions:test_messages_proto2_editions_cc_proto",
199        "//editions:test_messages_proto3_editions_cc_proto",
200        "//src/google/protobuf",
201        "//src/google/protobuf:protobuf_lite",
202        "//src/google/protobuf/json",
203        "//src/google/protobuf/util:type_resolver",
204        "@com_google_absl//absl/log:absl_check",
205        "@com_google_absl//absl/log:absl_log",
206        "@com_google_absl//absl/log:die_if_null",
207        "@com_google_absl//absl/status",
208        "@com_google_absl//absl/strings",
209        "@com_google_absl//absl/strings:str_format",
210        "@jsoncpp",
211    ],
212)
213
214cc_library(
215    name = "text_format_conformance_suite",
216    testonly = 1,
217    srcs = ["text_format_conformance_suite.cc"],
218    hdrs = ["text_format_conformance_suite.h"],
219    deps = [
220        ":conformance_test",
221        ":test_messages_proto2_proto_cc",
222        ":test_messages_proto3_proto_cc",
223        "//conformance/test_protos:test_messages_edition2023_cc_proto",
224        "//editions:test_messages_proto2_editions_cc_proto",
225        "//editions:test_messages_proto3_editions_cc_proto",
226        "//src/google/protobuf",
227        "@com_google_absl//absl/log:absl_log",
228        "@com_google_absl//absl/log:die_if_null",
229        "@com_google_absl//absl/strings",
230        "@com_google_absl//absl/strings:str_format",
231    ],
232)
233
234cc_binary(
235    name = "conformance_test_runner",
236    testonly = 1,
237    srcs = ["conformance_test_main.cc"],
238    visibility = ["//visibility:public"],
239    deps = [
240        ":binary_json_conformance_suite",
241        ":conformance_test",
242        ":text_format_conformance_suite",
243        "@com_google_absl//absl/strings:str_format",
244    ],
245)
246
247cc_binary(
248    name = "conformance_cpp",
249    testonly = 1,
250    srcs = ["conformance_cpp.cc"],
251    visibility = ["//src:__subpackages__"],
252    deps = [
253        ":conformance_cc_proto",
254        "//:protobuf",
255        "//:test_messages_proto2_cc_proto",
256        "//:test_messages_proto3_cc_proto",
257        "//conformance/test_protos:test_messages_edition2023_cc_proto",
258        "//editions:test_messages_proto2_editions_cc_proto",
259        "//editions:test_messages_proto3_editions_cc_proto",
260        "//src/google/protobuf",
261        "//src/google/protobuf:port",
262        "//src/google/protobuf:protobuf_lite",
263        "//src/google/protobuf/json",
264        "//src/google/protobuf/stubs",
265        "//src/google/protobuf/util:json_util",
266        "//src/google/protobuf/util:type_resolver",
267        "@com_google_absl//absl/log:absl_check",
268        "@com_google_absl//absl/log:absl_log",
269        "@com_google_absl//absl/status",
270        "@com_google_absl//absl/status:statusor",
271        "@com_google_absl//absl/strings",
272    ],
273)
274
275java_binary(
276    name = "conformance_java",
277    testonly = 1,
278    srcs = ["ConformanceJava.java"],
279    main_class = "ConformanceJava",
280    visibility = [
281        "//java:__subpackages__",
282    ],
283    deps = [
284        ":conformance_java_proto",
285        "//:protobuf_java",
286        "//:protobuf_java_util",
287        "//:test_messages_proto2_java_proto",
288        "//:test_messages_proto3_java_proto",
289        "//conformance/test_protos:test_messages_edition2023_java_proto",
290        "//editions:test_messages_proto2_editions_java_proto",
291        "//editions:test_messages_proto3_editions_java_proto",
292    ],
293)
294
295java_binary(
296    name = "conformance_java_lite",
297    testonly = 1,
298    srcs = ["ConformanceJavaLite.java"],
299    main_class = "ConformanceJavaLite",
300    visibility = [
301        "//java:__subpackages__",
302    ],
303    deps = [
304        ":conformance_java_proto_lite",
305        "//:protobuf_java_util",
306        "//:protobuf_javalite",
307        "//:test_messages_proto2_java_proto_lite",
308        "//:test_messages_proto3_java_proto_lite",
309        "//conformance/test_protos:test_messages_edition2023_java_proto_lite",
310        "//editions:test_messages_proto2_editions_java_proto_lite",
311        "//editions:test_messages_proto3_editions_java_proto_lite",
312    ],
313)
314
315py_binary(
316    name = "conformance_python",
317    testonly = 1,
318    srcs = ["conformance_python.py"],
319    imports = [
320        "..",
321        "../python",
322    ],
323    srcs_version = "PY2AND3",
324    visibility = ["//python:__subpackages__"],
325    deps = [
326        ":conformance_py_proto",
327        "//:protobuf_python",
328        "//conformance/test_protos:test_messages_edition2023_py_proto",
329        "//editions:test_messages_proto2_editions_py_pb2",
330        "//editions:test_messages_proto3_editions_py_pb2",
331        "//python:_message",  # Make upb visible if we need it.
332        "//python:conformance_test_py_proto",
333    ],
334)
335
336py_binary(
337    name = "update_failure_list",
338    srcs = ["update_failure_list.py"],
339)
340
341inline_sh_binary(
342    name = "conformance_php",
343    testonly = 1,
344    srcs = [
345        "autoload.php",
346        "conformance_php.php",
347    ],
348    cmd = """
349        php -d include_path=conformance:src/google/protobuf \\
350            -d auto_prepend_file=$(rootpath autoload.php) \\
351            $(rootpath conformance_php.php)
352    """,
353    visibility = ["//php:__subpackages__"],
354    deps = [
355        ":conformance_php_proto",
356        "//:test_messages_proto3_php_proto",
357        "//php:source_files",
358    ],
359)
360
361inline_sh_binary(
362    name = "conformance_php_c",
363    testonly = 1,
364    srcs = [
365        "conformance_php.php",
366        "//php:extension",
367    ],
368    cmd = """
369        php -dextension=$(rootpath //php:extension) \\
370            -d include_path=conformance:src/google/protobuf:editions/golden \\
371            $(rootpath conformance_php.php)
372    """,
373    visibility = ["//php:__subpackages__"],
374    deps = [
375        ":conformance_php_proto",
376        "//:test_messages_proto3_php_proto",
377        "//editions:test_messages_proto3_editions_php_proto",
378    ],
379)
380
381inline_sh_binary(
382    name = "conformance_csharp",
383    testonly = 1,
384    srcs = ["//csharp/src/Google.Protobuf.Conformance:conformance_dll"],
385    cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
386    visibility = ["//csharp:__subpackages__"],
387    deps = [
388        "//conformance/test_protos:test_messages_edition2023_csharp_proto",
389        "//csharp/src/Google.Protobuf.Conformance:conformance_runfiles",
390    ],
391)
392
393objc_library(
394    name = "conformance_objc_lib",
395    testonly = 1,
396    non_arc_srcs = ["conformance_objc.m"],
397    # See https://github.com/bazelbuild/bazel/issues/12897.
398    tags = ["manual"],
399    deps = [
400        ":conformance_objc_proto",
401        "//:test_messages_proto2_objc_proto",
402        "//:test_messages_proto3_objc_proto",
403        "//conformance/test_protos:test_messages_edition2023_objc_proto",
404        "//editions:test_messages_proto2_editions_objc_proto",
405        "//editions:test_messages_proto3_editions_objc_proto",
406    ],
407)
408
409cc_binary(
410    name = "conformance_objc",
411    testonly = 1,
412    # See https://github.com/bazelbuild/bazel/issues/12897.
413    tags = ["manual"],
414    visibility = ["//objectivec:__subpackages__"],
415    deps = [":conformance_objc_lib"],
416)
417
418ruby_binary(
419    name = "conformance_ruby",
420    testonly = True,
421    srcs = ["conformance_ruby.rb"],
422    visibility = ["//ruby:__subpackages__"],
423    deps = [
424        ":conformance_ruby_proto",
425        "//conformance/test_protos:test_messages_edition2023_ruby_proto",
426        "//ruby:conformance_editions_test_ruby_proto",
427        "//ruby:conformance_test_ruby_proto",
428        "//ruby:protobuf",
429    ],
430)
431
432################################################################################
433# Distribution files
434################################################################################
435
436filegroup(
437    name = "all_files",
438    srcs = glob(["**/*"]),
439    visibility = ["//src/google/protobuf/compiler/csharp:__pkg__"],
440)
441
442pkg_files(
443    name = "dist_files",
444    srcs = glob(
445        ["**/*"],
446        exclude = [
447            # Handled by dist_scripts:
448            "bazel_conformance_test_runner.sh",
449
450            # The following are not in autotools dist:
451            "autoload.php",
452            "failure_list_jruby.txt",
453            "update_failure_list.py",
454        ],
455    ),
456    strip_prefix = strip_prefix.from_root(""),
457    visibility = ["//pkg:__pkg__"],
458)
459
460pkg_filegroup(
461    name = "all_dist_files",
462    srcs = [
463        ":dist_files",
464    ],
465    visibility = ["//pkg:__pkg__"],
466)
467