diff options
author | Krzysztof Kosiński <krzysio@google.com> | 2024-03-20 00:24:01 +0000 |
---|---|---|
committer | Krzysztof Kosiński <krzysio@google.com> | 2024-03-20 00:24:01 +0000 |
commit | baef0010460f5fd46a3c7ac35dece5e8b876e922 (patch) | |
tree | 08eff208a348f16a5e87866f12dd1280da7168df | |
parent | bf900fa8fadc1c65748821342ffc6c1388fb7426 (diff) | |
download | generic-baef0010460f5fd46a3c7ac35dece5e8b876e922.tar.gz |
Replace Protobuf stubs with ABSL.
google/protobuf/stubs/strutil.h is removed in Protobuf 22.x
and replaced with a mandatory ABSL dependency.
Bug: 329747255
Test: unit test
Change-Id: I5b474e34d7a6b1fde1cb94bc50975790490b317a
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | libnos/generator/Android.bp | 5 | ||||
-rw-r--r-- | libnos/generator/main.cpp | 34 |
3 files changed, 20 insertions, 20 deletions
@@ -188,6 +188,7 @@ cc_defaults { "-Wall", "-Wextra", "-Werror", + "-Wno-gcc-compat", "-Wno-gnu-zero-variadic-macro-arguments", "-Wno-zero-length-array", ], diff --git a/libnos/generator/Android.bp b/libnos/generator/Android.bp index a7cc964..9e5a688 100644 --- a/libnos/generator/Android.bp +++ b/libnos/generator/Android.bp @@ -30,6 +30,9 @@ cc_binary_host { "nos_proto_defaults", "nos_cc_defaults", ], - static_libs: ["libnosprotos"], + static_libs: [ + "libabsl_host", + "libnosprotos", + ], shared_libs: ["libprotoc"], } diff --git a/libnos/generator/main.cpp b/libnos/generator/main.cpp index 25178c3..51acfa2 100644 --- a/libnos/generator/main.cpp +++ b/libnos/generator/main.cpp @@ -24,17 +24,16 @@ #include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> -#include <google/protobuf/stubs/strutil.h> +#include "absl/strings/strip.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" +#include "absl/strings/str_split.h" #include "nugget/protobuf/options.pb.h" using ::google::protobuf::FileDescriptor; -using ::google::protobuf::JoinStrings; using ::google::protobuf::MethodDescriptor; using ::google::protobuf::ServiceDescriptor; -using ::google::protobuf::Split; -using ::google::protobuf::SplitStringUsing; -using ::google::protobuf::StripSuffixString; using ::google::protobuf::compiler::CodeGenerator; using ::google::protobuf::compiler::OutputDirectory; using ::google::protobuf::io::Printer; @@ -61,8 +60,8 @@ std::string validateServiceOptions(const ServiceDescriptor& service) { template <typename Descriptor> std::vector<std::string> Packages(const Descriptor& descriptor) { - std::vector<std::string> namespaces; - SplitStringUsing(descriptor.full_name(), ".", &namespaces); + std::vector<std::string> namespaces = + absl::StrSplit(descriptor.full_name(), '.'); namespaces.pop_back(); // just take the package return namespaces; } @@ -73,23 +72,21 @@ std::string FullyQualifiedIdentifier(const Descriptor& descriptor) { if (namespaces.empty()) { return "::" + descriptor.name(); } else { - std::string namespace_path; - JoinStrings(namespaces, "::", &namespace_path); - return "::" + namespace_path + "::" + descriptor.name(); + return absl::StrCat("::", absl::StrJoin(namespaces, "::"), "::", descriptor.name()); } } template <typename Descriptor> std::string FullyQualifiedHeader(const Descriptor& descriptor) { - const auto packages = Packages(descriptor); - const auto file = Split(descriptor.file()->name(), "/").back(); - const auto header = StripSuffixString(file, ".proto") + ".pb.h"; + const std::vector<std::string> packages = Packages(descriptor); + const std::vector<std::string_view> path_components = + absl::StrSplit(descriptor.file()->name(), '/'); + const std::string file(path_components.back()); + const std::string header = absl::StrCat(absl::StripSuffix(file, ".proto"), ".pb.h"); if (packages.empty()) { return header; } else { - std::string package_path; - JoinStrings(packages, "/", &package_path); - return package_path + "/" + header; + return absl::StrCat(absl::StrJoin(packages, "/"), "/", header); } } @@ -270,6 +267,8 @@ uint32_t $class$::$method_name$(const $method_input_type$& request, $method_outp class CppNuggetServiceClientGenerator : public CodeGenerator { public: CppNuggetServiceClientGenerator() = default; + CppNuggetServiceClientGenerator(const CppNuggetServiceClientGenerator&) = delete; + CppNuggetServiceClientGenerator& operator=(const CppNuggetServiceClientGenerator&) = delete; ~CppNuggetServiceClientGenerator() override = default; bool Generate(const FileDescriptor* file, @@ -307,9 +306,6 @@ public: return true; } - -private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppNuggetServiceClientGenerator); }; } // namespace |