From e1e8f1e2227be7f335a9915699d4ccb547cc4d6e Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Fri, 28 Jul 2023 19:59:51 -0700 Subject: [PATCH] upb: create upb/base/BUILD The next in a series of CLs to split upb/BUILD into subdirs. PiperOrigin-RevId: 552010931 --- BUILD | 100 +++++++++++++++--------- benchmarks/BUILD | 1 + benchmarks/benchmark.cc | 2 +- cmake/BUILD.bazel | 1 + protos/BUILD | 1 + python/dist/BUILD.bazel | 1 + upb/base/BUILD | 70 +++++++++++++++++ upb/base/{ => internal}/log2.h | 0 upb/collections/map_sorter.c | 2 +- upb/hash/common.c | 2 +- upb/message/message.c | 2 +- upb/message/tagged_ptr.h | 4 +- upb/message/typedef.h | 35 +++++++++ upb/mini_descriptor/BUILD | 4 +- upb/mini_descriptor/internal/base92.h | 2 +- upb/mini_descriptor/internal/encode.c | 2 +- upb/mini_descriptor/internal/encode.hpp | 2 +- upb/mini_table/BUILD | 4 + upb/mini_table/internal/message.h | 3 +- upb/test/BUILD | 1 + 20 files changed, 190 insertions(+), 49 deletions(-) create mode 100644 upb/base/BUILD rename upb/base/{ => internal}/log2.h (100%) create mode 100644 upb/message/typedef.h diff --git a/BUILD b/BUILD index e71f1f972d..0cf69bb541 100644 --- a/BUILD +++ b/BUILD @@ -130,9 +130,6 @@ cc_library( "upb/alloc.h", "upb/arena.h", "upb/array.h", - "upb/base/descriptor_constants.h", - "upb/base/status.h", - "upb/base/string_view.h", "upb/collections/array.h", "upb/decode.h", "upb/encode.h", @@ -155,34 +152,19 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":base", + ":base_internal", ":collections_internal", ":fastdecode", ":hash", ":lex", ":mem", ":message_internal", + ":mini_table", ":port", ":wire", - "//upb/mini_table", ], ) -cc_library( - name = "base", - srcs = [ - "upb/base/status.c", - ], - hdrs = [ - "upb/base/descriptor_constants.h", - "upb/base/log2.h", - "upb/base/status.h", - "upb/base/string_view.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//:__subpackages__"], - deps = [":port"], -) - cc_library( name = "message", hdrs = [ @@ -191,25 +173,14 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":base", ":mem", ":message_internal", + ":mini_table", ":port", - "//upb/mini_table", ], ) -alias( - name = "mini_table", - actual = "//upb/mini_table", - visibility = ["//:friends"], -) - -alias( - name = "mini_table_internal", - actual = "//upb/mini_table:internal", - visibility = ["//:friends"], -) - cc_library( name = "message_internal", srcs = [ @@ -224,10 +195,11 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":base", + ":base_internal", ":hash", ":mem", + ":mini_table", ":port", - "//upb/mini_table", ], ) @@ -237,6 +209,7 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//:friends"], deps = [ + ":message_typedef", ":port", ], ) @@ -268,6 +241,7 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":base", ":collections_internal", ":eps_copy_input_stream", ":message_internal", @@ -337,10 +311,21 @@ cc_library( ], ) +cc_library( + name = "message_typedef", + hdrs = [ + "upb/message/typedef.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [], +) + cc_test( name = "message_accessors_test", srcs = ["upb/message/accessors_test.cc"], deps = [ + ":base", ":collections", ":message_accessors", ":port", @@ -362,6 +347,7 @@ cc_test( name = "message_promote_test", srcs = ["upb/message/promote_test.cc"], deps = [ + ":base", ":collections", ":message_accessors", ":message_copy", @@ -384,6 +370,7 @@ cc_test( name = "message_copy_test", srcs = ["upb/message/copy_test.cc"], deps = [ + ":base", ":collections", ":message_accessors", ":message_copy", @@ -429,6 +416,8 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ + ":base", + ":base_internal", ":collections_internal", ":message_accessors", ":message_accessors_internal", @@ -548,13 +537,14 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ ":base", + ":base_internal", ":hash", ":mem", ":message_internal", ":message_rep_internal", ":message_tagged_ptr", + ":mini_table", ":port", - "//upb/mini_table", ], ) @@ -589,6 +579,7 @@ bootstrap_cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":base", ":collections", ":port", ":upb", @@ -653,6 +644,7 @@ bootstrap_cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":base", ":collections", ":hash", ":message_accessors", @@ -688,12 +680,38 @@ cc_library( ], ) +# Aliases ###################################################################### + +alias( + name = "base", + actual = "//upb/base", + visibility = ["//visibility:public"], +) + +alias( + name = "base_internal", + actual = "//upb/base:internal", + visibility = ["//visibility:public"], +) + alias( name = "json", actual = "//upb/json", visibility = ["//visibility:public"], ) +alias( + name = "mini_table", + actual = "//upb/mini_table", + visibility = ["//:friends"], +) + +alias( + name = "mini_table_internal", + actual = "//upb/mini_table:internal", + visibility = ["//:friends"], +) + # Tests ######################################################################## cc_test( @@ -720,6 +738,7 @@ cc_test( name = "collections_test", srcs = ["upb/collections/test.cc"], deps = [ + ":base", ":collections", ":upb", "@com_google_googletest//:gtest_main", @@ -840,9 +859,9 @@ cc_library( deps = [ ":mem", ":message_internal", + ":mini_table", ":port", ":wire_internal", - "//upb/mini_table", ], ) @@ -872,10 +891,10 @@ cc_library( ":message_accessors_internal", ":message_internal", ":message_rep_internal", + ":mini_table", ":port", ":wire_reader", ":wire_types", - "//upb/mini_table", "@utf8_range", ], ) @@ -936,6 +955,7 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ ":base", + ":base_internal", ":mem", ":port", ], @@ -1004,6 +1024,7 @@ upb_amalgamation( ":message_internal", ":message_rep_internal", ":message_tagged_ptr", + ":message_typedef", ":port", ":reflection_internal", ":reflection", @@ -1011,6 +1032,7 @@ upb_amalgamation( ":wire_internal", ":wire_reader", ":wire_types", + "//upb/base:internal", "//upb/mini_descriptor:encode_internal", "//upb/mini_descriptor:internal", "//upb/mini_descriptor:mini_descriptor", @@ -1050,6 +1072,7 @@ upb_amalgamation( ":message_internal", ":message_rep_internal", ":message_tagged_ptr", + ":message_typedef", ":port", ":reflection_internal", ":reflection", @@ -1057,6 +1080,7 @@ upb_amalgamation( ":wire_internal", ":wire_reader", ":wire_types", + "//upb/base:internal", "//upb/mini_descriptor:encode_internal", "//upb/mini_descriptor:internal", "//upb/mini_descriptor:mini_descriptor", @@ -1097,6 +1121,7 @@ upb_amalgamation( ":message_internal", ":message_rep_internal", ":message_tagged_ptr", + ":message_typedef", ":port", ":reflection_internal", ":reflection", @@ -1104,6 +1129,7 @@ upb_amalgamation( ":wire_internal", ":wire_reader", ":wire_types", + "//upb/base:internal", "//upb/mini_descriptor:encode_internal", "//upb/mini_descriptor:internal", "//upb/mini_descriptor:mini_descriptor", diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 92873f3bdc..243274a189 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -95,6 +95,7 @@ cc_test( "//:descriptor_upb_proto", "//:mem", "//:reflection", + "//upb/base:internal", "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/container:flat_hash_set", "@com_google_protobuf//:protobuf", diff --git a/benchmarks/benchmark.cc b/benchmarks/benchmark.cc index a0b9d4c105..1fc6c421d3 100644 --- a/benchmarks/benchmark.cc +++ b/benchmarks/benchmark.cc @@ -37,7 +37,7 @@ #include "benchmarks/descriptor.upb.h" #include "benchmarks/descriptor.upbdefs.h" #include "benchmarks/descriptor_sv.pb.h" -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/mem/arena.h" #include "upb/reflection/def.hpp" diff --git a/cmake/BUILD.bazel b/cmake/BUILD.bazel index 06c2cf665f..9ddc669a07 100644 --- a/cmake/BUILD.bazel +++ b/cmake/BUILD.bazel @@ -100,6 +100,7 @@ sh_test( ":copy_protos", ":gen_cmakelists", "//:source_files", + "//upb/base:source_files", "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "@utf8_range//:utf8_range_srcs", diff --git a/protos/BUILD b/protos/BUILD index a5a84b4a64..c9c8672d92 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -49,6 +49,7 @@ cc_library( deps = [ ":protos", ":protos_traits", + "//:base", "//:collections_internal", "//:message_copy", "//:mini_table", diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index 6e758f21af..ccf226052b 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -214,6 +214,7 @@ pkg_tar( "//:LICENSE", "//:source_files", "//python:message_srcs", + "//upb/base:source_files", "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "//upb/util:source_files", diff --git a/upb/base/BUILD b/upb/base/BUILD new file mode 100644 index 0000000000..cf9089e2eb --- /dev/null +++ b/upb/base/BUILD @@ -0,0 +1,70 @@ +# Copyright (c) 2009-2021, Google LLC +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Google LLC nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") + +cc_library( + name = "base", + srcs = [ + "status.c", + ], + hdrs = [ + "descriptor_constants.h", + "status.h", + "string_view.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + ":internal", + "//:port", + ], +) + +cc_library( + name = "internal", + hdrs = [ + "internal/log2.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = ["//:port"], +) + +# begin:github_only +filegroup( + name = "source_files", + srcs = glob( + [ + "**/*.c", + "**/*.h", + ], + ), + visibility = [ + "//cmake:__pkg__", + "//python/dist:__pkg__", + ] +) +# end:github_only diff --git a/upb/base/log2.h b/upb/base/internal/log2.h similarity index 100% rename from upb/base/log2.h rename to upb/base/internal/log2.h diff --git a/upb/collections/map_sorter.c b/upb/collections/map_sorter.c index c18e03c784..e1a98e5474 100644 --- a/upb/collections/map_sorter.c +++ b/upb/collections/map_sorter.c @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/collections/map_sorter_internal.h" // Must be last. diff --git a/upb/hash/common.c b/upb/hash/common.c index 5095ef28e7..8804bc52d7 100644 --- a/upb/hash/common.c +++ b/upb/hash/common.c @@ -33,7 +33,7 @@ #include -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/hash/int_table.h" #include "upb/hash/str_table.h" diff --git a/upb/message/message.c b/upb/message/message.c index b47cddd2df..61566e6548 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -29,7 +29,7 @@ #include -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/message/internal.h" // Must be last. diff --git a/upb/message/tagged_ptr.h b/upb/message/tagged_ptr.h index 64602923b0..8c36e72dee 100644 --- a/upb/message/tagged_ptr.h +++ b/upb/message/tagged_ptr.h @@ -30,6 +30,8 @@ #include +#include "upb/message/typedef.h" + // Must be last. #include "upb/port/def.inc" @@ -37,8 +39,6 @@ extern "C" { #endif -typedef void upb_Message; - // When a upb_Message* is stored in a message, array, or map, it is stored in a // tagged form. If the tag bit is set, the referenced upb_Message is of type // _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of diff --git a/upb/message/typedef.h b/upb/message/typedef.h new file mode 100644 index 0000000000..ab3136d857 --- /dev/null +++ b/upb/message/typedef.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2009-2021, Google LLC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Google LLC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UPB_MESSAGE_TYPEDEF_H_ +#define UPB_MESSAGE_TYPEDEF_H_ + +// This typedef needs its own header to resolve a circular dependency between +// messages and mini tables. +typedef void upb_Message; + +#endif /* UPB_MESSAGE_TYPEDEF_H_ */ diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index 6d90998101..e9efbccf14 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -19,6 +19,7 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ "//:base", + "//:base_internal", "//:port", ], ) @@ -41,9 +42,9 @@ cc_library( ":internal", "//:base", "//:mem", + "//:mini_table", "//:mini_table_internal", "//:port", - "//upb/mini_table", ], ) @@ -61,6 +62,7 @@ cc_library( deps = [ ":internal", "//:base", + "//:base_internal", "//:port", ], ) diff --git a/upb/mini_descriptor/internal/base92.h b/upb/mini_descriptor/internal/base92.h index 7628baccb1..33572c65c8 100644 --- a/upb/mini_descriptor/internal/base92.h +++ b/upb/mini_descriptor/internal/base92.h @@ -28,7 +28,7 @@ #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_descriptor/internal/encode.c b/upb/mini_descriptor/internal/encode.c index d7aeeddcc1..4b00c683f4 100644 --- a/upb/mini_descriptor/internal/encode.c +++ b/upb/mini_descriptor/internal/encode.c @@ -27,7 +27,7 @@ #include "upb/mini_descriptor/internal/encode.h" -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/mini_descriptor/internal/base92.h" #include "upb/mini_descriptor/internal/modifiers.h" #include "upb/mini_descriptor/internal/wire_constants.h" diff --git a/upb/mini_descriptor/internal/encode.hpp b/upb/mini_descriptor/internal/encode.hpp index 1d22a76469..9b23cfe13f 100644 --- a/upb/mini_descriptor/internal/encode.hpp +++ b/upb/mini_descriptor/internal/encode.hpp @@ -30,7 +30,7 @@ #include -#include "upb/base/log2.h" +#include "upb/base/internal/log2.h" #include "upb/mini_descriptor/internal/encode.h" namespace upb { diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 759660ece2..b8b5df74c0 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -48,8 +48,10 @@ cc_library( deps = [ ":internal", "//:base", + "//:base_internal", "//:hash", "//:mem", + "//:message_typedef", "//:port", ], ) @@ -70,6 +72,8 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//:base", + "//:base_internal", + "//:message_typedef", "//:port", ], ) diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index 7e928d52f6..18c0568656 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -28,13 +28,12 @@ #ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#include "upb/message/typedef.h" #include "upb/mini_table/internal/field.h" // Must be last. #include "upb/port/def.inc" -typedef void upb_Message; - struct upb_Decoder; typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, diff --git a/upb/test/BUILD b/upb/test/BUILD index 0d1fd7b724..97240b8094 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -187,6 +187,7 @@ cc_test( ":test_messages_proto3_upb_proto", ":test_upb_proto", "//:upb", + "//:base", "//:port", "@com_google_googletest//:gtest_main", ],