diff --git a/protos_generator/BUILD b/protos_generator/BUILD index 276b2ce668..500fb1770a 100644 --- a/protos_generator/BUILD +++ b/protos_generator/BUILD @@ -69,11 +69,10 @@ cc_library( "//upbc:file_layout", "//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", - "@com_google_absl//absl/log:check", "@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 476924c2c5..a52271165e 100644 --- a/protos_generator/gen_utils.cc +++ b/protos_generator/gen_utils.cc @@ -31,11 +31,11 @@ #include "absl/strings/str_cat.h" // begin:google_only -// #include "absl/log/check.h" // #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 { @@ -44,9 +44,13 @@ namespace protobuf = ::google::protobuf; // begin:github_only #ifndef DCHECK #ifndef NDEBUG -#define DCHECK(condition) if(!(condition)) LOG(FATAL); +#define DCHECK(condition) \ + if (!(condition)) { \ + upbc::LogFatal("Failed DCHECK: ", #condition, "File: ", __FILE__, \ + ", Line: ", __LINE__); \ + } #else -#define DCHECK(condition) if(!(true || condition)) LOG(FATAL); +#define DCHECK(condition) if(!(true || condition)) ; #endif #endif // end:github_only @@ -162,7 +166,7 @@ std::string CppTypeInternal(const protobuf::FieldDescriptor* field, case protobuf::FieldDescriptor::CPPTYPE_STRING: return "absl::string_view"; default: - LOG(FATAL) << "Unexpected type: " << field->cpp_type(); + upbc::LogFatal("Unexpected type: ", field->cpp_type()); } } diff --git a/protos_generator/output.h b/protos_generator/output.h index ee4564e1a5..a281c840db 100644 --- a/protos_generator/output.h +++ b/protos_generator/output.h @@ -30,12 +30,11 @@ #include -#include "absl/base/log_severity.h" -#include "absl/log/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 { @@ -58,7 +57,7 @@ class Output { void Outdent() { Outdent(kIndentationSize); } void Outdent(size_t size) { if (indent_ < size) { - LOG(FATAL) << "mismatched Output indent/unindent calls"; + upbc::LogFatal("mismatched Output indent/unindent calls"); } indent_ -= size; } diff --git a/upbc/BUILD b/upbc/BUILD index 0b52c984ba..d9819cedc3 100644 --- a/upbc/BUILD +++ b/upbc/BUILD @@ -178,8 +178,6 @@ bootstrap_cc_library( deps = [ "//:port", "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", ], ) @@ -252,8 +250,6 @@ 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", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", ], ) diff --git a/upbc/plugin.h b/upbc/plugin.h index 7118ffa82c..6219795354 100644 --- a/upbc/plugin.h +++ b/upbc/plugin.h @@ -45,7 +45,6 @@ // end:github_only #include "absl/container/flat_hash_set.h" -#include "absl/log/log.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "upb/reflection/def.hpp" @@ -72,6 +71,12 @@ 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(); } @@ -113,8 +118,8 @@ class Plugin { if (!file) { absl::string_view name = ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); - LOG(FATAL) << "Couldn't add file " << name - << " to DefPool: " << status.error_message(); + LogFatal("Couldn't add file ", name, + " to DefPool: ", status.error_message()); } if (generate) func(file); }); @@ -169,7 +174,7 @@ class Plugin { request_ = UPB_DESC(compiler_CodeGeneratorRequest_parse)( data.data(), data.size(), arena_.ptr()); if (!request_) { - LOG(FATAL) << "Failed to parse CodeGeneratorRequest"; + LogFatal("Failed to parse CodeGeneratorRequest"); } response_ = UPB_DESC(compiler_CodeGeneratorResponse_new)(arena_.ptr()); UPB_DESC(compiler_CodeGeneratorResponse_set_supported_features) @@ -182,11 +187,11 @@ class Plugin { char* serialized = UPB_DESC(compiler_CodeGeneratorResponse_serialize)( response_, arena_.ptr(), &size); if (!serialized) { - LOG(FATAL) << "Failed to serialize CodeGeneratorResponse"; + LogFatal("Failed to serialize CodeGeneratorResponse"); } if (fwrite(serialized, 1, size, stdout) != size) { - LOG(FATAL) << "Failed to write response to stdout"; + LogFatal("Failed to write response to stdout"); } } }; diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 3b5f4d6da7..b7c2c63ef9 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -43,8 +43,6 @@ #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" -#include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -1262,7 +1260,7 @@ std::string FieldInitializer(upb::FieldDefPtr field, const upb_MiniTableField* field32, const Options& options) { if (options.bootstrap) { - CHECK(!field.is_extension()); + if (field.is_extension()) LogFatal("Should not be an extension"); return absl::Substitute( "*upb_MiniTable_FindFieldByNumber($0, $1)", MessageMiniTableRef(field.containing_type(), options), field.number()); @@ -1679,8 +1677,8 @@ int main(int argc, char** argv) { if (!file) { absl::string_view name = upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto)); - LOG(FATAL) << "Couldn't add file " << name - << " to DefPool: " << status.error_message(); + upbc::LogFatal("Couldn't add file ", name, + " to DefPool: ", status.error_message()); } if (generate) GenerateFile(pools, file, options, &plugin); });