From c2e99db90ba513195118461f3fe1ccf696530f09 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Tue, 31 May 2022 15:59:28 -0700 Subject: [PATCH] Add filegroups for test sources and include them in file lists. (#10049) These will be used to generate lists of sources for non-Bazel builds. --- pkg/BUILD.bazel | 76 +++++++++++++++++-- src/google/protobuf/BUILD.bazel | 34 ++++++++- src/google/protobuf/compiler/BUILD.bazel | 37 ++++++++- src/google/protobuf/compiler/cpp/BUILD.bazel | 18 +++++ .../protobuf/compiler/csharp/BUILD.bazel | 9 +++ src/google/protobuf/compiler/java/BUILD.bazel | 9 +++ .../protobuf/compiler/objectivec/BUILD.bazel | 9 +++ src/google/protobuf/compiler/php/BUILD.bazel | 9 +++ .../protobuf/compiler/python/BUILD.bazel | 9 +++ src/google/protobuf/compiler/ruby/BUILD.bazel | 9 +++ src/google/protobuf/io/BUILD.bazel | 9 +++ src/google/protobuf/stubs/BUILD.bazel | 9 +++ src/google/protobuf/util/BUILD.bazel | 18 ++++- src/google/protobuf/util/internal/BUILD.bazel | 20 ++++- 14 files changed, 264 insertions(+), 11 deletions(-) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index a2663dc2b..2a310963f 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -27,7 +27,7 @@ pkg_files( pkg_files( name = "compiler_plugin_protos_files", srcs = [ - "//src/google/protobuf/compiler:compiler_plugin_protos_files", + "//src/google/protobuf/compiler:compiler_plugin_protos_files", ], prefix = "include/google/protobuf/compiler", visibility = ["//visibility:private"], @@ -304,10 +304,33 @@ gen_file_lists( testonly = 1, out_stem = "src_file_lists", src_libs = { - # source rule: name in generated file + # {[source rule]: [name in generated file]} + # Libraries: ":protobuf": "libprotobuf", - ":protoc": "libprotoc", ":protobuf_lite": "libprotobuf_lite", + ":protoc": "libprotoc", + # Protos: + "//src/google/protobuf:well_known_type_protos": "wkt_protos", + "//src/google/protobuf:descriptor_proto": "descriptor_proto", + "//src/google/protobuf/compiler:plugin_proto": "plugin_proto", + # Test libraries: + ":lite_test_util": "lite_test_util", + ":test_util": "test_util", + # Tests and test-only protos: + "//src/google/protobuf:full_test_srcs": "protobuf_test", + "//src/google/protobuf:test_protos": "protobuf_test_protos", + "//src/google/protobuf:lite_test_srcs": "protobuf_lite_test", + "//src/google/protobuf:lite_test_protos": "protobuf_lite_test_protos", + "//src/google/protobuf/compiler:test_srcs": "compiler_test", + ":compiler_annotation_test_util": "annotation_test_util", + ":compiler_mock_code_generator": "mock_code_generator", + "//src/google/protobuf/compiler:test_proto_srcs": "compiler_test_protos", + "//src/google/protobuf/compiler:test_plugin_srcs": "test_plugin", + "//src/google/protobuf/io:test_srcs": "io_test", + ":testinglib": "testing", + "//src/google/protobuf/util:test_srcs": "util_test", + "//src/google/protobuf/util:test_proto_srcs": "util_test_protos", + "//src/google/protobuf/stubs:test_srcs": "stubs_test", }, ) @@ -362,15 +385,15 @@ cc_dist_library( }), tags = ["manual"], deps = [ + "//src/google/protobuf", "//src/google/protobuf:arena", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/io", "//src/google/protobuf/io:gzip_stream", "//src/google/protobuf/io:io_win32", "//src/google/protobuf/io:printer", "//src/google/protobuf/io:tokenizer", - "//src/google/protobuf:protobuf", - "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/stubs", "//src/google/protobuf/stubs:lite", "//src/google/protobuf/util:delimited_message_util", @@ -379,6 +402,14 @@ cc_dist_library( "//src/google/protobuf/util:json_util", "//src/google/protobuf/util:time_util", "//src/google/protobuf/util:type_resolver_util", + "//src/google/protobuf/util/internal:datapiece", + "//src/google/protobuf/util/internal:default_value", + "//src/google/protobuf/util/internal:field_mask_utility", + "//src/google/protobuf/util/internal:json", + "//src/google/protobuf/util/internal:object_writer", + "//src/google/protobuf/util/internal:protostream", + "//src/google/protobuf/util/internal:type_info", + "//src/google/protobuf/util/internal:utility", ], ) @@ -398,6 +429,41 @@ cc_dist_library( ], ) +cc_dist_library( + name = "lite_test_util", + testonly = 1, + tags = ["manual"], + deps = ["//src/google/protobuf:lite_test_util"], +) + +cc_dist_library( + name = "test_util", + testonly = 1, + tags = ["manual"], + deps = ["//src/google/protobuf:test_util"], +) + +cc_dist_library( + name = "compiler_annotation_test_util", + deps = ["//src/google/protobuf/compiler:annotation_test_util"], + testonly = 1, + tags = ["manual"], +) + +cc_dist_library( + name = "compiler_mock_code_generator", + deps = ["//src/google/protobuf/compiler:mock_code_generator"], + testonly = 1, + tags = ["manual"], +) + +cc_dist_library( + name = "testinglib", + deps = ["//src/google/protobuf/testing"], + testonly = 1, + tags = ["manual"], +) + ################################################################################ # Distribution sources ################################################################################ diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index da98ae2fb..0f0fd4df6 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -87,6 +87,10 @@ proto_library( name = "descriptor_proto", srcs = ["descriptor.proto"], strip_import_prefix = "/src", + visibility = [ + "//:__pkg__", + "//pkg:__pkg__", + ], ) ################################################################################ @@ -760,8 +764,8 @@ cc_test( ], }), deps = [ - ":protobuf", ":lite_test_util", + ":protobuf", ":test_util", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -773,8 +777,8 @@ cc_test( srcs = ["lite_unittest.cc"], deps = [ ":cc_lite_test_protos", - ":protobuf", ":lite_test_util", + ":protobuf", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "@com_google_googletest//:gtest", @@ -904,8 +908,8 @@ cc_test( }), deps = [ ":cc_test_protos", - ":protobuf", ":lite_test_util", + ":protobuf", "//src/google/protobuf/testing", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -1101,3 +1105,27 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "full_test_srcs", + srcs = glob( + include = [ + "*_test.cc", + "*unittest.cc", + ], + exclude = [ + "lite_unittest.cc", + "lite_arena_unittest.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) + +filegroup( + name = "lite_test_srcs", + srcs = [ + "lite_arena_unittest.cc", + "lite_unittest.cc", + ], + visibility = ["//pkg:__pkg__"], +) diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 8cc430b3a..419e8f5a1 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -16,7 +16,10 @@ load("//build_defs:cpp_opts.bzl", "COPTS") proto_library( name = "plugin_proto", srcs = ["plugin.proto"], - visibility = ["//:__pkg__"], + visibility = [ + "//:__pkg__", + "//pkg:__pkg__", + ], deps = ["//:descriptor_proto"], ) @@ -162,6 +165,7 @@ cc_library( hdrs = ["mock_code_generator.h"], copts = COPTS, strip_include_prefix = "/src", + visibility = ["//pkg:__pkg__"], deps = [ ":code_generator", "//src/google/protobuf/io", @@ -300,3 +304,34 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]) + [ + "//src/google/protobuf/compiler/cpp:test_srcs", + "//src/google/protobuf/compiler/csharp:test_srcs", + "//src/google/protobuf/compiler/java:test_srcs", + "//src/google/protobuf/compiler/objectivec:test_srcs", + "//src/google/protobuf/compiler/php:test_srcs", + "//src/google/protobuf/compiler/python:test_srcs", + "//src/google/protobuf/compiler/ruby:test_srcs", + ], + visibility = ["//pkg:__pkg__"], +) + +filegroup( + name = "test_plugin_srcs", + srcs = ["test_plugin.cc"], + visibility = ["//pkg:__pkg__"], +) + +filegroup( + name = "test_proto_srcs", + srcs = [ + "//src/google/protobuf/compiler/cpp:test_proto_srcs", + ], + visibility = ["//pkg:__pkg__"], +) diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index 557580926..098fd63e8 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -202,3 +202,21 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) + +filegroup( + name = "test_proto_srcs", + srcs = [ + "test_bad_identifiers.proto", + "test_large_enum_value.proto", + ], + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/csharp/BUILD.bazel b/src/google/protobuf/compiler/csharp/BUILD.bazel index 819c9dec2..ca9eb350a 100644 --- a/src/google/protobuf/compiler/csharp/BUILD.bazel +++ b/src/google/protobuf/compiler/csharp/BUILD.bazel @@ -107,3 +107,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index 66a809ec2..619d71518 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -124,3 +124,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel index 634dda248..30b6237a4 100644 --- a/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel @@ -70,3 +70,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/php/BUILD.bazel b/src/google/protobuf/compiler/php/BUILD.bazel index 82ba185fd..2ce166b31 100644 --- a/src/google/protobuf/compiler/php/BUILD.bazel +++ b/src/google/protobuf/compiler/php/BUILD.bazel @@ -32,3 +32,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/python/BUILD.bazel b/src/google/protobuf/compiler/python/BUILD.bazel index 1924a9ac5..d2d0ce12f 100644 --- a/src/google/protobuf/compiler/python/BUILD.bazel +++ b/src/google/protobuf/compiler/python/BUILD.bazel @@ -54,3 +54,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/compiler/ruby/BUILD.bazel b/src/google/protobuf/compiler/ruby/BUILD.bazel index 455865322..73b0fcf96 100644 --- a/src/google/protobuf/compiler/ruby/BUILD.bazel +++ b/src/google/protobuf/compiler/ruby/BUILD.bazel @@ -59,3 +59,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//src/google/protobuf/compiler:__pkg__"], +) diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel index be7fb4c4b..bf0d87cbd 100644 --- a/src/google/protobuf/io/BUILD.bazel +++ b/src/google/protobuf/io/BUILD.bazel @@ -145,3 +145,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//pkg:__pkg__"], +) diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel index 2446352ec..73def31f5 100644 --- a/src/google/protobuf/stubs/BUILD.bazel +++ b/src/google/protobuf/stubs/BUILD.bazel @@ -136,3 +136,12 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]), + visibility = ["//pkg:__pkg__"], +) diff --git a/src/google/protobuf/util/BUILD.bazel b/src/google/protobuf/util/BUILD.bazel index cf7bb1a4f..0443c52f6 100644 --- a/src/google/protobuf/util/BUILD.bazel +++ b/src/google/protobuf/util/BUILD.bazel @@ -218,8 +218,13 @@ filegroup( srcs = [ "json_format.proto", "json_format_proto3.proto", + "message_differencer_unittest.proto", + "//src/google/protobuf/util/internal:test_proto_srcs", + ], + visibility = [ + "//pkg:__pkg__", + "//python:__pkg__", ], - visibility = ["//python:__pkg__"], ) proto_library( @@ -281,3 +286,14 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]) + [ + "//src/google/protobuf/util/internal:test_srcs", + ], + visibility = ["//pkg:__pkg__"], +) diff --git a/src/google/protobuf/util/internal/BUILD.bazel b/src/google/protobuf/util/internal/BUILD.bazel index d42ecad51..b1cdc6990 100644 --- a/src/google/protobuf/util/internal/BUILD.bazel +++ b/src/google/protobuf/util/internal/BUILD.bazel @@ -8,7 +8,10 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("//build_defs:cpp_opts.bzl", "COPTS") package( - default_visibility = ["//src/google/protobuf/util:__pkg__"], + default_visibility = [ + "//src/google/protobuf/util:__pkg__", + "//pkg:__pkg__", + ], ) cc_library( @@ -448,3 +451,18 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//src:__pkg__"], ) + +filegroup( + name = "test_srcs", + srcs = glob([ + "*_test.cc", + "*unittest.cc", + ]) + [ + "type_info_test_helper.cc", + ], +) + +filegroup( + name = "test_proto_srcs", + srcs = glob(["testdata/*.proto"]), +)