diff --git a/protos_generator/BUILD b/protos_generator/BUILD index 500fb1770a..182465d644 100644 --- a/protos_generator/BUILD +++ b/protos_generator/BUILD @@ -70,9 +70,10 @@ cc_library( "//upbc:keywords", "//upbc:names", "//upbc:plugin", - "@com_google_absl//absl/base:log_severity", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", "@com_google_protobuf//src/google/protobuf/compiler:code_generator", diff --git a/protos_generator/gen_utils.cc b/protos_generator/gen_utils.cc index a52271165e..4ab3572b2e 100644 --- a/protos_generator/gen_utils.cc +++ b/protos_generator/gen_utils.cc @@ -29,32 +29,18 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" // begin:google_only // #include "absl/strings/str_replace.h" // end:google_only #include "absl/strings/str_split.h" #include "upbc/keywords.h" -#include "upbc/plugin.h" namespace protos_generator { namespace protobuf = ::google::protobuf; -// begin:github_only -#ifndef DCHECK -#ifndef NDEBUG -#define DCHECK(condition) \ - if (!(condition)) { \ - upbc::LogFatal("Failed DCHECK: ", #condition, "File: ", __FILE__, \ - ", Line: ", __LINE__); \ - } -#else -#define DCHECK(condition) if(!(true || condition)) ; -#endif -#endif -// end:github_only - std::string DotsToColons(const std::string& name) { return absl::StrReplaceAll(name, {{".", "::"}}); } @@ -166,7 +152,7 @@ std::string CppTypeInternal(const protobuf::FieldDescriptor* field, case protobuf::FieldDescriptor::CPPTYPE_STRING: return "absl::string_view"; default: - upbc::LogFatal("Unexpected type: ", field->cpp_type()); + ABSL_LOG(FATAL) << "Unexpected type: " << field->cpp_type(); } } @@ -182,14 +168,14 @@ std::string CppTypeParameterName(const protobuf::FieldDescriptor* field) { std::string MessageBaseType(const protobuf::FieldDescriptor* field, bool is_const) { - DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); + ABSL_DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); std::string maybe_const = is_const ? "const " : ""; return maybe_const + QualifiedClassName(field->message_type()); } std::string MessagePtrConstType(const protobuf::FieldDescriptor* field, bool is_const) { - DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); + ABSL_DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); std::string maybe_const = is_const ? "const " : ""; return "::protos::Ptr<" + maybe_const + QualifiedClassName(field->message_type()) + ">"; @@ -197,7 +183,7 @@ std::string MessagePtrConstType(const protobuf::FieldDescriptor* field, std::string MessageCProxyType(const protobuf::FieldDescriptor* field, bool is_const) { - DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); + ABSL_DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); std::string maybe_const = is_const ? "const " : ""; return maybe_const + QualifiedInternalClassName(field->message_type()) + "CProxy"; @@ -205,7 +191,7 @@ std::string MessageCProxyType(const protobuf::FieldDescriptor* field, std::string MessageProxyType(const protobuf::FieldDescriptor* field, bool is_const) { - DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); + ABSL_DCHECK(field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE); std::string maybe_const = is_const ? "const " : ""; return maybe_const + QualifiedInternalClassName(field->message_type()) + "Proxy"; diff --git a/protos_generator/output.h b/protos_generator/output.h index a281c840db..d0f765321a 100644 --- a/protos_generator/output.h +++ b/protos_generator/output.h @@ -30,11 +30,11 @@ #include +#include "absl/log/absl_log.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/zero_copy_stream.h" -#include "upbc/plugin.h" namespace protos_generator { @@ -57,7 +57,7 @@ class Output { void Outdent() { Outdent(kIndentationSize); } void Outdent(size_t size) { if (indent_ < size) { - upbc::LogFatal("mismatched Output indent/unindent calls"); + ABSL_LOG(FATAL) << "mismatched Output indent/unindent calls"; } indent_ -= size; } diff --git a/upbc/BUILD b/upbc/BUILD index d9819cedc3..d95d4175d7 100644 --- a/upbc/BUILD +++ b/upbc/BUILD @@ -178,6 +178,8 @@ bootstrap_cc_library( deps = [ "//:port", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) @@ -250,6 +252,8 @@ bootstrap_cc_binary( "//:wire_types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) @@ -293,6 +297,7 @@ cc_binary( ":plugin_upb_proto", ":upbdev", "//:port", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) diff --git a/upbc/plugin.h b/upbc/plugin.h index 6219795354..a3ec1d93c2 100644 --- a/upbc/plugin.h +++ b/upbc/plugin.h @@ -45,6 +45,7 @@ // end:github_only #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "upb/reflection/def.hpp" @@ -71,12 +72,6 @@ inline std::vector> ParseGeneratorParameter( return ret; } -template -void LogFatal(const Arg&... arg) { - fprintf(stderr, "FATAL ERROR: %s\n", absl::StrCat(arg...).c_str()); - exit(1); -} - class Plugin { public: Plugin() { ReadRequest(); } @@ -118,8 +113,8 @@ class Plugin { if (!file) { absl::string_view name = ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); - LogFatal("Couldn't add file ", name, - " to DefPool: ", status.error_message()); + ABSL_LOG(FATAL) << "Couldn't add file " << name + << " to DefPool: " << status.error_message(); } if (generate) func(file); }); @@ -174,7 +169,7 @@ class Plugin { request_ = UPB_DESC(compiler_CodeGeneratorRequest_parse)( data.data(), data.size(), arena_.ptr()); if (!request_) { - LogFatal("Failed to parse CodeGeneratorRequest"); + ABSL_LOG(FATAL) << "Failed to parse CodeGeneratorRequest"; } response_ = UPB_DESC(compiler_CodeGeneratorResponse_new)(arena_.ptr()); UPB_DESC(compiler_CodeGeneratorResponse_set_supported_features) @@ -187,11 +182,11 @@ class Plugin { char* serialized = UPB_DESC(compiler_CodeGeneratorResponse_serialize)( response_, arena_.ptr(), &size); if (!serialized) { - LogFatal("Failed to serialize CodeGeneratorResponse"); + ABSL_LOG(FATAL) << "Failed to serialize CodeGeneratorResponse"; } if (fwrite(serialized, 1, size, stdout) != size) { - LogFatal("Failed to write response to stdout"); + ABSL_LOG(FATAL) << "Failed to write response to stdout"; } } }; diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 5a8308a373..430d624d58 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -43,6 +43,8 @@ #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -1259,7 +1261,7 @@ std::string FieldInitializer(upb::FieldDefPtr field, const upb_MiniTableField* field32, const Options& options) { if (options.bootstrap) { - if (field.is_extension()) LogFatal("Should not be an extension"); + ABSL_CHECK(!field.is_extension()); return absl::Substitute( "*upb_MiniTable_FindFieldByNumber($0, $1)", MessageMiniTableRef(field.containing_type(), options), field.number()); @@ -1679,8 +1681,8 @@ int main(int argc, char** argv) { if (!file) { absl::string_view name = upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); - upbc::LogFatal("Couldn't add file ", name, - " to DefPool: ", status.error_message()); + ABSL_LOG(FATAL) << "Couldn't add file " << name + << " to DefPool: " << status.error_message(); } if (generate) GenerateFile(pools, file, options, &plugin); }); diff --git a/upbc/subprocess.cc b/upbc/subprocess.cc index 9087d0faa9..08628b705e 100644 --- a/upbc/subprocess.cc +++ b/upbc/subprocess.cc @@ -41,6 +41,7 @@ #include #endif +#include "absl/log/absl_log.h" #include "absl/strings/substitute.h" // Must be last. @@ -62,8 +63,8 @@ char* portable_strdup(const char* s) { static void CloseHandleOrDie(HANDLE handle) { if (!CloseHandle(handle)) { - GOOGLE_LOG(FATAL) << "CloseHandle: " - << Subprocess::Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "CloseHandle: " + << Subprocess::Win32ErrorMessage(GetLastError()); } } @@ -90,22 +91,22 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { HANDLE stdout_pipe_write; if (!CreatePipe(&stdin_pipe_read, &stdin_pipe_write, nullptr, 0)) { - GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); } if (!CreatePipe(&stdout_pipe_read, &stdout_pipe_write, nullptr, 0)) { - GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); } // Make child side of the pipes inheritable. if (!SetHandleInformation(stdin_pipe_read, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) { - GOOGLE_LOG(FATAL) << "SetHandleInformation: " - << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "SetHandleInformation: " + << Win32ErrorMessage(GetLastError()); } if (!SetHandleInformation(stdout_pipe_write, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) { - GOOGLE_LOG(FATAL) << "SetHandleInformation: " - << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "SetHandleInformation: " + << Win32ErrorMessage(GetLastError()); } // Setup STARTUPINFO to redirect handles. @@ -118,7 +119,7 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); if (startup_info.hStdError == INVALID_HANDLE_VALUE) { - GOOGLE_LOG(FATAL) << "GetStdHandle: " << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "GetStdHandle: " << Win32ErrorMessage(GetLastError()); } // Invoking cmd.exe allows for '.bat' files from the path as well as '.exe'. @@ -184,11 +185,11 @@ bool Subprocess::Communicate(const std::string& input_data, wait_result < WAIT_OBJECT_0 + handle_count) { signaled_handle = handles[wait_result - WAIT_OBJECT_0]; } else if (wait_result == WAIT_FAILED) { - GOOGLE_LOG(FATAL) << "WaitForMultipleObjects: " - << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "WaitForMultipleObjects: " + << Win32ErrorMessage(GetLastError()); } else { - GOOGLE_LOG(FATAL) << "WaitForMultipleObjects: Unexpected return code: " - << wait_result; + ABSL_LOG(FATAL) << "WaitForMultipleObjects: Unexpected return code: " + << wait_result; } if (signaled_handle == child_stdin_) { @@ -231,17 +232,17 @@ bool Subprocess::Communicate(const std::string& input_data, DWORD wait_result = WaitForSingleObject(child_handle_, INFINITE); if (wait_result == WAIT_FAILED) { - GOOGLE_LOG(FATAL) << "WaitForSingleObject: " - << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "WaitForSingleObject: " + << Win32ErrorMessage(GetLastError()); } else if (wait_result != WAIT_OBJECT_0) { - GOOGLE_LOG(FATAL) << "WaitForSingleObject: Unexpected return code: " - << wait_result; + ABSL_LOG(FATAL) << "WaitForSingleObject: Unexpected return code: " + << wait_result; } DWORD exit_code; if (!GetExitCodeProcess(child_handle_, &exit_code)) { - GOOGLE_LOG(FATAL) << "GetExitCodeProcess: " - << Win32ErrorMessage(GetLastError()); + ABSL_LOG(FATAL) << "GetExitCodeProcess: " + << Win32ErrorMessage(GetLastError()); } CloseHandleOrDie(child_handle_);