Removed upb dependencies on absl/log.

absl/log is not yet released in any ABSL LTS.

PiperOrigin-RevId: 503575398
pull/13171/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent a780ffae65
commit a1abf835d2
  1. 3
      protos_generator/BUILD
  2. 26
      protos_generator/gen_utils.cc
  3. 4
      protos_generator/output.h
  4. 5
      upbc/BUILD
  5. 17
      upbc/plugin.h
  6. 8
      upbc/protoc-gen-upb.cc
  7. 23
      upbc/subprocess.cc

@ -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",

@ -29,32 +29,18 @@
#include <string>
#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";

@ -30,11 +30,11 @@
#include <vector>
#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;
}

@ -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",
],
)

@ -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<std::pair<std::string, std::string>> ParseGeneratorParameter(
return ret;
}
template <class... Arg>
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";
}
}
};

@ -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);
});

@ -41,6 +41,7 @@
#include <sys/wait.h>
#endif
#include "absl/log/absl_log.h"
#include "absl/strings/substitute.h"
// Must be last.
@ -62,7 +63,7 @@ char* portable_strdup(const char* s) {
static void CloseHandleOrDie(HANDLE handle) {
if (!CloseHandle(handle)) {
GOOGLE_LOG(FATAL) << "CloseHandle: "
ABSL_LOG(FATAL) << "CloseHandle: "
<< Subprocess::Win32ErrorMessage(GetLastError());
}
}
@ -90,21 +91,21 @@ 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: "
ABSL_LOG(FATAL) << "SetHandleInformation: "
<< Win32ErrorMessage(GetLastError());
}
if (!SetHandleInformation(stdout_pipe_write, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT)) {
GOOGLE_LOG(FATAL) << "SetHandleInformation: "
ABSL_LOG(FATAL) << "SetHandleInformation: "
<< Win32ErrorMessage(GetLastError());
}
@ -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,10 +185,10 @@ 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: "
ABSL_LOG(FATAL) << "WaitForMultipleObjects: "
<< Win32ErrorMessage(GetLastError());
} else {
GOOGLE_LOG(FATAL) << "WaitForMultipleObjects: Unexpected return code: "
ABSL_LOG(FATAL) << "WaitForMultipleObjects: Unexpected return code: "
<< wait_result;
}
@ -231,16 +232,16 @@ bool Subprocess::Communicate(const std::string& input_data,
DWORD wait_result = WaitForSingleObject(child_handle_, INFINITE);
if (wait_result == WAIT_FAILED) {
GOOGLE_LOG(FATAL) << "WaitForSingleObject: "
ABSL_LOG(FATAL) << "WaitForSingleObject: "
<< Win32ErrorMessage(GetLastError());
} else if (wait_result != WAIT_OBJECT_0) {
GOOGLE_LOG(FATAL) << "WaitForSingleObject: Unexpected return code: "
ABSL_LOG(FATAL) << "WaitForSingleObject: Unexpected return code: "
<< wait_result;
}
DWORD exit_code;
if (!GetExitCodeProcess(child_handle_, &exit_code)) {
GOOGLE_LOG(FATAL) << "GetExitCodeProcess: "
ABSL_LOG(FATAL) << "GetExitCodeProcess: "
<< Win32ErrorMessage(GetLastError());
}

Loading…
Cancel
Save