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