From cf05c9f84f6bf9229cb3dbd8e30f4b1616a316c5 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 18 Feb 2022 00:39:23 +0000 Subject: [PATCH 01/27] Change sysroot flags --- toolchain/cc_toolchain_config.bzl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 27fe274e6e..e85e03e3da 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -102,13 +102,18 @@ def _impl(ctx): ], ) + if 'osx' in ctx.attr.target_full_name: + sysroot_action_set = all_link_actions + else: + sysroot_action_set = all_link_actions + all_compile_actions + sysroot_flags = feature( name = "sysroot_flags", #Only enable this if a sysroot was specified enabled = (ctx.attr.sysroot != ""), flag_sets = [ flag_set( - actions = all_link_actions + all_compile_actions, + actions = sysroot_action_set, flag_groups = [ flag_group( flags = [ From 20c5b6fd140a1351a489c7dc84d4b28e3632ba9e Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Thu, 17 Feb 2022 18:01:44 -0800 Subject: [PATCH 02/27] Update changelog --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 6491e2bf23..13d5cbb851 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -87,6 +87,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Remove GetPointer() and explicit nullptr defaults. * add proto_h flag for speeding up large builds * Add missing overload for reference wrapped fields. + * Add MergedDescriptorDatabase::FindAllFileNames() 2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From 951582e8935b3af68e9a72e466f32558d646595c Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Fri, 18 Feb 2022 14:07:43 -0800 Subject: [PATCH 03/27] Update changelog --- CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 13d5cbb851..d443caf3df 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -49,6 +49,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Adds client_streaming and server_streaming fields to MethodDescriptor. * Add "ensure_ascii" parameter to json_format.MessageToJson. This allows smaller JSON serializations with UTF-8 or other non-ASCII encodings. + * Added experimental support for directly assigning numpy scalars and array. Compiler * Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*) @@ -88,6 +89,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * add proto_h flag for speeding up large builds * Add missing overload for reference wrapped fields. * Add MergedDescriptorDatabase::FindAllFileNames() + * RepeatedField now defines an iterator type instead of using a pointer. 2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From db566928838d0a56e9b1170938e9dda59415e7ea Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Tue, 22 Feb 2022 10:37:27 -0800 Subject: [PATCH 04/27] Revert "objective-c: Add `objc_class_prefix` generation option." This reverts commit b5ab0b7a18b7336c60130f4ddb2d97c51792f896. --- objectivec/README.md | 10 ++-------- .../compiler/objectivec/objectivec_generator.cc | 14 ++------------ .../compiler/objectivec/objectivec_helpers.cc | 17 ++--------------- .../compiler/objectivec/objectivec_helpers.h | 4 ---- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/objectivec/README.md b/objectivec/README.md index b0278f2aee..9aedb219f5 100644 --- a/objectivec/README.md +++ b/objectivec/README.md @@ -133,8 +133,8 @@ This options allow you to provide a custom prefix for all the symbols generated from a proto file (classes (from message), enums, the Root for extension support). -If not set, the generation options `default_objc_class_prefix` and `use_package_as_prefix` -(documented below) control what is used instead. Since Objective C uses a global namespace for all +If not set, the generation option `use_package_as_prefix` (documented below) +controls what is used instead. Since Objective C uses a global namespace for all of its classes, there can be collisions. `use_package_as_prefix=yes` should avoid collisions since proto package are used to scope/name things in other languages, but this option can be used to get shorter names instead. Convention @@ -182,12 +182,6 @@ supported keys are: having to add the runtime directory to the header search path since the generate `#import` will be more complete. - * `default_objc_class_prefix`: The default ObjC prefix value to use when - generating sources. The generator will use this if the `objc_class_prefix` - file option is not set. This option can be useful if multiple iOS apps - consume the same proto file but wish to use a different prefix for their - generated sources. - * `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The `value` for `use_package_as_prefix` can be `yes` or `no`, and indicates if a prefix should be derived from the proto package for all the symbols diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index b6f53a5a9f..713f93ef1b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -190,20 +190,10 @@ bool ObjectiveCGenerator::GenerateAll( // header search path since the generate #import will be more complete. generation_options.runtime_import_prefix = StripSuffixString(options[i].second, "/"); - } else if (options[i].first == "default_objc_class_prefix") { - // The default objc class prefix to use if specified by the command line - // invocation. The file option is always honored first if one is present. - std::string value = options[i].second; - if (value.empty()) { - *error = "error: default_objc_class_prefix cannot be empty."; - return false; - } - SetDefaultObjcClassPrefix(value); } else if (options[i].first == "use_package_as_prefix") { // Controls how the symbols should be prefixed to avoid symbols - // collisions. The objc_class_prefix file option is always honored first - // followed by the default_objc_class_prefix generator option. This is is just - // what to do if either of these options are not set. The available options are: + // collisions. The objc_class_prefix file option is always honored, this + // is just what to do if that isn't set. The available options are: // "no": Not prefixed (the existing mode). // "yes": Make a prefix out of the proto package. bool value = false; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 7b85c517f2..cf926071fc 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -99,9 +99,6 @@ class PrefixModeStorage { public: PrefixModeStorage(); - const std::string default_objc_class_prefix() const { return default_objc_class_prefix_; } - void set_default_objc_class_prefix(const std::string& default_objc_class_prefix) { default_objc_class_prefix_ = default_objc_class_prefix; } - bool use_package_name() const { return use_package_name_; } void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } @@ -119,14 +116,13 @@ class PrefixModeStorage { private: bool use_package_name_; - std::string default_objc_class_prefix_; std::string exception_path_; std::string forced_prefix_; std::unordered_set exceptions_; }; PrefixModeStorage::PrefixModeStorage() { - // Even though there are generation options, have an env back door since some + // Even thought there are generation options, have an env back door since some // of these helpers could be used in other plugins. use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); @@ -173,10 +169,6 @@ PrefixModeStorage g_prefix_mode; } // namespace -void SetDefaultObjcClassPrefix(const std::string& default_objc_class_prefix) { - g_prefix_mode.set_default_objc_class_prefix(default_objc_class_prefix); -} - bool UseProtoPackageAsDefaultPrefix() { return g_prefix_mode.use_package_name(); } @@ -534,16 +526,11 @@ std::string BaseFileName(const FileDescriptor* file) { } std::string FileClassPrefix(const FileDescriptor* file) { - // Always honor the file option first. + // Always honor the file option. if (file->options().has_objc_class_prefix()) { return file->options().objc_class_prefix(); } - // If a default prefix is passed through objc_opt then accept it. - if (!g_prefix_mode.default_objc_class_prefix().empty()) { - return g_prefix_mode.default_objc_class_prefix(); - } - // If package prefix isn't enabled, done. if (!g_prefix_mode.use_package_name()) { return ""; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 418ffaba5e..f4b71ced8e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -47,9 +47,6 @@ namespace protobuf { namespace compiler { namespace objectivec { -// Set the default objc class prefix that should be used. This method is used only -// when default_objc_class_prefix is passed through objc_opt. -void PROTOC_EXPORT SetDefaultObjcClassPrefix(const std::string& objc_class_prefix); // Get/Set if the proto package should be used to make the default prefix for // symbols. This will then impact most of the type naming apis below. It is done // as a global to not break any other generator reusing the methods since they @@ -71,7 +68,6 @@ struct Options { std::string generate_for_named_framework; std::string named_framework_to_proto_path_mappings_path; std::string runtime_import_prefix; - std::string default_objc_class_prefix; bool prefixes_must_be_registered; bool require_prefixes; }; From d0c06bcd9346df37c1dd589dec50d9cf8ba960af Mon Sep 17 00:00:00 2001 From: Arfrever Date: Wed, 23 Feb 2022 00:53:14 +0100 Subject: [PATCH 05/27] cmake: Set correct sonames for libprotobuf-lite.so and libprotoc.so (#9529) Soname was set for libprotobuf.so in commit a9cf69a0ed7766f56976e48a0c96300e94433511, but similar changes for libprotobuf-lite.so and libprotoc.so were missed. Fixes: #8635 Co-authored-by: Arfrever Frehtes Taifersar Arahesis --- cmake/libprotobuf-lite.cmake | 1 + cmake/libprotobuf.cmake | 1 - cmake/libprotoc.cmake | 1 + update_version.py | 16 +++++++++++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 5e98748f60..b915f1f1d9 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -108,6 +108,7 @@ if(protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf-lite PROPERTIES VERSION ${protobuf_VERSION} + SOVERSION 30 OUTPUT_NAME ${LIB_PREFIX}protobuf-lite DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index ef5a3cf593..a9a0aef607 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -125,7 +125,6 @@ if(protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf PROPERTIES VERSION ${protobuf_VERSION} - # Use only the first SO version component for compatibility with Makefile emitted SONAME. SOVERSION 30 OUTPUT_NAME ${LIB_PREFIX}protobuf DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index ed20f31c75..4b967b2a2d 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -140,6 +140,7 @@ endif() set_target_properties(libprotoc PROPERTIES COMPILE_DEFINITIONS LIBPROTOC_EXPORTS VERSION ${protobuf_VERSION} + SOVERSION 30 OUTPUT_NAME ${LIB_PREFIX}protoc DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotoc ALIAS libprotoc) diff --git a/update_version.py b/update_version.py index 6e89555c87..61cf7e837e 100755 --- a/update_version.py +++ b/update_version.py @@ -103,11 +103,17 @@ def RewriteTextFile(filename, line_rewriter): def UpdateCMake(): - RewriteTextFile('cmake/libprotobuf.cmake', - lambda line : re.sub( - r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?', - 'SOVERSION %s' % GetSharedObjectVersion()[0], - line)) + cmake_files = ( + 'cmake/libprotobuf.cmake', + 'cmake/libprotobuf-lite.cmake', + 'cmake/libprotoc.cmake' + ) + for cmake_file in cmake_files: + RewriteTextFile(cmake_file, + lambda line : re.sub( + r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?', + 'SOVERSION %s' % GetSharedObjectVersion()[0], + line)) def UpdateConfigure(): From a112c4ab9642b13b648b19d3a416cfcf9994f3fd Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Fri, 11 Feb 2022 11:05:29 -0800 Subject: [PATCH 06/27] Add `prefix_to_proto_package_mappings_path` ObjC option. --- objectivec/README.md | 30 +++++-- .../objectivec/objectivec_generator.cc | 15 ++++ .../compiler/objectivec/objectivec_helpers.cc | 84 ++++++++++++++++--- .../compiler/objectivec/objectivec_helpers.h | 4 + 4 files changed, 116 insertions(+), 17 deletions(-) diff --git a/objectivec/README.md b/objectivec/README.md index 9aedb219f5..4d0ea95316 100644 --- a/objectivec/README.md +++ b/objectivec/README.md @@ -133,12 +133,12 @@ This options allow you to provide a custom prefix for all the symbols generated from a proto file (classes (from message), enums, the Root for extension support). -If not set, the generation option `use_package_as_prefix` (documented below) -controls what is used instead. Since Objective C uses a global namespace for all -of its classes, there can be collisions. `use_package_as_prefix=yes` should -avoid collisions since proto package are used to scope/name things in other -languages, but this option can be used to get shorter names instead. Convention -is to base the explicit prefix on the proto package. +If not set, the generation options `prefix_to_proto_package_mappings_path` and +`use_package_as_prefix` (documented below) controls what is used instead. Since +Objective C uses a global namespace for all of its classes, there can be collisions. +`use_package_as_prefix=yes` should avoid collisions since proto package are used to +scope/name things in other languages, but this option can be used to get shorter +names instead. Convention is to base the explicit prefix on the proto package. Objective C Generator `protoc` Options -------------------------------------- @@ -182,6 +182,24 @@ supported keys are: having to add the runtime directory to the header search path since the generate `#import` will be more complete. + * `prefix_to_proto_package_mappings_path`: The `value` used for + this key is a path to a file containing a list of prefixes and proto packages. + The generator will use this to locate which ObjC class prefix to use when + generating sources _unless_ the `objc_class_prefix` file option is set. + This option can be useful if multiple apps consume a common set of + proto files but wish to use a different prefix for the generated sources + between them. This option takes precedent over the `use_package_as_prefix` + option. + + The format of the file is: + * An entry is a line of "package=prefix". + * Comments start with `#`. + * A comment can go on a line after a expected package/prefix pair. + (i.e. - "package=prefix # comment") + * For files that do NOT have a proto package (not recommended), an + entry can be made as "no_package:PATH=prefix", where PATH is the + path for the .proto file. + * `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The `value` for `use_package_as_prefix` can be `yes` or `no`, and indicates if a prefix should be derived from the proto package for all the symbols diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 713f93ef1b..6eb537f844 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -190,6 +190,21 @@ bool ObjectiveCGenerator::GenerateAll( // header search path since the generate #import will be more complete. generation_options.runtime_import_prefix = StripSuffixString(options[i].second, "/"); + } else if (options[i].first == "prefix_to_proto_package_mappings_path") { + // Path to use for when loading the objc class prefix mappings to use. + // The `objc_class_prefix` file option is always honored first if one is present. + // This option also has precedent over the use_package_as_prefix option. + // + // The format of the file is: + // - An entry is a line of "package=prefix". + // - Comments start with "#". + // - A comment can go on a line after a expected package/prefix pair. + // (i.e. - "package=prefix # comment") + // - For files that do NOT have a proto package (not recommended), an + // entry can be made as "no_package:PATH=prefix", where PATH is the + // path for the .proto file. + // + SetPrefixToProtoPackageMappingsPath(options[i].second); } else if (options[i].first == "use_package_as_prefix") { // Controls how the symbols should be prefixed to avoid symbols // collisions. The objc_class_prefix file option is always honored, this diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index cf926071fc..4b33165781 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -95,10 +95,29 @@ class SimpleLineCollector : public LineConsumer { std::unordered_set* set_; }; +class ExpectedPrefixesCollector : public LineConsumer { + public: + ExpectedPrefixesCollector(std::map* inout_package_to_prefix_map) + : prefix_map_(inout_package_to_prefix_map) {} + + virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override; + + private: + std::map* prefix_map_; +}; + class PrefixModeStorage { public: PrefixModeStorage(); + const std::string prefix_to_proto_package_mappings_path() const { return prefix_to_proto_package_mappings_path_; } + void set_prefix_to_proto_package_mappings_path(const std::string& path) { + prefix_to_proto_package_mappings_path_ = path; + prefix_to_proto_package_map_.clear(); + } + + std::string prefix_from_proto_package_mappings(const FileDescriptor* file); + bool use_package_name() const { return use_package_name_; } void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } @@ -116,6 +135,8 @@ class PrefixModeStorage { private: bool use_package_name_; + std::map prefix_to_proto_package_map_; + std::string prefix_to_proto_package_mappings_path_; std::string exception_path_; std::string forced_prefix_; std::unordered_set exceptions_; @@ -140,6 +161,44 @@ PrefixModeStorage::PrefixModeStorage() { } } +std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDescriptor* file) { + if (!file) { + return ""; + } + + if (prefix_to_proto_package_map_.empty() && !prefix_to_proto_package_mappings_path_.empty()) { + std::string error_str; + // Re use the same collector as we use for expected_prefixes_path since the file + // format is the same. + ExpectedPrefixesCollector collector(&prefix_to_proto_package_map_); + if (!ParseSimpleFile(prefix_to_proto_package_mappings_path_, &collector, &error_str)) { + if (error_str.empty()) { + error_str = std::string("protoc:0: warning: Failed to parse") + + std::string(" prefix to proto package mappings file: ") + + prefix_to_proto_package_mappings_path_; + } + std::cerr << error_str << std::endl; + std::cerr.flush(); + prefix_to_proto_package_map_.clear(); + } + } + + const std::string package = file->package(); + // For files without packages, the can be registered as "no_package:PATH", + // allowing the expected prefixes file. + static const std::string no_package_prefix("no_package:"); + const std::string lookup_key = package.empty() ? no_package_prefix + file->name() : package; + + std::map::const_iterator prefix_lookup = + prefix_to_proto_package_map_.find(lookup_key); + + if (prefix_lookup != prefix_to_proto_package_map_.end()) { + return prefix_lookup->second; + } + + return ""; +} + bool PrefixModeStorage::is_package_exempted(const std::string& package) { if (exceptions_.empty() && !exception_path_.empty()) { std::string error_str; @@ -169,6 +228,14 @@ PrefixModeStorage g_prefix_mode; } // namespace +std::string GetPrefixToProtoPackageMappingsPath() { + return g_prefix_mode.prefix_to_proto_package_mappings_path(); +} + +void SetPrefixToProtoPackageMappingsPath(const std::string& file_path) { + g_prefix_mode.set_prefix_to_proto_package_mappings_path(file_path); +} + bool UseProtoPackageAsDefaultPrefix() { return g_prefix_mode.use_package_name(); } @@ -531,6 +598,12 @@ std::string FileClassPrefix(const FileDescriptor* file) { return file->options().objc_class_prefix(); } + // If package prefix is specified in an prefix to proto mappings file then use that. + std::string objc_class_prefix = g_prefix_mode.prefix_from_proto_package_mappings(file); + if (!objc_class_prefix.empty()) { + return objc_class_prefix; + } + // If package prefix isn't enabled, done. if (!g_prefix_mode.use_package_name()) { return ""; @@ -1205,17 +1278,6 @@ void RemoveComment(StringPiece* input) { namespace { -class ExpectedPrefixesCollector : public LineConsumer { - public: - ExpectedPrefixesCollector(std::map* inout_package_to_prefix_map) - : prefix_map_(inout_package_to_prefix_map) {} - - virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override; - - private: - std::map* prefix_map_; -}; - bool ExpectedPrefixesCollector::ConsumeLine( const StringPiece& line, std::string* out_error) { int offset = line.find('='); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index f4b71ced8e..2a37e6374a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -47,6 +47,10 @@ namespace protobuf { namespace compiler { namespace objectivec { +// Get/Set the path to a file to load for objc class prefix lookups. +std::string PROTOC_EXPORT GetPrefixToProtoPackageMappingsPath(); +void PROTOC_EXPORT SetPrefixToProtoPackageMappingsPath( + const std::string& file_path); // Get/Set if the proto package should be used to make the default prefix for // symbols. This will then impact most of the type naming apis below. It is done // as a global to not break any other generator reusing the methods since they From a5168a6e969089c9e4616d259c79155439f01941 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:45:56 -0800 Subject: [PATCH 07/27] Fix package naming rule Remove quotes around CPU since we want the variable evaluated instead of the string. This will allow the win64 build to get the correct name. --- protobuf_release.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf_release.bzl b/protobuf_release.bzl index cac0a0c52a..d883dbe971 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -27,7 +27,7 @@ def _package_naming_impl(ctx): elif "linux" in system_name: values["platform"] = "linux-" + cpu elif "mingw" in system_name: - if "cpu" == "x86_64": + if cpu == "x86_64": values["platform"] = "win64" else: values["platform"] = "win32" From e8470340e003b1e417cecf8eb9ed0cd41d496aef Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 24 Feb 2022 14:58:32 -0500 Subject: [PATCH 08/27] Rename ExpectedPrefixesCollector to PackageToPrefixesCollector Now that two files use the format, tweak the naming to the format for the file vs. the usage(s). Also add a "usage" param so the two places can provide a little context for any error messages generated while parsing. --- .../compiler/objectivec/objectivec_helpers.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 4b33165781..94a0286b33 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -95,14 +95,16 @@ class SimpleLineCollector : public LineConsumer { std::unordered_set* set_; }; -class ExpectedPrefixesCollector : public LineConsumer { +class PackageToPrefixesCollector : public LineConsumer { public: - ExpectedPrefixesCollector(std::map* inout_package_to_prefix_map) - : prefix_map_(inout_package_to_prefix_map) {} + PackageToPrefixesCollector(const std::string &usage, + std::map* inout_package_to_prefix_map) + : usage_(usage), prefix_map_(inout_package_to_prefix_map) {} virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override; private: + const std::string usage_; std::map* prefix_map_; }; @@ -170,7 +172,7 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDesc std::string error_str; // Re use the same collector as we use for expected_prefixes_path since the file // format is the same. - ExpectedPrefixesCollector collector(&prefix_to_proto_package_map_); + PackageToPrefixesCollector collector("Package to prefixes", &prefix_to_proto_package_map_); if (!ParseSimpleFile(prefix_to_proto_package_mappings_path_, &collector, &error_str)) { if (error_str.empty()) { error_str = std::string("protoc:0: warning: Failed to parse") @@ -1278,12 +1280,11 @@ void RemoveComment(StringPiece* input) { namespace { -bool ExpectedPrefixesCollector::ConsumeLine( +bool PackageToPrefixesCollector::ConsumeLine( const StringPiece& line, std::string* out_error) { int offset = line.find('='); if (offset == StringPiece::npos) { - *out_error = std::string("Expected prefixes file line without equal sign: '") + - std::string(line) + "'."; + *out_error = usage_ + " file line without equal sign: '" + StrCat(line) + "'."; return false; } StringPiece package = line.substr(0, offset); @@ -1304,7 +1305,7 @@ bool LoadExpectedPackagePrefixes(const Options& generation_options, return true; } - ExpectedPrefixesCollector collector(prefix_map); + PackageToPrefixesCollector collector("Expected prefixes", prefix_map); return ParseSimpleFile( generation_options.expected_prefixes_path, &collector, out_error); } From 6a77c9bab4bd3c8e10096694469b203bc211246f Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 24 Feb 2022 14:38:56 -0500 Subject: [PATCH 09/27] Make the ObjC support conditional to darwin. Fixes #9392 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4c774b0bea..db69069785 100644 --- a/configure.ac +++ b/configure.ac @@ -80,7 +80,7 @@ AC_LANG([C++]) ACX_USE_SYSTEM_EXTENSIONS m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc -AC_PROG_OBJC +AS_CASE([$target_os], [darwin*], [AC_PROG_OBJC], [AM_CONDITIONAL([am__fastdepOBJC], [false])]) # test_util.cc takes forever to compile with GCC and optimization turned on. AC_MSG_CHECKING([C++ compiler flags...]) From df0999141ed50fd6b844e558235b1be4aa59efa9 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 25 Feb 2022 14:11:12 +0000 Subject: [PATCH 10/27] Update JRuby 9.2.19.0 -> 9.2.20.1 and 9.3.0.0 to 9.3.3.0. --- kokoro/linux/dockerfile/test/ruby/Dockerfile | 4 ++-- ruby/pom.xml | 2 +- tests.sh | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kokoro/linux/dockerfile/test/ruby/Dockerfile b/kokoro/linux/dockerfile/test/ruby/Dockerfile index 836287090a..cfdc5ba031 100644 --- a/kokoro/linux/dockerfile/test/ruby/Dockerfile +++ b/kokoro/linux/dockerfile/test/ruby/Dockerfile @@ -35,8 +35,8 @@ RUN /bin/bash -l -c "rvm install 2.5.1" RUN /bin/bash -l -c "rvm install 2.6.0" RUN /bin/bash -l -c "rvm install 2.7.0" RUN /bin/bash -l -c "rvm install 3.0.0" -RUN /bin/bash -l -c "rvm install jruby-9.2.19.0" -RUN /bin/bash -l -c "rvm install jruby-9.3.0.0" +RUN /bin/bash -l -c "rvm install jruby-9.2.20.1" +RUN /bin/bash -l -c "rvm install jruby-9.3.3.0" RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" diff --git a/ruby/pom.xml b/ruby/pom.xml index c9ae9e6633..7fd164ac02 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -81,7 +81,7 @@ org.jruby jruby-complete - 9.2.19.0 + 9.2.20.1 provided diff --git a/tests.sh b/tests.sh index 8ea5ae6f6b..d9047c40d2 100755 --- a/tests.sh +++ b/tests.sh @@ -426,13 +426,13 @@ build_ruby30() { build_jruby92() { internal_build_cpp # For conformance tests. internal_build_java jdk8 && cd .. # For Maven protobuf jar with local changes - cd ruby && bash travis-test.sh jruby-9.2.19.0 && cd .. + cd ruby && bash travis-test.sh jruby-9.2.20.1 && cd .. } build_jruby93() { internal_build_cpp # For conformance tests. internal_build_java jdk8 && cd .. # For Maven protobuf jar with local changes - cd ruby && bash travis-test.sh jruby-9.3.0.0 && cd .. + cd ruby && bash travis-test.sh jruby-9.3.3.0 && cd .. } build_javascript() { From 89c40311dbfaed8c6269e58384af951159f5a895 Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Fri, 25 Feb 2022 09:06:20 -0800 Subject: [PATCH 11/27] Rename `proto_package_to_prefix_mappings_path` to `package_to_prefix_mappings_path`. --- objectivec/README.md | 6 ++-- .../objectivec/objectivec_generator.cc | 4 +-- .../compiler/objectivec/objectivec_helpers.cc | 34 +++++++++---------- .../compiler/objectivec/objectivec_helpers.h | 4 +-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/objectivec/README.md b/objectivec/README.md index 4d0ea95316..955fa531b7 100644 --- a/objectivec/README.md +++ b/objectivec/README.md @@ -133,7 +133,7 @@ This options allow you to provide a custom prefix for all the symbols generated from a proto file (classes (from message), enums, the Root for extension support). -If not set, the generation options `prefix_to_proto_package_mappings_path` and +If not set, the generation options `package_to_prefix_mappings_path` and `use_package_as_prefix` (documented below) controls what is used instead. Since Objective C uses a global namespace for all of its classes, there can be collisions. `use_package_as_prefix=yes` should avoid collisions since proto package are used to @@ -182,8 +182,8 @@ supported keys are: having to add the runtime directory to the header search path since the generate `#import` will be more complete. - * `prefix_to_proto_package_mappings_path`: The `value` used for - this key is a path to a file containing a list of prefixes and proto packages. + * `package_to_prefix_mappings_path`: The `value` used for this key is a + path to a file containing a list of proto packages and prefixes. The generator will use this to locate which ObjC class prefix to use when generating sources _unless_ the `objc_class_prefix` file option is set. This option can be useful if multiple apps consume a common set of diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 6eb537f844..9e9bbfd4f9 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -190,7 +190,7 @@ bool ObjectiveCGenerator::GenerateAll( // header search path since the generate #import will be more complete. generation_options.runtime_import_prefix = StripSuffixString(options[i].second, "/"); - } else if (options[i].first == "prefix_to_proto_package_mappings_path") { + } else if (options[i].first == "package_to_prefix_mappings_path") { // Path to use for when loading the objc class prefix mappings to use. // The `objc_class_prefix` file option is always honored first if one is present. // This option also has precedent over the use_package_as_prefix option. @@ -204,7 +204,7 @@ bool ObjectiveCGenerator::GenerateAll( // entry can be made as "no_package:PATH=prefix", where PATH is the // path for the .proto file. // - SetPrefixToProtoPackageMappingsPath(options[i].second); + SetPackageToPrefixMappingsPath(options[i].second); } else if (options[i].first == "use_package_as_prefix") { // Controls how the symbols should be prefixed to avoid symbols // collisions. The objc_class_prefix file option is always honored, this diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 94a0286b33..b085d0283c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -112,10 +112,10 @@ class PrefixModeStorage { public: PrefixModeStorage(); - const std::string prefix_to_proto_package_mappings_path() const { return prefix_to_proto_package_mappings_path_; } - void set_prefix_to_proto_package_mappings_path(const std::string& path) { - prefix_to_proto_package_mappings_path_ = path; - prefix_to_proto_package_map_.clear(); + const std::string package_to_prefix_mappings_path() const { return package_to_prefix_mappings_path_; } + void set_package_to_prefix_mappings_path(const std::string& path) { + package_to_prefix_mappings_path_ = path; + package_to_prefix_map_.clear(); } std::string prefix_from_proto_package_mappings(const FileDescriptor* file); @@ -137,8 +137,8 @@ class PrefixModeStorage { private: bool use_package_name_; - std::map prefix_to_proto_package_map_; - std::string prefix_to_proto_package_mappings_path_; + std::map package_to_prefix_map_; + std::string package_to_prefix_mappings_path_; std::string exception_path_; std::string forced_prefix_; std::unordered_set exceptions_; @@ -168,20 +168,20 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDesc return ""; } - if (prefix_to_proto_package_map_.empty() && !prefix_to_proto_package_mappings_path_.empty()) { + if (package_to_prefix_map_.empty() && !package_to_prefix_mappings_path_.empty()) { std::string error_str; // Re use the same collector as we use for expected_prefixes_path since the file // format is the same. - PackageToPrefixesCollector collector("Package to prefixes", &prefix_to_proto_package_map_); - if (!ParseSimpleFile(prefix_to_proto_package_mappings_path_, &collector, &error_str)) { + PackageToPrefixesCollector collector("Package to prefixes", &package_to_prefix_map_); + if (!ParseSimpleFile(package_to_prefix_mappings_path_, &collector, &error_str)) { if (error_str.empty()) { error_str = std::string("protoc:0: warning: Failed to parse") + std::string(" prefix to proto package mappings file: ") - + prefix_to_proto_package_mappings_path_; + + package_to_prefix_mappings_path_; } std::cerr << error_str << std::endl; std::cerr.flush(); - prefix_to_proto_package_map_.clear(); + package_to_prefix_map_.clear(); } } @@ -192,9 +192,9 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDesc const std::string lookup_key = package.empty() ? no_package_prefix + file->name() : package; std::map::const_iterator prefix_lookup = - prefix_to_proto_package_map_.find(lookup_key); + package_to_prefix_map_.find(lookup_key); - if (prefix_lookup != prefix_to_proto_package_map_.end()) { + if (prefix_lookup != package_to_prefix_map_.end()) { return prefix_lookup->second; } @@ -230,12 +230,12 @@ PrefixModeStorage g_prefix_mode; } // namespace -std::string GetPrefixToProtoPackageMappingsPath() { - return g_prefix_mode.prefix_to_proto_package_mappings_path(); +std::string GetPackageToPrefixMappingsPath() { + return g_prefix_mode.package_to_prefix_mappings_path(); } -void SetPrefixToProtoPackageMappingsPath(const std::string& file_path) { - g_prefix_mode.set_prefix_to_proto_package_mappings_path(file_path); +void SetPackageToPrefixMappingsPath(const std::string& file_path) { + g_prefix_mode.set_package_to_prefix_mappings_path(file_path); } bool UseProtoPackageAsDefaultPrefix() { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 2a37e6374a..d67ec04eba 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -48,8 +48,8 @@ namespace compiler { namespace objectivec { // Get/Set the path to a file to load for objc class prefix lookups. -std::string PROTOC_EXPORT GetPrefixToProtoPackageMappingsPath(); -void PROTOC_EXPORT SetPrefixToProtoPackageMappingsPath( +std::string PROTOC_EXPORT GetPackageToPrefixMappingsPath(); +void PROTOC_EXPORT SetPackageToPrefixMappingsPath( const std::string& file_path); // Get/Set if the proto package should be used to make the default prefix for // symbols. This will then impact most of the type naming apis below. It is done From 5b3f853d7dae8622445e55c3b73d16bbbadbddf6 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Fri, 25 Feb 2022 10:45:28 -0800 Subject: [PATCH 12/27] Make protoc executable names consistent Rename ppc64 cpu to ppcle_64 to match current release. --- protobuf_release.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protobuf_release.bzl b/protobuf_release.bzl index d883dbe971..c5d5f2bf2c 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -20,6 +20,8 @@ def _package_naming_impl(ctx): cpu = "s390_64" elif cpu == "aarch64": cpu = "aarch_64" + elif cpu == "ppc64": + cpu = "ppcle_64" # use the system name to determine the os and then create platform names if "apple" in system_name: From b44784cf3061e853d6b70a47c0216ad0806bc150 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 25 Feb 2022 15:30:07 -0800 Subject: [PATCH 13/27] Fix update_version.py script (#9554) Two small fixes to update_version.py: - The regex for updating SOVERSION in cmake files was not quite right. I fixed it to reflect that the value is a plain integer and not of the form x.y.z - For some reason the code for updating PHP_PROTO_VERSION appeared 3 times and led to a spurious warning, so I removed the extra calls there. --- update_version.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/update_version.py b/update_version.py index 61cf7e837e..3a96991816 100755 --- a/update_version.py +++ b/update_version.py @@ -111,7 +111,7 @@ def UpdateCMake(): for cmake_file in cmake_files: RewriteTextFile(cmake_file, lambda line : re.sub( - r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?', + r'SOVERSION ([0-9]+)$', 'SOVERSION %s' % GetSharedObjectVersion()[0], line)) @@ -365,18 +365,6 @@ def UpdatePhp(): changelog.appendChild(release) changelog.appendChild(document.createTextNode('\n ')) RewriteXml('php/ext/google/protobuf/package.xml', Callback) - RewriteTextFile('php/ext/google/protobuf/protobuf.h', - lambda line : re.sub( - r'PHP_PROTOBUF_VERSION ".*"$', - 'PHP_PROTOBUF_VERSION "%s"' % NEW_VERSION, - line)) - - RewriteTextFile('php/ext/google/protobuf/protobuf.h', - lambda line : re.sub( - r"^#define PHP_PROTOBUF_VERSION .*$", - "#define PHP_PROTOBUF_VERSION \"%s\"" % GetFullVersion(rc_suffix = 'RC'), - line)) - RewriteTextFile('php/ext/google/protobuf/protobuf.h', lambda line : re.sub( r"^#define PHP_PROTOBUF_VERSION .*$", From ee429aea17df613758bbee451f96ecf80e2cef9e Mon Sep 17 00:00:00 2001 From: Greg Miller <9447643+devjgm@users.noreply.github.com> Date: Fri, 25 Feb 2022 21:13:50 -0500 Subject: [PATCH 14/27] chore: gitignore ephemeral files that clangd uses This PR tells git to ignore ephemeral files that are created when developers use clangd. clangd needs a `compile_commands.json` file at the root of the repo (or in a `build/` directory) to tell it how to compile each file. CMake can generate this file with something like the following: ```console $ cmake -Scmake -B.build \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -Dprotobuf_BUILD_TESTS=OFF $ ln -sf .build/compile_commands.json . ``` Then clangd will compile and index files into the `.cache` directory. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 1040236af1..4fe3edde37 100644 --- a/.gitignore +++ b/.gitignore @@ -222,3 +222,7 @@ _build/ # BenchmarkDotNet BenchmarkDotNet.Artifacts/ + +# Clangd uses these common ephemeral files +.cache +compile_commands.json From 6c8bda86fe851e3aebd207a4d7bd105feb87882b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Sun, 27 Feb 2022 10:22:03 -0800 Subject: [PATCH 15/27] Suppress warning for intentional circular require --- ruby/lib/google/protobuf/descriptor_dsl.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ruby/lib/google/protobuf/descriptor_dsl.rb b/ruby/lib/google/protobuf/descriptor_dsl.rb index c3e9a5a620..7349b6df15 100644 --- a/ruby/lib/google/protobuf/descriptor_dsl.rb +++ b/ruby/lib/google/protobuf/descriptor_dsl.rb @@ -2,7 +2,14 @@ # # Code that implements the DSL for defining proto messages. -require 'google/protobuf/descriptor_pb' +# Suppress warning: loading in progress, circular require considered harmful. +# This circular require is intentional to avoid missing dependency. +begin + old_verbose, $VERBOSE = $VERBOSE, nil + require 'google/protobuf/descriptor_pb' +ensure + $VERBOSE = old_verbose +end module Google module Protobuf From aafcb92f621d8eb66fd39633c0e3a95eafe67617 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Mon, 28 Feb 2022 18:28:50 +0000 Subject: [PATCH 16/27] kotlin core maven export --- java/kotlin/BUILD | 30 ++++++++++++++++++++++++++++++ protobuf_deps.bzl | 6 +++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index b4bdf7393f..f2bc5385c2 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -1,5 +1,6 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") load("@rules_proto//proto:defs.bzl", "proto_library") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") @@ -47,6 +48,35 @@ kt_jvm_library( deps = ["//java/core"], ) +kt_jvm_library( + name = "kotlin", + runtime_deps = [ + ":bytestring_lib", + ":full_extensions", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + ":well_known_protos_kotlin", + ], + visibility = ["//visibility:public"], +) + +kt_jvm_export( + name = "kotlin_mvn", + maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, + resources = ["//:well_known_protos"], + runtime_deps = [ + ":bytestring_lib", + ":full_extensions", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + ":well_known_protos_kotlin", + ], + deploy_env = [ + "@com_github_jetbrains_kotlin//:kotlin-stdlib", + "//java/core", + ], +) + test_suite( name = "tests", tests = [ diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 7e2caa3302..27b8bee258 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -70,9 +70,9 @@ def protobuf_deps(): if not native.existing_rule("rules_jvm_external"): http_archive( name = "rules_jvm_external", - sha256 = "f36441aa876c4f6427bfb2d1f2d723b48e9d930b62662bf723ddfb8fc80f0140", - strip_prefix = "rules_jvm_external-4.1", - urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.1.zip"], + sha256 = "744bd7436f63af7e9872948773b8b106016dc164acb3960b4963f86754532ee7", + strip_prefix = "rules_jvm_external-906875b0d5eaaf61a8ca2c9c3835bde6f435d011", + urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/906875b0d5eaaf61a8ca2c9c3835bde6f435d011.zip"], ) if not native.existing_rule("rules_pkg"): From 93b4fa6fc7b826af03733a56a5a686356e54c806 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Mon, 28 Feb 2022 19:54:14 +0000 Subject: [PATCH 17/27] Only exe extension for windows --- toolchain/cc_toolchain_config.bzl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index e85e03e3da..81fe19e723 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -28,13 +28,16 @@ all_compile_actions = [ ] def _impl(ctx): - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "executable", - prefix = "", - extension = ".exe", - ), - ] + if 'mingw' in ctx.attr.target_full_name: + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + else: + artifact_name_patterns = [] tool_paths = [ tool_path( From 933239f8c3482786593a3db2b6a43b572cdbeca6 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 1 Mar 2022 00:27:42 +0000 Subject: [PATCH 18/27] Update build files --- java/BUILD | 2 ++ java/kotlin-lite/BUILD | 43 ++++++++++++++++++++++++++++++++++++++++++ java/kotlin/BUILD | 25 ++++++++++++------------ java/util/BUILD | 1 + 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/java/BUILD b/java/BUILD index 3e57ab6d7b..4a1cdc2c0f 100644 --- a/java/BUILD +++ b/java/BUILD @@ -13,6 +13,8 @@ filegroup( name = "release", srcs = [ "//java/core:release", # contains lite. + "//java/kotlin:release", + "//java/kotlin-lite:release", "//java/util:release", ] ) diff --git a/java/kotlin-lite/BUILD b/java/kotlin-lite/BUILD index a41584a8bb..fd0c103166 100644 --- a/java/kotlin-lite/BUILD +++ b/java/kotlin-lite/BUILD @@ -1,5 +1,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_lite_proto_library") +load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") +load("//:protobuf_version.bzl", "PROTOBUF_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") java_lite_proto_library( @@ -13,6 +15,47 @@ kt_jvm_library( deps = ["//java/lite"], ) +kt_jvm_library( + name = "well_known_protos_kotlin_lite", + srcs = [ + "//:gen_well_known_protos_kotlinlite", + ], + deps = [ + "//java/lite", + "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/kotlin:shared_runtime", + ], +) + +kt_jvm_export( + name = "kotlin-lite_mvn", + maven_coordinates = "com.google.protobuf:protobuf-kotlin-lite:%s" % PROTOBUF_VERSION, + pom_template = "//java/kotlin-lite:pom_template.xml", + resources = ["//:well_known_protos"], + runtime_deps = [ + ":lite_extensions", + ":well_known_protos_kotlin_lite", + "//java/kotlin:bytestring_lib", + "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/kotlin:shared_runtime", + ], + deploy_env = [ + "@com_github_jetbrains_kotlin//:kotlin-stdlib", + "//java/lite", + ], +) + +filegroup( + name = "release", + srcs = [ + ":kotlin-lite_mvn-docs", + ":kotlin-lite_mvn-maven-source", + ":kotlin-lite_mvn-pom", + ":kotlin-lite_mvn-project", + ], + visibility = ["//java:__pkg__"], +) + test_suite( name = "tests", tests = [ diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index f2bc5385c2..1da4de535c 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -37,6 +37,7 @@ kt_jvm_library( name = "bytestring_lib", srcs = ["src/main/kotlin/com/google/protobuf/ByteStrings.kt"], deps = ["//java/lite"], + visibility = ["//java:__subpackages__"], ) kt_jvm_library( @@ -48,21 +49,10 @@ kt_jvm_library( deps = ["//java/core"], ) -kt_jvm_library( - name = "kotlin", - runtime_deps = [ - ":bytestring_lib", - ":full_extensions", - ":only_for_use_in_proto_generated_code_its_generator_and_tests", - ":shared_runtime", - ":well_known_protos_kotlin", - ], - visibility = ["//visibility:public"], -) - kt_jvm_export( name = "kotlin_mvn", maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, + pom_template = "//java/kotlin:pom_template.xml", resources = ["//:well_known_protos"], runtime_deps = [ ":bytestring_lib", @@ -77,6 +67,17 @@ kt_jvm_export( ], ) +filegroup( + name = "release", + srcs = [ + ":kotlin_mvn-docs", + ":kotlin_mvn-maven-source", + ":kotlin_mvn-pom", + ":kotlin_mvn-project", + ], + visibility = ["//java:__pkg__"], +) + test_suite( name = "tests", tests = [ diff --git a/java/util/BUILD b/java/util/BUILD index 2714917e41..c835b68202 100644 --- a/java/util/BUILD +++ b/java/util/BUILD @@ -27,6 +27,7 @@ java_export( pom_template = "pom_template.xml", visibility = ["//java:__pkg__"], runtime_deps = [":util"], + deploy_env = ["//java/core"], ) filegroup( From 14e445bc34f3d51fb117297f2e893edb8d54ad78 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 28 Feb 2022 16:32:04 -0500 Subject: [PATCH 19/27] Stop passing generation options thru the graph. They never were needed below file, and they really are specific to two high level case, so don't pass them every where else. --- .../objectivec/objectivec_enum_field.cc | 9 ++-- .../objectivec/objectivec_enum_field.h | 11 ++--- .../compiler/objectivec/objectivec_field.cc | 43 ++++++++----------- .../compiler/objectivec/objectivec_field.h | 17 +++----- .../compiler/objectivec/objectivec_file.cc | 2 +- .../objectivec/objectivec_map_field.cc | 7 ++- .../objectivec/objectivec_map_field.h | 5 +-- .../compiler/objectivec/objectivec_message.cc | 8 ++-- .../compiler/objectivec/objectivec_message.h | 3 +- .../objectivec/objectivec_message_field.cc | 9 ++-- .../objectivec/objectivec_message_field.h | 12 ++---- .../objectivec/objectivec_primitive_field.cc | 12 +++--- .../objectivec/objectivec_primitive_field.h | 18 +++----- 13 files changed, 63 insertions(+), 93 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index ff69f39f48..cdb208065e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -65,9 +65,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor, } } // namespace -EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor, - const Options& options) - : SingleFieldGenerator(descriptor, options) { +EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor) + : SingleFieldGenerator(descriptor) { SetEnumVariables(descriptor, &variables_); } @@ -129,8 +128,8 @@ void EnumFieldGenerator::DetermineForwardDeclarations( } RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : RepeatedFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : RepeatedFieldGenerator(descriptor) { SetEnumVariables(descriptor, &variables_); variables_["array_storage_type"] = "GPBEnumArray"; } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index 3fb0a9fd11..f89107e857 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -41,8 +41,7 @@ namespace compiler { namespace objectivec { class EnumFieldGenerator : public SingleFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); EnumFieldGenerator(const EnumFieldGenerator&) = delete; EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete; @@ -56,20 +55,18 @@ class EnumFieldGenerator : public SingleFieldGenerator { std::set* fwd_decls) const override; protected: - EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); + EnumFieldGenerator(const FieldDescriptor* descriptor); virtual ~EnumFieldGenerator(); }; class RepeatedEnumFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); public: virtual void FinishInitialization() override; protected: - RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); virtual ~RepeatedEnumFieldGenerator(); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index eb23fee19f..2500f37dd0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -118,40 +118,39 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, } // namespace -FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options) { +FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field) { FieldGenerator* result = NULL; if (field->is_repeated()) { switch (GetObjectiveCType(field)) { case OBJECTIVECTYPE_MESSAGE: { if (field->is_map()) { - result = new MapFieldGenerator(field, options); + result = new MapFieldGenerator(field); } else { - result = new RepeatedMessageFieldGenerator(field, options); + result = new RepeatedMessageFieldGenerator(field); } break; } case OBJECTIVECTYPE_ENUM: - result = new RepeatedEnumFieldGenerator(field, options); + result = new RepeatedEnumFieldGenerator(field); break; default: - result = new RepeatedPrimitiveFieldGenerator(field, options); + result = new RepeatedPrimitiveFieldGenerator(field); break; } } else { switch (GetObjectiveCType(field)) { case OBJECTIVECTYPE_MESSAGE: { - result = new MessageFieldGenerator(field, options); + result = new MessageFieldGenerator(field); break; } case OBJECTIVECTYPE_ENUM: - result = new EnumFieldGenerator(field, options); + result = new EnumFieldGenerator(field); break; default: if (IsReferenceType(field)) { - result = new PrimitiveObjFieldGenerator(field, options); + result = new PrimitiveObjFieldGenerator(field); } else { - result = new PrimitiveFieldGenerator(field, options); + result = new PrimitiveFieldGenerator(field); } break; } @@ -160,8 +159,7 @@ FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, return result; } -FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor, - const Options& options) +FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor) : descriptor_(descriptor) { SetCommonFieldVariables(descriptor, &variables_); } @@ -266,9 +264,8 @@ void FieldGenerator::FinishInitialization(void) { } } -SingleFieldGenerator::SingleFieldGenerator(const FieldDescriptor* descriptor, - const Options& options) - : FieldGenerator(descriptor, options) { +SingleFieldGenerator::SingleFieldGenerator(const FieldDescriptor* descriptor) + : FieldGenerator(descriptor) { // Nothing } @@ -310,9 +307,8 @@ bool SingleFieldGenerator::RuntimeUsesHasBit(void) const { return true; } -ObjCObjFieldGenerator::ObjCObjFieldGenerator(const FieldDescriptor* descriptor, - const Options& options) - : SingleFieldGenerator(descriptor, options) { +ObjCObjFieldGenerator::ObjCObjFieldGenerator(const FieldDescriptor* descriptor) + : SingleFieldGenerator(descriptor) { variables_["property_storage_attribute"] = "strong"; if (IsRetainedName(variables_["name"])) { variables_["storage_attribute"] = " NS_RETURNS_NOT_RETAINED"; @@ -353,8 +349,8 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration( } RepeatedFieldGenerator::RepeatedFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : ObjCObjFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : ObjCObjFieldGenerator(descriptor) { // Default to no comment and let the cases needing it fill it in. variables_["array_comment"] = ""; } @@ -407,19 +403,18 @@ bool RepeatedFieldGenerator::RuntimeUsesHasBit(void) const { return false; // The array (or map/dict) having anything is what is used. } -FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor, - const Options& options) +FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) : descriptor_(descriptor), field_generators_(descriptor->field_count()), extension_generators_(descriptor->extension_count()) { // Construct all the FieldGenerators. for (int i = 0; i < descriptor->field_count(); i++) { field_generators_[i].reset( - FieldGenerator::Make(descriptor->field(i), options)); + FieldGenerator::Make(descriptor->field(i))); } for (int i = 0; i < descriptor->extension_count(); i++) { extension_generators_[i].reset( - FieldGenerator::Make(descriptor->extension(i), options)); + FieldGenerator::Make(descriptor->extension(i))); } } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.h b/src/google/protobuf/compiler/objectivec/objectivec_field.h index ad8e55aeb2..c5080d6ba6 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -44,8 +43,7 @@ namespace objectivec { class FieldGenerator { public: - static FieldGenerator* Make(const FieldDescriptor* field, - const Options& options); + static FieldGenerator* Make(const FieldDescriptor* field); virtual ~FieldGenerator(); @@ -96,7 +94,7 @@ class FieldGenerator { std::string raw_field_name() const { return variable("raw_field_name"); } protected: - FieldGenerator(const FieldDescriptor* descriptor, const Options& options); + FieldGenerator(const FieldDescriptor* descriptor); virtual void FinishInitialization(void); bool WantsHasProperty(void) const; @@ -120,8 +118,7 @@ class SingleFieldGenerator : public FieldGenerator { virtual bool RuntimeUsesHasBit(void) const override; protected: - SingleFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + SingleFieldGenerator(const FieldDescriptor* descriptor); }; // Subclass with common support for when the field ends up as an ObjC Object. @@ -136,8 +133,7 @@ class ObjCObjFieldGenerator : public SingleFieldGenerator { virtual void GeneratePropertyDeclaration(io::Printer* printer) const override; protected: - ObjCObjFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + ObjCObjFieldGenerator(const FieldDescriptor* descriptor); }; class RepeatedFieldGenerator : public ObjCObjFieldGenerator { @@ -155,15 +151,14 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator { virtual bool RuntimeUsesHasBit(void) const override; protected: - RepeatedFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + RepeatedFieldGenerator(const FieldDescriptor* descriptor); virtual void FinishInitialization(void) override; }; // Convenience class which constructs FieldGenerators for a Descriptor. class FieldGeneratorMap { public: - FieldGeneratorMap(const Descriptor* descriptor, const Options& options); + FieldGeneratorMap(const Descriptor* descriptor); ~FieldGeneratorMap(); FieldGeneratorMap(const FieldGeneratorMap&) = delete; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index d9f43a55c7..0b4f4fa291 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -196,7 +196,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) } for (int i = 0; i < file_->message_type_count(); i++) { MessageGenerator* generator = - new MessageGenerator(root_class_name_, file_->message_type(i), options_); + new MessageGenerator(root_class_name_, file_->message_type(i)); message_generators_.emplace_back(generator); } for (int i = 0; i < file_->extension_count(); i++) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index c1b1f53b14..f6943cd990 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -81,14 +81,13 @@ const char* MapEntryTypeName(const FieldDescriptor* descriptor, bool isKey) { } // namespace -MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor, - const Options& options) - : RepeatedFieldGenerator(descriptor, options) { +MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor) + : RepeatedFieldGenerator(descriptor) { const FieldDescriptor* key_descriptor = descriptor->message_type()->map_key(); const FieldDescriptor* value_descriptor = descriptor->message_type()->map_value(); - value_field_generator_.reset(FieldGenerator::Make(value_descriptor, options)); + value_field_generator_.reset(FieldGenerator::Make(value_descriptor)); // Pull over some variables_ from the value. variables_["field_type"] = value_field_generator_->variable("field_type"); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index 84eac6183a..c5b9b1df43 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -41,8 +41,7 @@ namespace compiler { namespace objectivec { class MapFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); public: virtual void FinishInitialization(void) override; @@ -51,7 +50,7 @@ class MapFieldGenerator : public RepeatedFieldGenerator { MapFieldGenerator& operator=(const MapFieldGenerator&) = delete; protected: - MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options); + MapFieldGenerator(const FieldDescriptor* descriptor); virtual ~MapFieldGenerator(); virtual void DetermineObjectiveCClassDefinitions( diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 3a00113f32..634b227d3f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -171,11 +171,10 @@ const FieldDescriptor** SortFieldsByStorageSize(const Descriptor* descriptor) { } // namespace MessageGenerator::MessageGenerator(const std::string& root_classname, - const Descriptor* descriptor, - const Options& options) + const Descriptor* descriptor) : root_classname_(root_classname), descriptor_(descriptor), - field_generators_(descriptor, options), + field_generators_(descriptor), class_name_(ClassName(descriptor_)), deprecated_attribute_(GetOptionalDeprecatedAttribute( descriptor, descriptor->file(), false, true)) { @@ -197,8 +196,7 @@ MessageGenerator::MessageGenerator(const std::string& root_classname, for (int i = 0; i < descriptor_->nested_type_count(); i++) { MessageGenerator* generator = new MessageGenerator(root_classname_, - descriptor_->nested_type(i), - options); + descriptor_->nested_type(i)); nested_message_generators_.emplace_back(generator); } } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 01108d29e7..f532751810 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -51,7 +50,7 @@ class EnumGenerator; class MessageGenerator { public: MessageGenerator(const std::string& root_classname, - const Descriptor* descriptor, const Options& options); + const Descriptor* descriptor); ~MessageGenerator(); MessageGenerator(const MessageGenerator&) = delete; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index 299a20b152..437da524ae 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -58,9 +58,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, } // namespace -MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor, - const Options& options) - : ObjCObjFieldGenerator(descriptor, options) { +MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor) + : ObjCObjFieldGenerator(descriptor) { SetMessageVariables(descriptor, &variables_); } @@ -79,8 +78,8 @@ void MessageFieldGenerator::DetermineObjectiveCClassDefinitions( } RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : RepeatedFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : RepeatedFieldGenerator(descriptor) { SetMessageVariables(descriptor, &variables_); variables_["array_storage_type"] = "NSMutableArray"; variables_["array_property_type"] = diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index 01799a120b..1abf5c8ed5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -41,12 +41,10 @@ namespace compiler { namespace objectivec { class MessageFieldGenerator : public ObjCObjFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); protected: - MessageFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + MessageFieldGenerator(const FieldDescriptor* descriptor); MessageFieldGenerator(const MessageFieldGenerator&) = delete; MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete; @@ -61,12 +59,10 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator { }; class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); protected: - RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); virtual ~RepeatedMessageFieldGenerator(); RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index e198c5c182..5a89f45c0d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -125,8 +125,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, } // namespace PrimitiveFieldGenerator::PrimitiveFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : SingleFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : SingleFieldGenerator(descriptor) { SetPrimitiveVariables(descriptor, &variables_); } @@ -159,8 +159,8 @@ void PrimitiveFieldGenerator::SetExtraRuntimeHasBitsBase(int has_base) { } PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : ObjCObjFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : ObjCObjFieldGenerator(descriptor) { SetPrimitiveVariables(descriptor, &variables_); variables_["property_storage_attribute"] = "copy"; } @@ -168,8 +168,8 @@ PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator( PrimitiveObjFieldGenerator::~PrimitiveObjFieldGenerator() {} RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator( - const FieldDescriptor* descriptor, const Options& options) - : RepeatedFieldGenerator(descriptor, options) { + const FieldDescriptor* descriptor) + : RepeatedFieldGenerator(descriptor) { SetPrimitiveVariables(descriptor, &variables_); std::string base_name = PrimitiveArrayTypeName(descriptor); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h index a9f30f6419..291d11a2e3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h @@ -41,12 +41,10 @@ namespace compiler { namespace objectivec { class PrimitiveFieldGenerator : public SingleFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); protected: - PrimitiveFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + PrimitiveFieldGenerator(const FieldDescriptor* descriptor); virtual ~PrimitiveFieldGenerator(); PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete; @@ -59,12 +57,10 @@ class PrimitiveFieldGenerator : public SingleFieldGenerator { }; class PrimitiveObjFieldGenerator : public ObjCObjFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); protected: - PrimitiveObjFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + PrimitiveObjFieldGenerator(const FieldDescriptor* descriptor); virtual ~PrimitiveObjFieldGenerator(); PrimitiveObjFieldGenerator(const PrimitiveObjFieldGenerator&) = delete; @@ -73,12 +69,10 @@ class PrimitiveObjFieldGenerator : public ObjCObjFieldGenerator { }; class RepeatedPrimitiveFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, - const Options& options); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); protected: - RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, - const Options& options); + RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor); virtual ~RepeatedPrimitiveFieldGenerator(); RepeatedPrimitiveFieldGenerator(const RepeatedPrimitiveFieldGenerator&) = From d9048081b25ee4a48b40ce687d60a5228cb182b9 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 28 Feb 2022 17:01:23 -0500 Subject: [PATCH 20/27] Remove the non prefix validation options from Options. The other generation options never were in the Options structure and ImportWriter was the only thing that needed some the non validation options and it already required directly passing the options. So refine Options to just be validation options and bundle all the File related generation options into a new FileGenerator specific GenerationOptions. --- .../compiler/objectivec/objectivec_file.cc | 22 ++++++++++--------- .../compiler/objectivec/objectivec_file.h | 14 ++++++++---- .../objectivec/objectivec_generator.cc | 13 ++++++----- .../compiler/objectivec/objectivec_helpers.cc | 8 +++---- .../compiler/objectivec/objectivec_helpers.h | 6 ++--- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 0b4f4fa291..e11ca0e245 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -185,11 +186,12 @@ bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) { } // namespace -FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) +FileGenerator::FileGenerator(const FileDescriptor* file, + const GenerationOptions& generation_options) : file_(file), + generation_options_(generation_options), root_class_name_(FileClassName(file)), - is_bundled_proto_(IsProtobufLibraryBundledProtoFile(file)), - options_(options) { + is_bundled_proto_(IsProtobufLibraryBundledProtoFile(file)) { for (int i = 0; i < file_->enum_type_count(); i++) { EnumGenerator* generator = new EnumGenerator(file_->enum_type(i)); enum_generators_.emplace_back(generator); @@ -240,9 +242,9 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // #import any headers for "public imports" in the proto file. { ImportWriter import_writer( - options_.generate_for_named_framework, - options_.named_framework_to_proto_path_mappings_path, - options_.runtime_import_prefix, + generation_options_.generate_for_named_framework, + generation_options_.named_framework_to_proto_path_mappings_path, + generation_options_.runtime_import_prefix, is_bundled_proto_); const std::string header_extension(kHeaderExtension); for (int i = 0; i < file_->public_dependency_count(); i++) { @@ -354,9 +356,9 @@ void FileGenerator::GenerateSource(io::Printer* printer) { { ImportWriter import_writer( - options_.generate_for_named_framework, - options_.named_framework_to_proto_path_mappings_path, - options_.runtime_import_prefix, + generation_options_.generate_for_named_framework, + generation_options_.named_framework_to_proto_path_mappings_path, + generation_options_.runtime_import_prefix, is_bundled_proto_); const std::string header_extension(kHeaderExtension); @@ -600,7 +602,7 @@ void FileGenerator::PrintFileRuntimePreamble( "\n", "filename", file_->name()); ImportWriter::PrintRuntimeImports( - printer, headers_to_import, options_.runtime_import_prefix, true); + printer, headers_to_import, generation_options_.runtime_import_prefix, true); printer->Print("\n"); } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index 87258a39fe..fc71c70c9d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -49,7 +48,15 @@ class MessageGenerator; class FileGenerator { public: - FileGenerator(const FileDescriptor* file, const Options& options); + struct GenerationOptions { + GenerationOptions() {} + std::string generate_for_named_framework; + std::string named_framework_to_proto_path_mappings_path; + std::string runtime_import_prefix; + }; + + FileGenerator(const FileDescriptor* file, + const GenerationOptions& generation_options); ~FileGenerator(); FileGenerator(const FileGenerator&) = delete; @@ -60,6 +67,7 @@ class FileGenerator { private: const FileDescriptor* file_; + const GenerationOptions& generation_options_; std::string root_class_name_; bool is_bundled_proto_; @@ -67,8 +75,6 @@ class FileGenerator { std::vector> message_generators_; std::vector> extension_generators_; - const Options options_; - void PrintFileRuntimePreamble( io::Printer* printer, const std::vector& headers_to_import) const; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 9e9bbfd4f9..e0279a1d2e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -94,7 +94,8 @@ bool ObjectiveCGenerator::GenerateAll( // // e.g. protoc ... --objc_opt=expected_prefixes=file.txt,generate_for_named_framework=MyFramework - Options generation_options; + Options validation_options; + FileGenerator::GenerationOptions generation_options; std::vector > options; ParseGeneratorParameter(parameter, &options); @@ -116,14 +117,14 @@ bool ObjectiveCGenerator::GenerateAll( // // There is no validation that the prefixes are good prefixes, it is // assumed that they are when you create the file. - generation_options.expected_prefixes_path = options[i].second; + validation_options.expected_prefixes_path = options[i].second; } else if (options[i].first == "expected_prefixes_suppressions") { // A semicolon delimited string that lists the paths of .proto files to // exclude from the package prefix validations (expected_prefixes_path). // This is provided as an "out", to skip some files being checked. for (StringPiece split_piece : Split( options[i].second, ";", true)) { - generation_options.expected_prefixes_suppressions.push_back( + validation_options.expected_prefixes_suppressions.push_back( std::string(split_piece)); } } else if (options[i].first == "prefixes_must_be_registered") { @@ -135,7 +136,7 @@ bool ObjectiveCGenerator::GenerateAll( // tried to use a prefix that isn't registered. // Default is "no". if (!StringToBool(options[i].second, - &generation_options.prefixes_must_be_registered)) { + &validation_options.prefixes_must_be_registered)) { *error = "error: Unknown value for prefixes_must_be_registered: " + options[i].second; return false; } @@ -147,7 +148,7 @@ bool ObjectiveCGenerator::GenerateAll( // raised if a files doesn't have one. // Default is "no". if (!StringToBool(options[i].second, - &generation_options.require_prefixes)) { + &validation_options.require_prefixes)) { *error = "error: Unknown value for require_prefixes: " + options[i].second; return false; } @@ -258,7 +259,7 @@ bool ObjectiveCGenerator::GenerateAll( // ----------------------------------------------------------------- // Validate the objc prefix/package pairings. - if (!ValidateObjCClassPrefixes(files, generation_options, error)) { + if (!ValidateObjCClassPrefixes(files, validation_options, error)) { // *error will have been filled in. return false; } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index b085d0283c..696ea2cc6d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -1298,16 +1298,16 @@ bool PackageToPrefixesCollector::ConsumeLine( return true; } -bool LoadExpectedPackagePrefixes(const Options& generation_options, +bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, std::map* prefix_map, std::string* out_error) { - if (generation_options.expected_prefixes_path.empty()) { + if (expected_prefixes_path.empty()) { return true; } PackageToPrefixesCollector collector("Expected prefixes", prefix_map); return ParseSimpleFile( - generation_options.expected_prefixes_path, &collector, out_error); + expected_prefixes_path, &collector, out_error); } bool ValidateObjCClassPrefix( @@ -1465,7 +1465,7 @@ bool ValidateObjCClassPrefixes(const std::vector& files, // Load the expected package prefixes, if available, to validate against. std::map expected_package_prefixes; - if (!LoadExpectedPackagePrefixes(generation_options, + if (!LoadExpectedPackagePrefixes(generation_options.expected_prefixes_path, &expected_package_prefixes, out_error)) { return false; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index d67ec04eba..490cb02b9e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -64,14 +64,12 @@ std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList(); void PROTOC_EXPORT SetProtoPackagePrefixExceptionList( const std::string& file_path); -// Generator options (see objectivec_generator.cc for a description of each): +// Generator Prefix Validation Options (see objectivec_generator.cc for a +// description of each): struct Options { Options(); std::string expected_prefixes_path; std::vector expected_prefixes_suppressions; - std::string generate_for_named_framework; - std::string named_framework_to_proto_path_mappings_path; - std::string runtime_import_prefix; bool prefixes_must_be_registered; bool require_prefixes; }; From 76ba220c38ecb4025f72ac307524973ad9161672 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 28 Feb 2022 17:17:11 -0500 Subject: [PATCH 21/27] And an overload for ValidateObjCClassPrefixes(). This version defaults all the options, so folks don't have to pass it. Since Options never had a PROTOC_EXPORT, it isn't immediately clear how well the existing api worked for any shared lib cases, so this should give a simpler api for the basic usage (if anyone wants to use it). --- .../protobuf/compiler/objectivec/objectivec_helpers.cc | 7 +++++++ .../protobuf/compiler/objectivec/objectivec_helpers.h | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 696ea2cc6d..b15f580954 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -1454,6 +1454,13 @@ bool ValidateObjCClassPrefix( } // namespace +bool ValidateObjCClassPrefixes(const std::vector& files, + std::string* out_error) { + // Options's ctor load from the environment. + Options options; + return ValidateObjCClassPrefixes(files, options, out_error); +} + bool ValidateObjCClassPrefixes(const std::vector& files, const Options& generation_options, std::string* out_error) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 490cb02b9e..d21fed215a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -253,7 +253,11 @@ IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); // and the result is false. bool PROTOC_EXPORT ValidateObjCClassPrefixes( const std::vector& files, - const Options& generation_options, std::string* out_error); + const Options& validation_options, std::string* out_error); +// Same was the other ValidateObjCClassPrefixes() calls, but the options all +// come from the environment variables. +bool PROTOC_EXPORT ValidateObjCClassPrefixes( + const std::vector& files, std::string* out_error); // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform // the input into the expected output. From 020e4e33d179db705433ac41fa747a2cd7882296 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 1 Mar 2022 14:16:50 -0500 Subject: [PATCH 22/27] Simplify imports of the WKTs within the library itself. Overdue followup to https://github.com/protocolbuffers/protobuf/pull/7173 Since all the files are at the same level as the runtime headers, there is no need for things to be framework based imports, they should all just work like the other headers do. - Directly generate the bundled header imports into the preamble section when generating for a bundled proto. - Update the preamble generation to skip the CPP wrapper when generating for a bundled proto file. - Regenerate the WKTs. - Update GPBProtocolBuffer.h/GPBWellKnownTypes.h to also skip the CPP wrapping. GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS in the podspec and non bundled files still has to exist because that comes into play for those files to find the runtime headers. --- objectivec/GPBAny.pbobjc.h | 18 ++------- objectivec/GPBAny.pbobjc.m | 20 ++-------- objectivec/GPBApi.pbobjc.h | 18 ++------- objectivec/GPBApi.pbobjc.m | 26 +++---------- objectivec/GPBDuration.pbobjc.h | 18 ++------- objectivec/GPBDuration.pbobjc.m | 20 ++-------- objectivec/GPBEmpty.pbobjc.h | 18 ++------- objectivec/GPBEmpty.pbobjc.m | 20 ++-------- objectivec/GPBFieldMask.pbobjc.h | 18 ++------- objectivec/GPBFieldMask.pbobjc.m | 20 ++-------- objectivec/GPBProtocolBuffers.h | 39 +++++-------------- objectivec/GPBSourceContext.pbobjc.h | 18 ++------- objectivec/GPBSourceContext.pbobjc.m | 20 ++-------- objectivec/GPBStruct.pbobjc.h | 18 ++------- objectivec/GPBStruct.pbobjc.m | 18 +-------- objectivec/GPBTimestamp.pbobjc.h | 18 ++------- objectivec/GPBTimestamp.pbobjc.m | 20 ++-------- objectivec/GPBType.pbobjc.h | 18 ++------- objectivec/GPBType.pbobjc.m | 24 ++---------- objectivec/GPBWellKnownTypes.h | 18 ++------- objectivec/GPBWrappers.pbobjc.h | 18 ++------- objectivec/GPBWrappers.pbobjc.m | 20 ++-------- .../compiler/objectivec/objectivec_file.cc | 36 ++++++++++++++--- 23 files changed, 106 insertions(+), 375 deletions(-) diff --git a/objectivec/GPBAny.pbobjc.h b/objectivec/GPBAny.pbobjc.h index 5ed3f2ee68..7fb4129b13 100644 --- a/objectivec/GPBAny.pbobjc.h +++ b/objectivec/GPBAny.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBAny.pbobjc.m b/objectivec/GPBAny.pbobjc.m index a5143f15dc..7632c8c279 100644 --- a/objectivec/GPBAny.pbobjc.m +++ b/objectivec/GPBAny.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBAny.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBAny.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBApi.pbobjc.h b/objectivec/GPBApi.pbobjc.h index 5d55ebf399..1634a9212e 100644 --- a/objectivec/GPBApi.pbobjc.h +++ b/objectivec/GPBApi.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBApi.pbobjc.m b/objectivec/GPBApi.pbobjc.m index 5915ce1122..639462b19d 100644 --- a/objectivec/GPBApi.pbobjc.m +++ b/objectivec/GPBApi.pbobjc.m @@ -1,27 +1,11 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBApi.pbobjc.h" - #import "GPBSourceContext.pbobjc.h" - #import "GPBType.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBApi.pbobjc.h" +#import "GPBSourceContext.pbobjc.h" +#import "GPBType.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBDuration.pbobjc.h b/objectivec/GPBDuration.pbobjc.h index 88527f520d..d6236b07f3 100644 --- a/objectivec/GPBDuration.pbobjc.h +++ b/objectivec/GPBDuration.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBDuration.pbobjc.m b/objectivec/GPBDuration.pbobjc.m index d3cc7e31ca..11ba5e5f7b 100644 --- a/objectivec/GPBDuration.pbobjc.m +++ b/objectivec/GPBDuration.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBDuration.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBDuration.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBEmpty.pbobjc.h b/objectivec/GPBEmpty.pbobjc.h index 45600ead86..8a31c04ff5 100644 --- a/objectivec/GPBEmpty.pbobjc.h +++ b/objectivec/GPBEmpty.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBEmpty.pbobjc.m b/objectivec/GPBEmpty.pbobjc.m index df3e398170..8aefddb5b4 100644 --- a/objectivec/GPBEmpty.pbobjc.m +++ b/objectivec/GPBEmpty.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBEmpty.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBEmpty.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBFieldMask.pbobjc.h b/objectivec/GPBFieldMask.pbobjc.h index 3028b775dc..c4667b44db 100644 --- a/objectivec/GPBFieldMask.pbobjc.h +++ b/objectivec/GPBFieldMask.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBFieldMask.pbobjc.m b/objectivec/GPBFieldMask.pbobjc.m index 3605f89d80..ab25d3f9b1 100644 --- a/objectivec/GPBFieldMask.pbobjc.m +++ b/objectivec/GPBFieldMask.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBFieldMask.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBFieldMask.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBProtocolBuffers.h b/objectivec/GPBProtocolBuffers.h index c5df916396..619c08228b 100644 --- a/objectivec/GPBProtocolBuffers.h +++ b/objectivec/GPBProtocolBuffers.h @@ -44,33 +44,14 @@ #import "GPBWellKnownTypes.h" #import "GPBWireFormat.h" -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - // Well-known proto types -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import - #import - #import - #import - #import - #import - #import - #import -#else - #import "GPBAny.pbobjc.h" - #import "GPBApi.pbobjc.h" - #import "GPBDuration.pbobjc.h" - #import "GPBEmpty.pbobjc.h" - #import "GPBFieldMask.pbobjc.h" - #import "GPBSourceContext.pbobjc.h" - #import "GPBStruct.pbobjc.h" - #import "GPBTimestamp.pbobjc.h" - #import "GPBType.pbobjc.h" - #import "GPBWrappers.pbobjc.h" -#endif +#import "GPBAny.pbobjc.h" +#import "GPBApi.pbobjc.h" +#import "GPBDuration.pbobjc.h" +#import "GPBEmpty.pbobjc.h" +#import "GPBFieldMask.pbobjc.h" +#import "GPBSourceContext.pbobjc.h" +#import "GPBStruct.pbobjc.h" +#import "GPBTimestamp.pbobjc.h" +#import "GPBType.pbobjc.h" +#import "GPBWrappers.pbobjc.h" diff --git a/objectivec/GPBSourceContext.pbobjc.h b/objectivec/GPBSourceContext.pbobjc.h index 7a103362b5..b17fec0b78 100644 --- a/objectivec/GPBSourceContext.pbobjc.h +++ b/objectivec/GPBSourceContext.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBSourceContext.pbobjc.m b/objectivec/GPBSourceContext.pbobjc.m index b3e6fa759c..376d4421de 100644 --- a/objectivec/GPBSourceContext.pbobjc.m +++ b/objectivec/GPBSourceContext.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBSourceContext.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBSourceContext.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBStruct.pbobjc.h b/objectivec/GPBStruct.pbobjc.h index abdd6c82be..dd6ab28f0e 100644 --- a/objectivec/GPBStruct.pbobjc.h +++ b/objectivec/GPBStruct.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBStruct.pbobjc.m b/objectivec/GPBStruct.pbobjc.m index 554046a9fe..726cfb860e 100644 --- a/objectivec/GPBStruct.pbobjc.m +++ b/objectivec/GPBStruct.pbobjc.m @@ -1,25 +1,11 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBStruct.pbobjc.h" #import -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBStruct.pbobjc.h" -#endif // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBTimestamp.pbobjc.h b/objectivec/GPBTimestamp.pbobjc.h index a328afc7c9..8203383bdd 100644 --- a/objectivec/GPBTimestamp.pbobjc.h +++ b/objectivec/GPBTimestamp.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBTimestamp.pbobjc.m b/objectivec/GPBTimestamp.pbobjc.m index 736a75d19f..72d348f42a 100644 --- a/objectivec/GPBTimestamp.pbobjc.m +++ b/objectivec/GPBTimestamp.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBTimestamp.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBTimestamp.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBType.pbobjc.h b/objectivec/GPBType.pbobjc.h index 747e15d455..ee02b0a683 100644 --- a/objectivec/GPBType.pbobjc.h +++ b/objectivec/GPBType.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBType.pbobjc.m b/objectivec/GPBType.pbobjc.m index 70dae31c68..556df19711 100644 --- a/objectivec/GPBType.pbobjc.m +++ b/objectivec/GPBType.pbobjc.m @@ -1,29 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBType.pbobjc.h" +#import "GPBAny.pbobjc.h" +#import "GPBSourceContext.pbobjc.h" #import -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBType.pbobjc.h" - #import "GPBAny.pbobjc.h" - #import "GPBSourceContext.pbobjc.h" -#endif // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/objectivec/GPBWellKnownTypes.h b/objectivec/GPBWellKnownTypes.h index 784ba9ff99..80d9db00e9 100644 --- a/objectivec/GPBWellKnownTypes.h +++ b/objectivec/GPBWellKnownTypes.h @@ -30,21 +30,9 @@ #import -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBAny.pbobjc.h" - #import "GPBDuration.pbobjc.h" - #import "GPBTimestamp.pbobjc.h" -#endif +#import "GPBAny.pbobjc.h" +#import "GPBDuration.pbobjc.h" +#import "GPBTimestamp.pbobjc.h" NS_ASSUME_NONNULL_BEGIN diff --git a/objectivec/GPBWrappers.pbobjc.h b/objectivec/GPBWrappers.pbobjc.h index 713bafc89b..e6741ae120 100644 --- a/objectivec/GPBWrappers.pbobjc.h +++ b/objectivec/GPBWrappers.pbobjc.h @@ -1,21 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import - #import - #import -#else - #import "GPBDescriptor.h" - #import "GPBMessage.h" - #import "GPBRootObject.h" -#endif +#import "GPBDescriptor.h" +#import "GPBMessage.h" +#import "GPBRootObject.h" #if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. diff --git a/objectivec/GPBWrappers.pbobjc.m b/objectivec/GPBWrappers.pbobjc.m index 32201d4d83..b02a0716e2 100644 --- a/objectivec/GPBWrappers.pbobjc.m +++ b/objectivec/GPBWrappers.pbobjc.m @@ -1,23 +1,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// This CPP symbol can be defined to use imports that match up to the framework -// imports needed when using CocoaPods. -#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) - #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBProtocolBuffers_RuntimeSupport.h" -#endif - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS - #import -#else - #import "GPBWrappers.pbobjc.h" -#endif +#import "GPBProtocolBuffers_RuntimeSupport.h" +#import "GPBWrappers.pbobjc.h" + // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index e11ca0e245..163639701d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -245,7 +245,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { generation_options_.generate_for_named_framework, generation_options_.named_framework_to_proto_path_mappings_path, generation_options_.runtime_import_prefix, - is_bundled_proto_); + /* include_wkt_imports = */ false); const std::string header_extension(kHeaderExtension); for (int i = 0; i < file_->public_dependency_count(); i++) { import_writer.AddFile(file_->public_dependency(i), header_extension); @@ -340,8 +340,17 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { void FileGenerator::GenerateSource(io::Printer* printer) { // #import the runtime support. + const std::string header_extension(kHeaderExtension); std::vector headers; headers.push_back("GPBProtocolBuffers_RuntimeSupport.h"); + if (is_bundled_proto_) { + headers.push_back("GPB" + FilePathBasename(file_) + header_extension); + for (int i = 0; i < file_->dependency_count(); i++) { + const std::string header_name = + "GPB" + FilePathBasename(file_->dependency(i)) + header_extension; + headers.push_back(header_name); + } + } PrintFileRuntimePreamble(printer, headers); // Enums use atomic in the generated code, so add the system import as needed. @@ -359,8 +368,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { generation_options_.generate_for_named_framework, generation_options_.named_framework_to_proto_path_mappings_path, generation_options_.runtime_import_prefix, - is_bundled_proto_); - const std::string header_extension(kHeaderExtension); + /* include_wkt_imports = */ false); // #import the header for this proto file. import_writer.AddFile(file_, header_extension); @@ -601,8 +609,26 @@ void FileGenerator::PrintFileRuntimePreamble( "// source: $filename$\n" "\n", "filename", file_->name()); - ImportWriter::PrintRuntimeImports( - printer, headers_to_import, generation_options_.runtime_import_prefix, true); + + if (is_bundled_proto_) { + // This is basically a clone of ImportWriter::PrintRuntimeImports() but + // without the CPP symbol gate, since within the bundled files, that isn't + // needed. + std::string import_prefix = generation_options_.runtime_import_prefix; + if (!import_prefix.empty()) { + import_prefix += "/"; + } + for (const auto& header : headers_to_import) { + printer->Print( + "#import \"$import_prefix$$header$\"\n", + "import_prefix", import_prefix, + "header", header); + } + } else { + ImportWriter::PrintRuntimeImports( + printer, headers_to_import, generation_options_.runtime_import_prefix, true); + } + printer->Print("\n"); } From 1d13b60904eaeb08d35cc3f84a3801ef7381a64f Mon Sep 17 00:00:00 2001 From: Arfrever Date: Wed, 2 Mar 2022 02:06:14 +0100 Subject: [PATCH 23/27] cmake: Use linker version scripts (#9545) Autotools build system already uses linker version scripts since commit 13d165de9e737cec750a2ab3d1ef68bb3f276c48. Fixes: #6113 --- cmake/CMakeLists.txt | 28 ++++++++++++++++++++++++++-- cmake/libprotobuf-lite.cmake | 5 +++++ cmake/libprotobuf.cmake | 5 +++++ cmake/libprotoc.cmake | 5 +++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2366d4b427..7315733614 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,5 +1,5 @@ # Minimum CMake required -cmake_minimum_required(VERSION 3.1.3) +cmake_minimum_required(VERSION 3.10) if(protobuf_VERBOSE) message(STATUS "Protocol Buffers Configuring...") @@ -127,6 +127,30 @@ if (protobuf_DISABLE_RTTI) add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1) endif() +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map +"{ + global: + main; + local: + *; +};") +# CheckLinkerFlag module available in CMake >=3.18. +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18) + include(CheckLinkerFlag) + check_linker_flag(CXX -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map protobuf_HAVE_LD_VERSION_SCRIPT) +else() + include(CheckCXXSourceCompiles) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map) + check_cxx_source_compiles(" + int main() { + return 0; + } + " protobuf_HAVE_LD_VERSION_SCRIPT) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endif() +file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map) + find_package(Threads REQUIRED) set(_protobuf_FIND_ZLIB) @@ -182,7 +206,7 @@ else (protobuf_BUILD_SHARED_LIBS) # Prior to CMake 3.15, the MSVC runtime library was pushed into the same flags # making programmatic control difficult. Prefer the functionality in newer # CMake versions when available. - if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15) + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.15) if (protobuf_MSVC_STATIC_RUNTIME) set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>) else() diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index b915f1f1d9..6cc547e4b8 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -93,6 +93,11 @@ endif() add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC} ${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${libprotobuf_lite_rc_files}) +if(protobuf_HAVE_LD_VERSION_SCRIPT) + target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf-lite.map) + set_target_properties(libprotobuf-lite PROPERTIES + LINK_DEPENDS ${protobuf_source_dir}/src/libprotobuf-lite.map) +endif() target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT}) if(protobuf_LINK_LIBATOMIC) target_link_libraries(libprotobuf-lite atomic) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index a9a0aef607..9e08ebfd2a 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -107,6 +107,11 @@ endif() add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${libprotobuf_rc_files}) +if(protobuf_HAVE_LD_VERSION_SCRIPT) + target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf.map) + set_target_properties(libprotobuf PROPERTIES + LINK_DEPENDS ${protobuf_source_dir}/src/libprotobuf.map) +endif() target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT}) if(protobuf_WITH_ZLIB) target_link_libraries(libprotobuf ${ZLIB_LIBRARIES}) diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 4b967b2a2d..317e4c2836 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -131,6 +131,11 @@ endif() add_library(libprotoc ${protobuf_SHARED_OR_STATIC} ${libprotoc_files} ${libprotoc_headers} ${libprotoc_rc_files}) +if(protobuf_HAVE_LD_VERSION_SCRIPT) + target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotoc.map) + set_target_properties(libprotoc PROPERTIES + LINK_DEPENDS ${protobuf_source_dir}/src/libprotoc.map) +endif() target_link_libraries(libprotoc libprotobuf) if(MSVC AND protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotoc From 23b2fe6e392eb71a9186740c97d849514a9dd41b Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 2 Mar 2022 17:44:18 +0000 Subject: [PATCH 24/27] Update CHANGES.txt --- CHANGES.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index d443caf3df..0385e5c9e9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -24,7 +24,8 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Fix comments for message set wire format. Kotlin - * Add orNull extensions for optional message fields in Kotlin. + * Add orNull extensions for optional message fields. + * Add orNull extensions to all proto3 message fields. Python * Fix type annotations of some Duration and Timestamp methods. @@ -90,6 +91,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Add missing overload for reference wrapped fields. * Add MergedDescriptorDatabase::FindAllFileNames() * RepeatedField now defines an iterator type instead of using a pointer. + * Remove obsolete macros GOOGLE_PROTOBUF_HAS_ONEOF and GOOGLE_PROTOBUF_HAS_ARENAS. 2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From f7232f2aa31125cafcb37fe8d130f1eac115710e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 2 Mar 2022 19:17:27 +0000 Subject: [PATCH 25/27] Replace EasyMock dependency with Mockito and re-pin Bazel deps --- java/core/BUILD | 4 +- java/core/pom.xml | 4 +- java/kotlin-lite/pom.xml | 4 +- java/kotlin/pom.xml | 4 +- java/lite/pom.xml | 4 +- java/pom.xml | 6 +- java/util/pom.xml | 4 +- maven_install.json | 130 ++++++++++++++++++++++----------------- protobuf_deps.bzl | 2 +- 9 files changed, 88 insertions(+), 74 deletions(-) diff --git a/java/core/BUILD b/java/core/BUILD index cf4ae7cd74..011fb1c7e1 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -281,7 +281,7 @@ junit_tests( "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", - "@maven//:org_easymock_easymock", + "@maven//:org_mockito_mockito_core", ], ) @@ -408,6 +408,6 @@ junit_tests( ":test_util_lite", "@maven//:com_google_truth_truth", "@maven//:junit_junit", - "@maven//:org_easymock_easymock", + "@maven//:org_mockito_mockito_core", ], ) diff --git a/java/core/pom.xml b/java/core/pom.xml index ce068ee684..07d88a0e61 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -23,8 +23,8 @@ test - org.easymock - easymock + org.mockito + mockito-core test diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 490fbb2bfe..0637e6fb2d 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -31,8 +31,8 @@ test - org.easymock - easymock + org.mockito + mockito-core test diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 0f6feb26c5..d78456bded 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -30,8 +30,8 @@ test - org.easymock - easymock + org.mockito + mockito-core test diff --git a/java/lite/pom.xml b/java/lite/pom.xml index c19d596868..ce1d807421 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -23,8 +23,8 @@ test - org.easymock - easymock + org.mockito + mockito-core test diff --git a/java/pom.xml b/java/pom.xml index e1025976c1..e11bfe2c5f 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -79,9 +79,9 @@ test - org.easymock - easymock - 3.2 + org.mockito + mockito-core + 4.3.1 test diff --git a/java/util/pom.xml b/java/util/pom.xml index 27c82be64b..82b5d0a87e 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -52,8 +52,8 @@ junit - org.easymock - easymock + org.mockito + mockito-core test diff --git a/maven_install.json b/maven_install.json index bce3e2b463..808e0130d8 100644 --- a/maven_install.json +++ b/maven_install.json @@ -1,25 +1,13 @@ { "dependency_tree": { "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", - "__INPUT_ARTIFACTS_HASH": 1634601905, - "__RESOLVED_ARTIFACTS_HASH": -143733866, + "__INPUT_ARTIFACTS_HASH": -1867950668, + "__RESOLVED_ARTIFACTS_HASH": 1254982283, "conflict_resolution": { "com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.5.1", "junit:junit:4.12": "junit:junit:4.13.2" }, "dependencies": [ - { - "coord": "cglib:cglib-nodep:2.2.2", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar", - "https://repo.maven.apache.org/maven2/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar" - ], - "sha256": "e78c7792e59554ed8a23d18a12e3a0d2f7a244217ecf89621477f63aec074f15", - "url": "https://repo1.maven.org/maven2/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar" - }, { "coord": "com.google.auto.value:auto-value-annotations:1.7.4", "dependencies": [], @@ -83,21 +71,21 @@ { "coord": "com.google.guava:guava-testlib:30.1.1-jre", "dependencies": [ - "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", - "com.google.j2objc:j2objc-annotations:1.3", "com.google.code.findbugs:jsr305:3.0.2", - "org.hamcrest:hamcrest-core:1.3", - "com.google.guava:guava:30.1.1-jre", - "com.google.guava:failureaccess:1.0.1", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:guava:30.1.1-jre", + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", "junit:junit:4.13.2", - "org.checkerframework:checker-qual:3.9.1" + "org.checkerframework:checker-qual:3.9.1", + "org.hamcrest:hamcrest-core:1.3" ], "directDependencies": [ - "com.google.j2objc:j2objc-annotations:1.3", "com.google.code.findbugs:jsr305:3.0.2", - "com.google.guava:guava:30.1.1-jre", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:guava:30.1.1-jre", + "com.google.j2objc:j2objc-annotations:1.3", "junit:junit:4.13.2", "org.checkerframework:checker-qual:3.9.1" ], @@ -112,19 +100,19 @@ { "coord": "com.google.guava:guava:30.1.1-jre", "dependencies": [ - "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", - "com.google.j2objc:j2objc-annotations:1.3", "com.google.code.findbugs:jsr305:3.0.2", - "com.google.guava:failureaccess:1.0.1", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", "org.checkerframework:checker-qual:3.9.1" ], "directDependencies": [ - "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", - "com.google.j2objc:j2objc-annotations:1.3", "com.google.code.findbugs:jsr305:3.0.2", - "com.google.guava:failureaccess:1.0.1", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", "org.checkerframework:checker-qual:3.9.1" ], "file": "v1/https/repo1.maven.org/maven2/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar", @@ -162,20 +150,20 @@ { "coord": "com.google.truth:truth:1.1.2", "dependencies": [ - "org.ow2.asm:asm:9.0", "com.google.auto.value:auto-value-annotations:1.7.4", - "com.google.guava:guava:30.1.1-jre", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:guava:30.1.1-jre", "junit:junit:4.13.2", - "org.checkerframework:checker-qual:3.9.1" + "org.checkerframework:checker-qual:3.9.1", + "org.ow2.asm:asm:9.0" ], "directDependencies": [ - "org.ow2.asm:asm:9.0", "com.google.auto.value:auto-value-annotations:1.7.4", - "com.google.guava:guava:30.1.1-jre", "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.guava:guava:30.1.1-jre", "junit:junit:4.13.2", - "org.checkerframework:checker-qual:3.9.1" + "org.checkerframework:checker-qual:3.9.1", + "org.ow2.asm:asm:9.0" ], "file": "v1/https/repo1.maven.org/maven2/com/google/truth/truth/1.1.2/truth-1.1.2.jar", "mirror_urls": [ @@ -201,6 +189,30 @@ "sha256": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3", "url": "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" }, + { + "coord": "net.bytebuddy:byte-buddy-agent:1.12.7", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.12.7/byte-buddy-agent-1.12.7.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.12.7/byte-buddy-agent-1.12.7.jar", + "https://repo.maven.apache.org/maven2/net/bytebuddy/byte-buddy-agent/1.12.7/byte-buddy-agent-1.12.7.jar" + ], + "sha256": "73d84bb6e8e8980e674d796a29063f510ceb527c6f8c912a08a13e236be05c71", + "url": "https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.12.7/byte-buddy-agent-1.12.7.jar" + }, + { + "coord": "net.bytebuddy:byte-buddy:1.12.7", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.12.7/byte-buddy-1.12.7.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.12.7/byte-buddy-1.12.7.jar", + "https://repo.maven.apache.org/maven2/net/bytebuddy/byte-buddy/1.12.7/byte-buddy-1.12.7.jar" + ], + "sha256": "d2e46555699e70361b5471a7e142f9c67855bba6907a285177ebd8ad973775d8", + "url": "https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.12.7/byte-buddy-1.12.7.jar" + }, { "coord": "org.checkerframework:checker-qual:3.9.1", "dependencies": [], @@ -213,24 +225,6 @@ "sha256": "ab0468b1ba35bb2ae45f61a60dc4960bd887660ab8f05113a662a7e675eae776", "url": "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.9.1/checker-qual-3.9.1.jar" }, - { - "coord": "org.easymock:easymock:3.2", - "dependencies": [ - "cglib:cglib-nodep:2.2.2", - "org.objenesis:objenesis:1.3" - ], - "directDependencies": [ - "cglib:cglib-nodep:2.2.2", - "org.objenesis:objenesis:1.3" - ], - "file": "v1/https/repo1.maven.org/maven2/org/easymock/easymock/3.2/easymock-3.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/easymock/easymock/3.2/easymock-3.2.jar", - "https://repo.maven.apache.org/maven2/org/easymock/easymock/3.2/easymock-3.2.jar" - ], - "sha256": "b3dd1cf5019f942d8cc2afad0aa6aef4b21532446fe90a6b68d567e3389763dd", - "url": "https://repo1.maven.org/maven2/org/easymock/easymock/3.2/easymock-3.2.jar" - }, { "coord": "org.hamcrest:hamcrest-core:1.3", "dependencies": [], @@ -244,16 +238,36 @@ "url": "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" }, { - "coord": "org.objenesis:objenesis:1.3", + "coord": "org.mockito:mockito-core:4.3.1", + "dependencies": [ + "net.bytebuddy:byte-buddy-agent:1.12.7", + "net.bytebuddy:byte-buddy:1.12.7", + "org.objenesis:objenesis:3.2" + ], + "directDependencies": [ + "net.bytebuddy:byte-buddy-agent:1.12.7", + "net.bytebuddy:byte-buddy:1.12.7", + "org.objenesis:objenesis:3.2" + ], + "file": "v1/https/repo1.maven.org/maven2/org/mockito/mockito-core/4.3.1/mockito-core-4.3.1.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/mockito/mockito-core/4.3.1/mockito-core-4.3.1.jar", + "https://repo.maven.apache.org/maven2/org/mockito/mockito-core/4.3.1/mockito-core-4.3.1.jar" + ], + "sha256": "148de2c6928365db29443ca12d35c930d9f481172b934fdd801d1cb1409ea83a", + "url": "https://repo1.maven.org/maven2/org/mockito/mockito-core/4.3.1/mockito-core-4.3.1.jar" + }, + { + "coord": "org.objenesis:objenesis:3.2", "dependencies": [], "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/org/objenesis/objenesis/1.3/objenesis-1.3.jar", + "file": "v1/https/repo1.maven.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar", "mirror_urls": [ - "https://repo1.maven.org/maven2/org/objenesis/objenesis/1.3/objenesis-1.3.jar", - "https://repo.maven.apache.org/maven2/org/objenesis/objenesis/1.3/objenesis-1.3.jar" + "https://repo1.maven.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar", + "https://repo.maven.apache.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar" ], - "sha256": "dd4ef3d3091063a4fec578cbb2bbe6c1f921c00091ba2993dcd9afd25ff9444a", - "url": "https://repo1.maven.org/maven2/org/objenesis/objenesis/1.3/objenesis-1.3.jar" + "sha256": "03d960bd5aef03c653eb000413ada15eb77cdd2b8e4448886edf5692805e35f3", + "url": "https://repo1.maven.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar" }, { "coord": "org.ow2.asm:asm:9.0", diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 27b8bee258..2bee1b763c 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -11,7 +11,7 @@ PROTOBUF_MAVEN_ARTIFACTS = [ "com.google.guava:guava-testlib:30.1.1-jre", "com.google.truth:truth:1.1.2", "junit:junit:4.12", - "org.easymock:easymock:3.2", + "org.mockito:mockito-core:4.3.1", ] def protobuf_deps(): From 1c51f9fb39fabe47486a3477b6960e5ca1a7bdd3 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 2 Mar 2022 20:50:28 +0000 Subject: [PATCH 26/27] Undo unintentional file list changes --- cmake/libprotobuf.cmake | 1 - src/Makefile.am | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 126321d1ff..9e08ebfd2a 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -90,7 +90,6 @@ set(libprotobuf_includes ${protobuf_source_dir}/src/google/protobuf/util/delimited_message_util.h ${protobuf_source_dir}/src/google/protobuf/util/field_comparator.h ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util.h - ${protobuf_source_dir}/src/google/protobuf/util/internal/json_escaping.h ${protobuf_source_dir}/src/google/protobuf/util/json_util.h ${protobuf_source_dir}/src/google/protobuf/util/message_differencer.h ${protobuf_source_dir}/src/google/protobuf/util/time_util.h diff --git a/src/Makefile.am b/src/Makefile.am index 3331482ffd..d53cf57420 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -172,7 +172,6 @@ nobase_include_HEADERS = \ google/protobuf/util/delimited_message_util.h \ google/protobuf/util/field_comparator.h \ google/protobuf/util/field_mask_util.h \ - google/protobuf/util/internal/json_escaping.h \ google/protobuf/util/json_util.h \ google/protobuf/util/message_differencer.h \ google/protobuf/util/time_util.h \ @@ -285,6 +284,7 @@ libprotobuf_la_SOURCES = \ google/protobuf/util/internal/field_mask_utility.cc \ google/protobuf/util/internal/field_mask_utility.h \ google/protobuf/util/internal/json_escaping.cc \ + google/protobuf/util/internal/json_escaping.h \ google/protobuf/util/internal/json_objectwriter.cc \ google/protobuf/util/internal/json_objectwriter.h \ google/protobuf/util/internal/json_stream_parser.cc \ @@ -803,6 +803,12 @@ protobuf_test_SOURCES = \ google/protobuf/util/delimited_message_util_test.cc \ google/protobuf/util/field_comparator_test.cc \ google/protobuf/util/field_mask_util_test.cc \ + google/protobuf/util/internal/default_value_objectwriter_test.cc \ + google/protobuf/util/internal/json_objectwriter_test.cc \ + google/protobuf/util/internal/json_stream_parser_test.cc \ + google/protobuf/util/internal/protostream_objectsource_test.cc \ + google/protobuf/util/internal/protostream_objectwriter_test.cc \ + google/protobuf/util/internal/type_info_test_helper.cc \ google/protobuf/util/json_util_test.cc \ google/protobuf/util/message_differencer_unittest.cc \ google/protobuf/util/time_util_test.cc \ From 5faa6123d1aeaf552112186d05f9f523007f0407 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 2 Mar 2022 20:54:57 +0000 Subject: [PATCH 27/27] Reimplement the type sorter to avoid a ICE in gcc 4.8.2. Thanks to @sbenzaquen for this fix. --- src/google/protobuf/descriptor.cc | 78 +++++++++++++++---------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 5be4fa6179..0524fd4622 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -162,47 +162,45 @@ constexpr size_t EffectiveAlignof() { return std::is_same::value ? 8 : alignof(T); } +template +using AppendIfAlign = + typename std::conditional() == align, void (*)(T..., U), + void (*)(T...)>::type; + // Metafunction to sort types in descending order of alignment. // Useful for the flat allocator to ensure proper alignment of all elements // without having to add padding. +// Instead of implementing a proper sort metafunction we just do a +// filter+merge, which is much simpler to write as a metafunction. +// We have a fixed set of alignments we can filter on. // For simplicity we use a function pointer as a type list. -struct TypeListSorter { - template - static auto AppendIfAlign(void (*)(T...)) -> - typename std::conditional() == align, - void (*)(T..., U), void (*)(T...)>::type { - return nullptr; - } - - template - static auto SortImpl(void (*)(), void (*)(T16...), void (*)(T8...), - void (*)(T4...), void (*)(T2...), void (*)(T1...)) - -> void (*)(T16..., T8..., T4..., T2..., T1...) { - return nullptr; - } - - template - static auto SortImpl(void (*)(T, Ts...), T16 p16, T8 p8, T4 p4, T2 p2, T1 p1) - -> decltype(Self::template SortImpl( - static_cast(nullptr), AppendIfAlign<16, T>(p16), - AppendIfAlign<8, T>(p8), AppendIfAlign<4, T>(p4), - AppendIfAlign<2, T>(p2), AppendIfAlign<1, T>(p1))) { - return nullptr; - } +template +struct TypeListSortImpl; + +template +struct TypeListSortImpl { + using type = void (*)(T16..., T8..., T4..., T2..., T1...); +}; - // Instead of implementing a proper sort metafunction we just do a - // filter+merge, which is much simpler to write as a metafunction. - // We have a fixed set of alignments we can filter on. - template - static auto SortByAlignment(void (*p)() = nullptr) - -> decltype(SortImpl(static_cast(nullptr), p, p, p, p, - p)) { - return nullptr; - } +template +struct TypeListSortImpl { + using type = typename TypeListSortImpl< + void (*)(Rest...), AppendIfAlign<16, First, T16...>, + AppendIfAlign<8, First, T8...>, AppendIfAlign<4, First, T4...>, + AppendIfAlign<2, First, T2...>, AppendIfAlign<1, First, T1...>>::type; }; +template +using SortByAlignment = + typename TypeListSortImpl::type; + template