diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index 0412546dc5..21ec308876 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -39,7 +39,7 @@ jobs: image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: upb-bazel - bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/... ${{ matrix.config.flags }} + bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... ${{ matrix.config.flags }} exclude-targets: ${{ matrix.config.exclude-targets }} linux-gcc: @@ -58,7 +58,7 @@ jobs: image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-6.3.0-63dd26c0c7a808d92673a3e52e848189d4ab0f17" credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-gcc" - bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/... + bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... windows: strategy: @@ -75,7 +75,7 @@ jobs: with: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-windows" - bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upbc/... //python/... //protos/... //protos_generator/... + bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upb_generator/... //python/... //protos/... //protos_generator/... exclude-targets: -//python:conformance_test -//upb:def_builder_test macos: @@ -97,7 +97,7 @@ jobs: with: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-macos" - bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/... + bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... no-python: strategy: diff --git a/bazel/upb_c_proto_library.bzl b/bazel/upb_c_proto_library.bzl index 4e45d50816..108582e5cb 100644 --- a/bazel/upb_c_proto_library.bzl +++ b/bazel/upb_c_proto_library.bzl @@ -32,7 +32,7 @@ upb_c_proto_library_aspect = aspect( default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use", ), "_upb_toolchain": attr.label( - default = Label("//upbc:protoc-gen-upb_toolchain"), + default = Label("//upb_generator:protoc-gen-upb_toolchain"), ), "_cc_toolchain": attr.label( default = "@bazel_tools//tools/cpp:current_cc_toolchain", diff --git a/bazel/upb_minitable_proto_library.bzl b/bazel/upb_minitable_proto_library.bzl index ad2cb7acbb..c00d824145 100644 --- a/bazel/upb_minitable_proto_library.bzl +++ b/bazel/upb_minitable_proto_library.bzl @@ -44,7 +44,7 @@ upb_minitable_proto_library_aspect = aspect( default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use", ), "_upb_minitable_toolchain": attr.label( - default = Label("//upbc:protoc-gen-upb_minitable_toolchain"), + default = Label("//upb_generator:protoc-gen-upb_minitable_toolchain"), ), "_cc_toolchain": attr.label( default = "@bazel_tools//tools/cpp:current_cc_toolchain", diff --git a/bazel/upb_proto_reflection_library.bzl b/bazel/upb_proto_reflection_library.bzl index 23b7696d91..4181f7b650 100644 --- a/bazel/upb_proto_reflection_library.bzl +++ b/bazel/upb_proto_reflection_library.bzl @@ -29,7 +29,7 @@ _upb_proto_reflection_library_aspect = aspect( default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use", ), "_upbdefs_toolchain": attr.label( - default = Label("//upbc:protoc-gen-upbdefs_toolchain"), + default = Label("//upb_generator:protoc-gen-upbdefs_toolchain"), cfg = getattr(proto_common, "proto_lang_toolchain_cfg", "target"), ), "_cc_toolchain": attr.label( diff --git a/protos_generator/BUILD b/protos_generator/BUILD index fae587a624..ac8cfeca8b 100644 --- a/protos_generator/BUILD +++ b/protos_generator/BUILD @@ -30,7 +30,7 @@ cc_binary( ":output", "//:protobuf", "//src/google/protobuf/compiler:code_generator", - "//upbc:file_layout", + "//upb_generator:file_layout", ], ) @@ -58,10 +58,10 @@ cc_library( "//:protobuf", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", - "//upbc:common", - "//upbc:file_layout", - "//upbc:keywords", - "//upbc:names", + "//upb_generator:common", + "//upb_generator:file_layout", + "//upb_generator:keywords", + "//upb_generator:names", ], ) @@ -96,6 +96,6 @@ cc_library( visibility = ["//visibility:private"], deps = [ ":output", - "//upbc:keywords", + "//upb_generator:keywords", ], ) diff --git a/protos_generator/gen_accessors.cc b/protos_generator/gen_accessors.cc index 410a42b15b..b9101950c3 100644 --- a/protos_generator/gen_accessors.cc +++ b/protos_generator/gen_accessors.cc @@ -41,9 +41,9 @@ #include "protos_generator/gen_utils.h" #include "protos_generator/names.h" #include "protos_generator/output.h" -#include "upbc/common.h" -#include "upbc/keywords.h" -#include "upbc/names.h" +#include "upb_generator/common.h" +#include "upb_generator/keywords.h" +#include "upb_generator/names.h" namespace protos_generator { @@ -98,12 +98,12 @@ void WriteFieldAccessorsInHeader(const protobuf::Descriptor* desc, OutputIndenter i(output); auto field_names = CreateFieldNameMap(desc); - auto upbc_field_names = upbc::CreateFieldNameMap(desc); + auto upbc_field_names = upb::generator::CreateFieldNameMap(desc); for (const auto* field : FieldNumberOrder(desc)) { std::string resolved_field_name = ResolveFieldName(field, field_names); std::string resolved_upbc_name = - upbc::ResolveFieldName(field, upbc_field_names); + upb::generator::ResolveFieldName(field, upbc_field_names); WriteFieldAccessorHazzer(desc, field, resolved_field_name, resolved_upbc_name, output); WriteFieldAccessorClear(desc, field, resolved_field_name, @@ -214,14 +214,14 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Output& output) { output("namespace internal {\n"); const char arena_expression[] = "arena_"; auto field_names = CreateFieldNameMap(desc); - auto upbc_field_names = upbc::CreateFieldNameMap(desc); + auto upbc_field_names = upb::generator::CreateFieldNameMap(desc); // Generate const methods. OutputIndenter i(output); for (const auto* field : FieldNumberOrder(desc)) { std::string resolved_field_name = ResolveFieldName(field, field_names); std::string resolved_upbc_name = - upbc::ResolveFieldName(field, upbc_field_names); + upb::generator::ResolveFieldName(field, upbc_field_names); if (field->is_map()) { WriteMapAccessorDefinitions(desc, field, resolved_field_name, class_name, output); @@ -327,7 +327,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message, MessagePtrConstType(val, /* is_const */ true), MessageName(message), MessageName(val->message_type()), optional_conversion_code, converted_key_name, upbc_name, - ::upbc::MessageInit(val->message_type()->full_name())); + ::upb::generator::MessageInit(val->message_type()->full_name())); output( R"cc( bool $0::set_$1($2 key, $3 value) { @@ -341,7 +341,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message, MessagePtrConstType(val, /* is_const */ false), MessageName(message), MessageName(val->message_type()), optional_conversion_code, converted_key_name, upbc_name, - ::upbc::MessageInit(val->message_type()->full_name())); + ::upb::generator::MessageInit(val->message_type()->full_name())); output( R"cc( absl::StatusOr<$3> $0::get_$1($2 key) { @@ -586,7 +586,7 @@ std::string ResolveFieldName(const protobuf::FieldDescriptor* field, } } } - return upbc::ResolveKeywordConflict(std::string(field_name)); + return upb::generator::ResolveKeywordConflict(std::string(field_name)); } } // namespace protos_generator diff --git a/protos_generator/gen_messages.cc b/protos_generator/gen_messages.cc index ca75ba70dd..251920abc6 100644 --- a/protos_generator/gen_messages.cc +++ b/protos_generator/gen_messages.cc @@ -42,8 +42,8 @@ #include "protos_generator/gen_utils.h" #include "protos_generator/names.h" #include "protos_generator/output.h" -#include "upbc/common.h" -#include "upbc/file_layout.h" +#include "upb_generator/common.h" +#include "upb_generator/file_layout.h" namespace protos_generator { @@ -176,7 +176,8 @@ void WriteModelPublicDeclaration( return *this; } )cc", - ClassName(descriptor), ::upbc::MessageInit(descriptor->full_name()), + ClassName(descriptor), + ::upb::generator::MessageInit(descriptor->full_name()), MessageName(descriptor), QualifiedClassName(descriptor)); WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessage, output); @@ -387,7 +388,7 @@ void WriteMessageImplementation( } )cc", ClassName(descriptor), MessageName(descriptor), - ::upbc::MessageInit(descriptor->full_name()), + ::upb::generator::MessageInit(descriptor->full_name()), QualifiedClassName(descriptor)); output("\n"); // Minitable @@ -395,7 +396,8 @@ void WriteMessageImplementation( R"cc( const upb_MiniTable* $0::minitable() { return &$1; } )cc", - ClassName(descriptor), ::upbc::MessageInit(descriptor->full_name())); + ClassName(descriptor), + ::upb::generator::MessageInit(descriptor->full_name())); output("\n"); } diff --git a/protos_generator/gen_repeated_fields.cc b/protos_generator/gen_repeated_fields.cc index d5b4bab650..57b13f2745 100644 --- a/protos_generator/gen_repeated_fields.cc +++ b/protos_generator/gen_repeated_fields.cc @@ -41,9 +41,9 @@ #include "protos_generator/gen_utils.h" #include "protos_generator/names.h" #include "protos_generator/output.h" -#include "upbc/common.h" -#include "upbc/file_layout.h" -#include "upbc/names.h" +#include "upb_generator/common.h" +#include "upb_generator/file_layout.h" +#include "upb_generator/names.h" namespace protos_generator { namespace protobuf = ::google::protobuf; @@ -204,13 +204,13 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message, return ::protos::RepeatedField<$1>::Proxy(arr, arena_); } )cc", - class_name, // $0 - MessageBaseType(field, /* maybe_const */ false), // $1 - resolved_field_name, // $2 - MessageName(message), // $3 - upbc_name, // $4 - upbc::kRepeatedFieldArrayGetterPostfix, // $5 - upbc::kRepeatedFieldMutableArrayGetterPostfix // $6 + class_name, // $0 + MessageBaseType(field, /* maybe_const */ false), // $1 + resolved_field_name, // $2 + MessageName(message), // $3 + upbc_name, // $4 + upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 + upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 ); } @@ -270,13 +270,13 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message, return ::protos::RepeatedField<$1>::Proxy(arr, arena_); } )cc", - class_name, // $0 - CppConstType(field), // $1 - resolved_field_name, // $2 - MessageName(message), // $3 - upbc_name, // $4 - upbc::kRepeatedFieldArrayGetterPostfix, // $5 - upbc::kRepeatedFieldMutableArrayGetterPostfix // $6 + class_name, // $0 + CppConstType(field), // $1 + resolved_field_name, // $2 + MessageName(message), // $3 + upbc_name, // $4 + upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 + upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 ); } @@ -334,13 +334,13 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message, return ::protos::RepeatedField<$1>::Proxy(arr, arena_); } )cc", - class_name, // $0 - CppConstType(field), // $1 - resolved_field_name, // $2 - MessageName(message), // $3 - upbc_name, // $4 - upbc::kRepeatedFieldArrayGetterPostfix, // $5 - upbc::kRepeatedFieldMutableArrayGetterPostfix // $6 + class_name, // $0 + CppConstType(field), // $1 + resolved_field_name, // $2 + MessageName(message), // $3 + upbc_name, // $4 + upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 + upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 ); } diff --git a/protos_generator/names.cc b/protos_generator/names.cc index eb3fbee431..e31edbc747 100644 --- a/protos_generator/names.cc +++ b/protos_generator/names.cc @@ -32,7 +32,7 @@ #include -#include "upbc/keywords.h" +#include "upb_generator/keywords.h" namespace protos_generator { @@ -113,7 +113,7 @@ std::string ClassName(const protobuf::Descriptor* descriptor) { } if (parent) res += ClassName(parent) + "_"; absl::StrAppend(&res, descriptor->name()); - return ::upbc::ResolveKeywordConflict(res); + return ::upb::generator::ResolveKeywordConflict(res); } std::string QualifiedClassName(const protobuf::Descriptor* descriptor) { diff --git a/protos_generator/output.h b/protos_generator/output.h index 53f0720dcc..0db6ad5fa5 100644 --- a/protos_generator/output.h +++ b/protos_generator/output.h @@ -129,7 +129,7 @@ class Output { void* void_buffer; int size; if (!stream_->Next(&void_buffer, &size)) { - fprintf(stderr, "upbc: Failed to write to to output\n"); + fprintf(stderr, "upb_generator: Failed to write to to output\n"); abort(); } output_buffer_ = static_cast(void_buffer); diff --git a/protos_generator/protoc-gen-upb-protos.cc b/protos_generator/protoc-gen-upb-protos.cc index 58c37121f8..53224b5dba 100644 --- a/protos_generator/protoc-gen-upb-protos.cc +++ b/protos_generator/protoc-gen-upb-protos.cc @@ -40,7 +40,7 @@ #include "protos_generator/gen_utils.h" #include "protos_generator/names.h" #include "protos_generator/output.h" -#include "upbc/file_layout.h" +#include "upb_generator/file_layout.h" namespace protos_generator { namespace { diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index d1c43cdbee..ce8635759c 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -212,7 +212,7 @@ filegroup( name = "plugin_proto_src", srcs = ["plugin.proto"], visibility = [ - "//upbc:__subpackages__", + "//upb_generator:__subpackages__", # For compatibility with workspaces that still use the old upb repo "@upb//:__subpackages__", ], diff --git a/upb/BUILD b/upb/BUILD index 9f1cf4bc8e..b67b7a6c4f 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -12,7 +12,7 @@ load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library") load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library") load("//bazel:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts") load( - "//upbc:bootstrap_compiler.bzl", + "//upb_generator:bootstrap_compiler.bzl", "bootstrap_cc_library", "bootstrap_upb_proto_library", ) diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 30c80c7e53..1cd66f7464 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -1,5 +1,4 @@ -/* This file was generated by upbc (the upb compiler) from the input - * file: +/* This file was generated by upb_generator from the input file: * * google/protobuf/descriptor.proto * diff --git a/upbc/BUILD b/upb_generator/BUILD similarity index 98% rename from upbc/BUILD rename to upb_generator/BUILD index d8166bbba6..04085079ee 100644 --- a/upbc/BUILD +++ b/upb_generator/BUILD @@ -20,7 +20,7 @@ load( "upb_proto_reflection_library", ) load( - "//upbc:bootstrap_compiler.bzl", + "//upb_generator:bootstrap_compiler.bzl", "bootstrap_cc_binary", "bootstrap_cc_library", "bootstrap_upb_proto_library", @@ -191,8 +191,8 @@ bootstrap_cc_library( ) cc_binary( - name = "libupbc.so", - srcs = ["upbc_so.c"], + name = "libupb_generator.so", + srcs = ["upb_generator_so.c"], copts = UPB_DEFAULT_COPTS + ["-DUPB_BUILD_API"], linkshared = 1, linkstatic = 1, diff --git a/upbc/bootstrap_compiler.bzl b/upb_generator/bootstrap_compiler.bzl similarity index 96% rename from upbc/bootstrap_compiler.bzl rename to upb_generator/bootstrap_compiler.bzl index fcc1102c7b..b0ccbd799a 100644 --- a/upbc/bootstrap_compiler.bzl +++ b/upb_generator/bootstrap_compiler.bzl @@ -1,17 +1,17 @@ """Macros that implement bootstrapping for the upb code generator.""" -load( - "//bazel:upb_proto_library.bzl", - "upb_proto_library", -) load( "//upb/cmake:build_defs.bzl", "staleness_test", ) +load( + "//bazel:upb_proto_library.bzl", + "upb_proto_library", +) _stages = ["_stage0", "_stage1", ""] _protoc = "//:protoc" -_upbc_base = "//upbc:protoc-gen-" +_upbc_base = "//upb_generator:protoc-gen-" # begin:google_only # _is_google3 = True @@ -28,7 +28,7 @@ def _upbc(generator, stage): def bootstrap_cc_library(name, visibility, deps, bootstrap_deps, **kwargs): for stage in _stages: - stage_visibility = visibility if stage == "" else ["//upbc:__pkg__"] + stage_visibility = visibility if stage == "" else ["//upb_generator:__pkg__"] native.cc_library( name = name + stage, deps = deps + [dep + stage for dep in bootstrap_deps], @@ -93,7 +93,7 @@ def _generate_stage1_proto(name, base_dir, src_files, src_rules, generator, kwar "=$(location " + _upbc(generator, 0) + ") " + _extra_proto_path + "--" + generator + "_out=$(RULEDIR)/" + base_dir + "stage1 " + " ".join(src_files), - visibility = ["//upbc:__pkg__"], + visibility = ["//upb_generator:__pkg__"], tools = [ _protoc, _upbc(generator, 0), @@ -140,7 +140,7 @@ def bootstrap_upb_proto_library( srcs = _generated_srcs_for_suffix(base_dir + "stage0", oss_src_files, ".upb.c"), hdrs = _generated_srcs_for_suffix(base_dir + "stage0", oss_src_files, ".upb.h"), includes = [base_dir + "stage0"], - visibility = ["//upbc:__pkg__"], + visibility = ["//upb_generator:__pkg__"], # This macro signals to the runtime that it must use OSS APIs for descriptor.proto/plugin.proto. defines = ["UPB_BOOTSTRAP_STAGE0"], deps = [ @@ -162,7 +162,7 @@ def bootstrap_upb_proto_library( srcs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb_minitable.c"), hdrs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb_minitable.h"), includes = [base_dir + "stage1"], - visibility = ["//upbc:__pkg__"], + visibility = ["//upb_generator:__pkg__"], deps = [ "//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", ] + [dep + "_stage1" for dep in deps], @@ -172,7 +172,7 @@ def bootstrap_upb_proto_library( name = name + "_stage1", hdrs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb.h"), includes = [base_dir + "stage1"], - visibility = ["//upbc:__pkg__"], + visibility = ["//upb_generator:__pkg__"], deps = [ "//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", ":" + name + "_minitable_stage1", diff --git a/upbc/code_generator_request.c b/upb_generator/code_generator_request.c similarity index 88% rename from upbc/code_generator_request.c rename to upb_generator/code_generator_request.c index 4ab5fcc0a0..1c9bcd3ae3 100644 --- a/upbc/code_generator_request.c +++ b/upb_generator/code_generator_request.c @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/code_generator_request.h" +#include "upb_generator/code_generator_request.h" #include @@ -48,7 +48,7 @@ typedef struct { upb_Status* status; upb_DefPool* symtab; - upbc_CodeGeneratorRequest* out; + upb_CodeGeneratorRequest* out; jmp_buf jmp; } upbc_State; @@ -68,7 +68,7 @@ static void upbc_State_Init(upbc_State* s) { s->symtab = upb_DefPool_New(); if (!s->symtab) upbc_Error(s, __func__, "could not allocate def pool"); - s->out = upbc_CodeGeneratorRequest_new(s->arena); + s->out = upb_CodeGeneratorRequest_new(s->arena); if (!s->out) upbc_Error(s, __func__, "could not allocate request"); } @@ -83,11 +83,11 @@ static upb_StringView upbc_State_StrDup(upbc_State* s, const char* str) { static void upbc_State_AddMiniDescriptor(upbc_State* s, const char* name, upb_StringView encoding) { const upb_StringView key = upb_StringView_FromString(name); - upbc_CodeGeneratorRequest_UpbInfo* info = - upbc_CodeGeneratorRequest_UpbInfo_new(s->arena); + upb_CodeGeneratorRequest_UpbInfo* info = + upb_CodeGeneratorRequest_UpbInfo_new(s->arena); if (!info) upbc_Error(s, __func__, "Out of memory"); - upbc_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, encoding); - bool ok = upbc_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena); + upb_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, encoding); + bool ok = upb_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena); if (!ok) upbc_Error(s, __func__, "could not set mini descriptor in map"); } @@ -144,7 +144,7 @@ static void upbc_Scrape_File(upbc_State* s, const upb_FileDef* f) { static void upbc_Scrape_Files(upbc_State* s) { const google_protobuf_compiler_CodeGeneratorRequest* request = - upbc_CodeGeneratorRequest_request(s->out); + upb_CodeGeneratorRequest_request(s->out); size_t len = 0; const google_protobuf_FileDescriptorProto* const* files = @@ -184,7 +184,7 @@ static void upbc_Scrape_NestedMessages(upbc_State* s, const upb_MessageDef* m) { } static void upbc_Scrape_MessageSubs(upbc_State* s, - upbc_CodeGeneratorRequest_UpbInfo* info, + upb_CodeGeneratorRequest_UpbInfo* info, const upb_MessageDef* m) { const upb_MiniTableField** fields = malloc(upb_MessageDef_FieldCount(m) * sizeof(*fields)); @@ -200,7 +200,7 @@ static void upbc_Scrape_MessageSubs(upbc_State* s, const upb_MessageDef* sub = upb_FieldDef_MessageSubDef(f); if (!sub) upbc_Error(s, __func__, "Missing sub"); upb_StringView name = upbc_State_StrDup(s, upb_MessageDef_FullName(sub)); - upbc_CodeGeneratorRequest_UpbInfo_add_sub_message(info, name, s->arena); + upb_CodeGeneratorRequest_UpbInfo_add_sub_message(info, name, s->arena); } for (uint32_t i = 0; i < enum_count; i++) { @@ -210,7 +210,7 @@ static void upbc_Scrape_MessageSubs(upbc_State* s, const upb_EnumDef* sub = upb_FieldDef_EnumSubDef(f); if (!sub) upbc_Error(s, __func__, "Missing sub (2)"); upb_StringView name = upbc_State_StrDup(s, upb_EnumDef_FullName(sub)); - upbc_CodeGeneratorRequest_UpbInfo_add_sub_enum(info, name, s->arena); + upb_CodeGeneratorRequest_UpbInfo_add_sub_enum(info, name, s->arena); } free(fields); @@ -221,15 +221,15 @@ static void upbc_Scrape_Message(upbc_State* s, const upb_MessageDef* m) { bool ok = upb_MessageDef_MiniDescriptorEncode(m, s->arena, &desc); if (!ok) upbc_Error(s, __func__, "could not encode message"); - upbc_CodeGeneratorRequest_UpbInfo* info = - upbc_CodeGeneratorRequest_UpbInfo_new(s->arena); + upb_CodeGeneratorRequest_UpbInfo* info = + upb_CodeGeneratorRequest_UpbInfo_new(s->arena); if (!info) upbc_Error(s, __func__, "Out of memory"); - upbc_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, desc); + upb_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, desc); upbc_Scrape_MessageSubs(s, info, m); const upb_StringView key = upbc_State_StrDup(s, upb_MessageDef_FullName(m)); - ok = upbc_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena); + ok = upb_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena); if (!ok) upbc_Error(s, __func__, "could not set mini descriptor in map"); upbc_Scrape_NestedEnums(s, m); @@ -237,18 +237,18 @@ static void upbc_Scrape_Message(upbc_State* s, const upb_MessageDef* m) { upbc_Scrape_NestedMessages(s, m); } -static upbc_CodeGeneratorRequest* upbc_State_MakeCodeGeneratorRequest( +static upb_CodeGeneratorRequest* upbc_State_MakeCodeGeneratorRequest( upbc_State* const s, google_protobuf_compiler_CodeGeneratorRequest* const request) { if (UPB_SETJMP(s->jmp)) return NULL; upbc_State_Init(s); - upbc_CodeGeneratorRequest_set_request(s->out, request); + upb_CodeGeneratorRequest_set_request(s->out, request); upbc_Scrape_Files(s); upbc_State_Fini(s); return s->out; } -upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest( +upb_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest( google_protobuf_compiler_CodeGeneratorRequest* request, upb_Arena* arena, upb_Status* status) { upbc_State s = { diff --git a/upbc/code_generator_request.h b/upb_generator/code_generator_request.h similarity index 88% rename from upbc/code_generator_request.h rename to upb_generator/code_generator_request.h index 3218c08bed..ddd9131a51 100644 --- a/upbc/code_generator_request.h +++ b/upb_generator/code_generator_request.h @@ -28,12 +28,12 @@ // (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 UPBC_CODE_GENERATOR_REQUEST_H_ -#define UPBC_CODE_GENERATOR_REQUEST_H_ +#ifndef UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ +#define UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ #include "upb/mem/arena.h" #include "upb/reflection/def.h" -#include "upbc/code_generator_request.upb.h" +#include "upb_generator/code_generator_request.upb.h" // Must be last. #include "upb/port/def.inc" @@ -42,7 +42,7 @@ extern "C" { #endif -upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest( +upb_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest( struct google_protobuf_compiler_CodeGeneratorRequest* request, upb_Arena* a, upb_Status* s); @@ -52,4 +52,4 @@ upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest( #include "upb/port/undef.inc" -#endif /* UPBC_CODE_GENERATOR_REQUEST_H_ */ +#endif /* UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ */ diff --git a/upbc/code_generator_request.proto b/upb_generator/code_generator_request.proto similarity index 99% rename from upbc/code_generator_request.proto rename to upb_generator/code_generator_request.proto index 600faee272..63501cf4da 100644 --- a/upbc/code_generator_request.proto +++ b/upb_generator/code_generator_request.proto @@ -30,7 +30,7 @@ syntax = "proto2"; -package upbc; +package upb; import "google/protobuf/compiler/plugin.proto"; diff --git a/upbc/common.cc b/upb_generator/common.cc similarity index 96% rename from upbc/common.cc rename to upb_generator/common.cc index b5bad200b4..c81bcb0e18 100644 --- a/upbc/common.cc +++ b/upb_generator/common.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/common.h" +#include "upb_generator/common.h" #include #include @@ -48,7 +48,8 @@ // Must be last #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { std::string StripExtension(absl::string_view fname) { size_t lastdot = fname.find_last_of('.'); @@ -68,8 +69,7 @@ std::string ToPreproc(absl::string_view str) { void EmitFileWarning(absl::string_view name, Output& output) { output( - "/* This file was generated by upbc (the upb compiler) from the input\n" - " * file:\n" + "/* This file was generated by upb_generator from the input file:\n" " *\n" " * $0\n" " *\n" @@ -185,4 +185,5 @@ std::string GetFieldRep(const upb_MiniTableField* field32, UPB_UNREACHABLE(); } -} // namespace upbc +} // namespace generator +} // namespace upb diff --git a/upbc/common.h b/upb_generator/common.h similarity index 95% rename from upbc/common.h rename to upb_generator/common.h index e6077146fe..5f4bd4ed8c 100644 --- a/upbc/common.h +++ b/upb_generator/common.h @@ -28,8 +28,8 @@ // (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 UPBC_COMMON_H -#define UPBC_COMMON_H +#ifndef UPB_GENERATOR_COMMON_H +#define UPB_GENERATOR_COMMON_H #include @@ -37,7 +37,8 @@ #include "absl/strings/substitute.h" #include "upb/reflection/def.hpp" -namespace upbc { +namespace upb { +namespace generator { class Output { public: @@ -97,6 +98,7 @@ std::string GetModeInit(const upb_MiniTableField* field32, std::string GetFieldRep(const upb_MiniTableField* field32, const upb_MiniTableField* field64); -} // namespace upbc +} // namespace generator +} // namespace upb -#endif // UPBC_COMMON_H +#endif // UPB_GENERATOR_COMMON_H diff --git a/upbc/file_layout.cc b/upb_generator/file_layout.cc similarity index 97% rename from upbc/file_layout.cc rename to upb_generator/file_layout.cc index fab61202d0..9fa03d2635 100644 --- a/upbc/file_layout.cc +++ b/upb_generator/file_layout.cc @@ -28,15 +28,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/file_layout.h" +#include "upb_generator/file_layout.h" #include #include #include "upb/mini_table/internal/extension.h" -#include "upbc/common.h" +#include "upb_generator/common.h" -namespace upbc { +namespace upb { +namespace generator { const char* kEnumsInit = "enums_layout"; const char* kExtensionsInit = "extensions_layout"; @@ -141,4 +142,5 @@ std::vector FieldNumberOrder(upb::MessageDefPtr message) { return fields; } -} // namespace upbc +} // namespace generator +} // namespace upb diff --git a/upbc/file_layout.h b/upb_generator/file_layout.h similarity index 94% rename from upbc/file_layout.h rename to upb_generator/file_layout.h index 9df43aaaea..a5b9416a7d 100644 --- a/upbc/file_layout.h +++ b/upb_generator/file_layout.h @@ -28,14 +28,14 @@ // (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 UPBC_FILE_LAYOUT_H -#define UPBC_FILE_LAYOUT_H +#ifndef UPB_GENERATOR_FILE_LAYOUT_H +#define UPB_GENERATOR_FILE_LAYOUT_H #include // begin:google_only // #ifndef UPB_BOOTSTRAP_STAGE0 -// #include "net/proto2/proto/descriptor.upb.h" +// #include "google/protobuf/descriptor.upb.h" // #else // #include "google/protobuf/descriptor.upb.h" // #endif @@ -54,7 +54,8 @@ // Must be last #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { std::vector SortedEnums(upb::FileDefPtr file); @@ -122,8 +123,9 @@ class DefPoolPair { upb::DefPool pool64_; }; -} // namespace upbc +} // namespace generator +} // namespace upb #include "upb/port/undef.inc" -#endif // UPBC_FILE_LAYOUT_H +#endif // UPB_GENERATOR_FILE_LAYOUT_H diff --git a/upbc/get_used_fields.c b/upb_generator/get_used_fields.c similarity index 99% rename from upbc/get_used_fields.c rename to upb_generator/get_used_fields.c index 796e50133c..55a4ff4b00 100644 --- a/upbc/get_used_fields.c +++ b/upb_generator/get_used_fields.c @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/get_used_fields.h" +#include "upb_generator/get_used_fields.h" #include "google/protobuf/descriptor.upb.h" #include "google/protobuf/compiler/plugin.upb.h" diff --git a/upbc/get_used_fields.h b/upb_generator/get_used_fields.h similarity index 92% rename from upbc/get_used_fields.h rename to upb_generator/get_used_fields.h index ccf3208e85..428c654892 100644 --- a/upbc/get_used_fields.h +++ b/upb_generator/get_used_fields.h @@ -28,8 +28,8 @@ // (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 UPBC_GET_USED_FIELDS -#define UPBC_GET_USED_FIELDS +#ifndef UPB_GENERATOR_GET_USED_FIELDS +#define UPB_GENERATOR_GET_USED_FIELDS #include "upb/base/status.h" #include "upb/base/string_view.h" @@ -43,7 +43,7 @@ extern "C" { #endif // Consume |buf|, deserialize it to a Code_Generator_Request proto, then -// upbc_Code_Generator_Request, and return it as a JSON-encoded string. +// upb_Code_Generator_Request, and return it as a JSON-encoded string. UPB_API upb_StringView upbdev_GetUsedFields( const char* request, size_t request_size, const char* payload, size_t payload_size, const char* message_name, upb_Arena* arena); @@ -54,4 +54,4 @@ UPB_API upb_StringView upbdev_GetUsedFields( #include "upb/port/undef.inc" -#endif // UPBC_GET_USED_FIELDS +#endif // UPB_GENERATOR_GET_USED_FIELDS diff --git a/upbc/keywords.cc b/upb_generator/keywords.cc similarity index 96% rename from upbc/keywords.cc rename to upb_generator/keywords.cc index 3f51705739..eb6af3a313 100644 --- a/upbc/keywords.cc +++ b/upb_generator/keywords.cc @@ -28,12 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/keywords.h" +#include "upb_generator/keywords.h" #include #include -namespace upbc { +namespace upb { +namespace generator { static const char* const kKeywordList[] = { // @@ -149,4 +150,5 @@ std::string ResolveKeywordConflict(const std::string& name) { return name; } -} // namespace upbc +} // namespace generator +} // namespace upb diff --git a/upbc/keywords.h b/upb_generator/keywords.h similarity index 95% rename from upbc/keywords.h rename to upb_generator/keywords.h index 6638f99f38..51564a21f3 100644 --- a/upbc/keywords.h +++ b/upb_generator/keywords.h @@ -33,11 +33,13 @@ #include -namespace upbc { +namespace upb { +namespace generator { // Resolves proto field name conflict with C++ reserved keywords. std::string ResolveKeywordConflict(const std::string& name); -} // namespace upbc +} // namespace generator +} // namespace upb #endif // UPB_PROTOS_GENERATOR_KEYWORDS_H diff --git a/upbc/names.cc b/upb_generator/names.cc similarity index 97% rename from upbc/names.cc rename to upb_generator/names.cc index 63521b8f12..847c8f1b18 100644 --- a/upbc/names.cc +++ b/upb_generator/names.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/names.h" +#include "upb_generator/names.h" #include @@ -37,7 +37,8 @@ #include "google/protobuf/descriptor.h" #include "upb/reflection/def.hpp" -namespace upbc { +namespace upb { +namespace generator { namespace protobuf = ::google::protobuf; @@ -129,4 +130,5 @@ std::string ResolveFieldName(upb::FieldDefPtr field, return std::string(field_name); } -} // namespace upbc +} // namespace generator +} // namespace upb diff --git a/upbc/names.h b/upb_generator/names.h similarity index 97% rename from upbc/names.h rename to upb_generator/names.h index 87b0a15541..7eef159451 100644 --- a/upbc/names.h +++ b/upb_generator/names.h @@ -39,7 +39,8 @@ #include "google/protobuf/descriptor.h" #include "upb/reflection/def.hpp" -namespace upbc { +namespace upb { +namespace generator { using NameToFieldDescriptorMap = absl::flat_hash_map; @@ -68,6 +69,7 @@ ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldArrayGetterPostfix; ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldMutableArrayGetterPostfix; -} // namespace upbc +} // namespace generator +} // namespace upb #endif // UPB_PROTOS_GENERATOR_NAMES_H diff --git a/upbc/plugin.h b/upb_generator/plugin.h similarity index 96% rename from upbc/plugin.h rename to upb_generator/plugin.h index 465bda0183..1500d4097c 100644 --- a/upbc/plugin.h +++ b/upb_generator/plugin.h @@ -28,8 +28,8 @@ // (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_UPBC_PLUGIN_H_ -#define UPB_UPBC_PLUGIN_H_ +#ifndef UPB_UPB_GENERATOR_PLUGIN_H_ +#define UPB_UPB_GENERATOR_PLUGIN_H_ #include @@ -42,8 +42,8 @@ // begin:google_only // #ifndef UPB_BOOTSTRAP_STAGE0 -// #include "net/proto2/proto/descriptor.upb.h" -// #include "third_party/protobuf/compiler/plugin.upb.h" +// #include "google/protobuf/descriptor.upb.h" +// #include "google/protobuf/compiler/plugin.upb.h" // #else // #include "google/protobuf/compiler/plugin.upb.h" // #include "google/protobuf/descriptor.upb.h" @@ -64,7 +64,8 @@ // Must be last. #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { inline std::vector> ParseGeneratorParameter( const absl::string_view text) { @@ -205,8 +206,9 @@ class Plugin { } }; -} // namespace upbc +} // namespace generator +} // namespace upb #include "upb/port/undef.inc" -#endif // UPB_UPBC_PLUGIN_H_ +#endif // UPB_UPB_GENERATOR_PLUGIN_H_ diff --git a/upbc/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc similarity index 98% rename from upbc/protoc-gen-upb.cc rename to upb_generator/protoc-gen-upb.cc index 0fa716ad72..60fa5be3cd 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -53,15 +53,16 @@ #include "upb/base/string_view.h" #include "upb/reflection/def.hpp" #include "upb/wire/types.h" -#include "upbc/common.h" -#include "upbc/file_layout.h" -#include "upbc/names.h" -#include "upbc/plugin.h" +#include "upb_generator/common.h" +#include "upb_generator/file_layout.h" +#include "upb_generator/names.h" +#include "upb_generator/plugin.h" // Must be last. #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { namespace { struct Options { @@ -278,7 +279,8 @@ void DumpEnumValues(upb::EnumDefPtr desc, Output& output) { } std::string GetFieldRep(const DefPoolPair& pools, upb::FieldDefPtr field) { - return upbc::GetFieldRep(pools.GetField32(field), pools.GetField64(field)); + return upb::generator::GetFieldRep(pools.GetField32(field), + pools.GetField64(field)); } void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, @@ -993,7 +995,7 @@ std::string FieldInitializer(upb::FieldDefPtr field, "*upb_MiniTable_FindFieldByNumber($0, $1)", MessageMiniTableRef(field.containing_type(), options), field.number()); } else { - return upbc::FieldInitializer(field, field64, field32); + return upb::generator::FieldInitializer(field, field64, field32); } } @@ -1131,20 +1133,21 @@ absl::string_view ToStringView(upb_StringView str) { } // namespace -} // namespace upbc +} // namespace generator +} // namespace upb int main(int argc, char** argv) { - upbc::DefPoolPair pools; - upbc::Plugin plugin; - upbc::Options options; + upb::generator::DefPoolPair pools; + upb::generator::Plugin plugin; + upb::generator::Options options; if (!ParseOptions(&plugin, &options)) return 0; plugin.GenerateFilesRaw([&](const UPB_DESC(FileDescriptorProto) * file_proto, bool generate) { upb::Status status; upb::FileDefPtr file = pools.AddFile(file_proto, &status); if (!file) { - absl::string_view name = - upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); + absl::string_view name = upb::generator::ToStringView( + UPB_DESC(FileDescriptorProto_name)(file_proto)); ABSL_LOG(FATAL) << "Couldn't add file " << name << " to DefPool: " << status.error_message(); } diff --git a/upbc/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc similarity index 96% rename from upbc/protoc-gen-upb_minitable.cc rename to upb_generator/protoc-gen-upb_minitable.cc index 745dc8441a..69be262240 100644 --- a/upbc/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -49,15 +49,16 @@ #include "upb/base/string_view.h" #include "upb/reflection/def.hpp" #include "upb/wire/types.h" -#include "upbc/common.h" -#include "upbc/file_layout.h" -#include "upbc/names.h" -#include "upbc/plugin.h" +#include "upb_generator/common.h" +#include "upb_generator/file_layout.h" +#include "upb_generator/names.h" +#include "upb_generator/plugin.h" // Must be last. #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { namespace { // Returns fields in order of "hotness", eg. how frequently they appear in @@ -406,15 +407,15 @@ std::string ArchDependentSize(int64_t size32, int64_t size64) { } std::string FieldInitializer(const DefPoolPair& pools, upb::FieldDefPtr field) { - return upbc::FieldInitializer(field, pools.GetField64(field), - pools.GetField32(field)); + return upb::generator::FieldInitializer(field, pools.GetField64(field), + pools.GetField32(field)); } // Writes a single field into a .upb.c source file. void WriteMessageField(upb::FieldDefPtr field, const upb_MiniTableField* field64, const upb_MiniTableField* field32, Output& output) { - output(" $0,\n", upbc::FieldInitializer(field, field64, field32)); + output(" $0,\n", upb::generator::FieldInitializer(field, field64, field32)); } std::string GetSub(upb::FieldDefPtr field) { @@ -687,23 +688,24 @@ absl::string_view ToStringView(upb_StringView str) { } // namespace -} // namespace upbc +} // namespace generator +} // namespace upb int main(int argc, char** argv) { - upbc::DefPoolPair pools; - upbc::Plugin plugin; - if (!upbc::ParseOptions(&plugin)) return 0; + upb::generator::DefPoolPair pools; + upb::generator::Plugin plugin; + if (!upb::generator::ParseOptions(&plugin)) return 0; plugin.GenerateFilesRaw([&](const UPB_DESC(FileDescriptorProto) * file_proto, bool generate) { upb::Status status; upb::FileDefPtr file = pools.AddFile(file_proto, &status); if (!file) { - absl::string_view name = - upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); + absl::string_view name = upb::generator::ToStringView( + UPB_DESC(FileDescriptorProto_name)(file_proto)); ABSL_LOG(FATAL) << "Couldn't add file " << name << " to DefPool: " << status.error_message(); } - if (generate) upbc::GenerateFile(pools, file, &plugin); + if (generate) upb::generator::GenerateFile(pools, file, &plugin); }); return 0; } diff --git a/upbc/protoc-gen-upbdefs.cc b/upb_generator/protoc-gen-upbdefs.cc similarity index 94% rename from upbc/protoc-gen-upbdefs.cc rename to upb_generator/protoc-gen-upbdefs.cc index d2870b03d2..69682c4e78 100644 --- a/upbc/protoc-gen-upbdefs.cc +++ b/upb_generator/protoc-gen-upbdefs.cc @@ -33,11 +33,12 @@ #include "google/protobuf/descriptor.upb.h" #include "upb/reflection/def.hpp" #include "upb/util/def_to_proto.h" -#include "upbc/common.h" -#include "upbc/file_layout.h" -#include "upbc/plugin.h" +#include "upb_generator/common.h" +#include "upb_generator/file_layout.h" +#include "upb_generator/plugin.h" -namespace upbc { +namespace upb { +namespace generator { namespace { std::string DefInitSymbol(upb::FileDefPtr file) { @@ -160,16 +161,18 @@ void GenerateFile(upb::FileDefPtr file, Plugin* plugin) { } } // namespace -} // namespace upbc +} // namespace generator +} // namespace upb int main(int argc, char** argv) { - upbc::Plugin plugin; + upb::generator::Plugin plugin; if (!plugin.parameter().empty()) { plugin.SetError( absl::StrCat("Expected no parameters, got: ", plugin.parameter())); return 0; } - plugin.GenerateFiles( - [&](upb::FileDefPtr file) { upbc::GenerateFile(file, &plugin); }); + plugin.GenerateFiles([&](upb::FileDefPtr file) { + upb::generator::GenerateFile(file, &plugin); + }); return 0; } diff --git a/upbc/protoc-gen-upbdev.cc b/upb_generator/protoc-gen-upbdev.cc similarity index 92% rename from upbc/protoc-gen-upbdev.cc rename to upb_generator/protoc-gen-upbdev.cc index 3093169630..d2461dd5d8 100644 --- a/upbc/protoc-gen-upbdev.cc +++ b/upb_generator/protoc-gen-upbdev.cc @@ -32,8 +32,8 @@ #include #include "google/protobuf/compiler/plugin.upb.h" -#include "upbc/subprocess.h" -#include "upbc/upbdev.h" +#include "upb_generator/subprocess.h" +#include "upb_generator/upbdev.h" static constexpr char kDefaultPlugin[] = "protoc_dart_plugin"; @@ -57,7 +57,7 @@ int main() { plugin = std::string(param.data, param.size); } - // Wrap the request inside a upbc_CodeGeneratorRequest and JSON-encode it. + // Wrap the request inside a upb_CodeGeneratorRequest and JSON-encode it. const upb_StringView sv = upbdev_ProcessInput(input.data(), input.size(), a, &status); if (!upb_Status_IsOk(&status)) { @@ -66,8 +66,8 @@ int main() { } // Launch the subprocess. - upbc::Subprocess subprocess; - subprocess.Start(plugin, upbc::Subprocess::SEARCH_PATH); + upb::generator::Subprocess subprocess; + subprocess.Start(plugin, upb::generator::Subprocess::SEARCH_PATH); // Exchange JSON strings with the subprocess. const std::string json_request = std::string(sv.data, sv.size); diff --git a/upbc/stage0/google/protobuf/compiler/plugin.upb.c b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.c similarity index 100% rename from upbc/stage0/google/protobuf/compiler/plugin.upb.c rename to upb_generator/stage0/google/protobuf/compiler/plugin.upb.c diff --git a/upbc/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h similarity index 99% rename from upbc/stage0/google/protobuf/compiler/plugin.upb.h rename to upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index 4227e51fa7..9361f291d1 100644 --- a/upbc/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -1,5 +1,4 @@ -/* This file was generated by upbc (the upb compiler) from the input - * file: +/* This file was generated by upb_generator from the input file: * * google/protobuf/compiler/plugin.proto * diff --git a/upbc/subprocess.cc b/upb_generator/subprocess.cc similarity index 99% rename from upbc/subprocess.cc rename to upb_generator/subprocess.cc index e0c2604230..0f6f8b4a62 100644 --- a/upbc/subprocess.cc +++ b/upb_generator/subprocess.cc @@ -31,7 +31,7 @@ // Shamelessly copied from the protobuf compiler's subprocess.cc // except this version passes strings instead of Messages. -#include "upbc/subprocess.h" +#include "upb_generator/subprocess.h" #include #include @@ -50,7 +50,8 @@ // Must be last. #include "upb/port/def.inc" -namespace upbc { +namespace upb { +namespace generator { namespace { char* portable_strdup(const char* s) { @@ -462,4 +463,5 @@ bool Subprocess::Communicate(const std::string& input_data, #endif // !_WIN32 -} // namespace upbc +} // namespace generator +} // namespace upb diff --git a/upbc/subprocess.h b/upb_generator/subprocess.h similarity index 94% rename from upbc/subprocess.h rename to upb_generator/subprocess.h index b30b5bfb59..5465ccdd80 100644 --- a/upbc/subprocess.h +++ b/upb_generator/subprocess.h @@ -31,8 +31,8 @@ // Shamelessly copied from the protobuf compiler's subprocess.h // except this version passes strings instead of Messages. -#ifndef THIRD_PARTY_UPB_UPBC_H_ -#define THIRD_PARTY_UPB_UPBC_H_ +#ifndef THIRD_PARTY_UPB_UPB_GENERATOR_H_ +#define THIRD_PARTY_UPB_UPB_GENERATOR_H_ #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -45,7 +45,8 @@ #endif // !_WIN32 #include -namespace upbc { +namespace upb { +namespace generator { // Utility class for launching sub-processes. class Subprocess { @@ -97,6 +98,7 @@ class Subprocess { #endif // !_WIN32 }; -} // namespace upbc +} // namespace generator +} // namespace upb -#endif // THIRD_PARTY_UPB_UPBC_H_ +#endif // THIRD_PARTY_UPB_UPB_GENERATOR_H_ diff --git a/upbc/upbc_so.c b/upb_generator/upb_generator_so.c similarity index 95% rename from upbc/upbc_so.c rename to upb_generator/upb_generator_so.c index 1cfc04b2ab..30b800f9ed 100644 --- a/upbc/upbc_so.c +++ b/upb_generator/upb_generator_so.c @@ -30,5 +30,5 @@ // These headers form a spanning tree for the upbc defs needed by FFI layers. -#include "upbc/get_used_fields.h" -#include "upbc/upbdev.h" +#include "upb_generator/get_used_fields.h" +#include "upb_generator/upbdev.h" diff --git a/upbc/upbdev.c b/upb_generator/upbdev.c similarity index 92% rename from upbc/upbdev.c rename to upb_generator/upbdev.c index ffccd07104..837b459702 100644 --- a/upbc/upbdev.c +++ b/upb_generator/upbdev.c @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "upbc/upbdev.h" +#include "upb_generator/upbdev.h" #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -45,9 +45,9 @@ #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/mem/arena.h" -#include "upbc/code_generator_request.h" -#include "upbc/code_generator_request.upb.h" -#include "upbc/code_generator_request.upbdefs.h" +#include "upb_generator/code_generator_request.h" +#include "upb_generator/code_generator_request.upb.h" +#include "upb_generator/code_generator_request.upbdefs.h" static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode( const char* data, size_t size, upb_Arena* arena, upb_Status* status) { @@ -65,12 +65,12 @@ static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode( return response; } -static upb_StringView upbc_JsonEncode(const upbc_CodeGeneratorRequest* request, +static upb_StringView upbc_JsonEncode(const upb_CodeGeneratorRequest* request, upb_Arena* arena, upb_Status* status) { upb_StringView out = {.data = NULL, .size = 0}; upb_DefPool* s = upb_DefPool_New(); - const upb_MessageDef* m = upbc_CodeGeneratorRequest_getmsgdef(s); + const upb_MessageDef* m = upb_CodeGeneratorRequest_getmsgdef(s); const int options = upb_JsonEncode_FormatEnumsAsIntegers; out.size = upb_JsonEncode(request, m, s, options, NULL, 0, status); @@ -95,7 +95,7 @@ upb_StringView upbdev_ProcessInput(const char* buf, size_t size, google_protobuf_compiler_CodeGeneratorRequest* inner_request = google_protobuf_compiler_CodeGeneratorRequest_parse(buf, size, arena); - const upbc_CodeGeneratorRequest* outer_request = + const upb_CodeGeneratorRequest* outer_request = upbc_MakeCodeGeneratorRequest(inner_request, arena, status); if (!upb_Status_IsOk(status)) return out; diff --git a/upbc/upbdev.h b/upb_generator/upbdev.h similarity index 94% rename from upbc/upbdev.h rename to upb_generator/upbdev.h index 047a1be3e8..1814b52452 100644 --- a/upbc/upbdev.h +++ b/upb_generator/upbdev.h @@ -28,8 +28,8 @@ // (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 UPBC_UPBDEV_H_ -#define UPBC_UPBDEV_H_ +#ifndef UPB_GENERATOR_UPBDEV_H_ +#define UPB_GENERATOR_UPBDEV_H_ #include "upb/base/status.h" #include "upb/base/string_view.h" @@ -43,7 +43,7 @@ extern "C" { #endif // Consume |buf|, deserialize it to a Code_Generator_Request proto, construct a -// upbc_Code_Generator_Request, and return it as a JSON-encoded string. +// upb_Code_Generator_Request, and return it as a JSON-encoded string. UPB_API upb_StringView upbdev_ProcessInput(const char* buf, size_t size, upb_Arena* arena, upb_Status* status); @@ -68,4 +68,4 @@ UPB_API void upbdev_Status_Clear(upb_Status* status); #include "upb/port/undef.inc" -#endif // UPBC_UPBDEV_H_ +#endif // UPB_GENERATOR_UPBDEV_H_