Internal changes

PiperOrigin-RevId: 494027305
pull/11220/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 308307050e
commit ac1fee677e
  1. 16
      src/google/protobuf/compiler/python/generator.cc
  2. 1
      src/google/protobuf/compiler/python/helpers.cc
  3. 7
      src/google/protobuf/compiler/python/plugin_unittest.cc
  4. 6
      src/google/protobuf/compiler/python/pyi_generator.cc

@ -51,9 +51,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/logging.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -168,7 +167,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) {
} }
// (We could add a default case above but then we wouldn't get the nice // (We could add a default case above but then we wouldn't get the nice
// compiler warning when a new type is added.) // compiler warning when a new type is added.)
GOOGLE_ABSL_LOG(FATAL) << "Not reached."; GOOGLE_LOG(FATAL) << "Not reached.";
return ""; return "";
} }
@ -180,8 +179,7 @@ std::string StringifySyntax(FileDescriptor::Syntax syntax) {
return "proto3"; return "proto3";
case FileDescriptor::SYNTAX_UNKNOWN: case FileDescriptor::SYNTAX_UNKNOWN:
default: default:
GOOGLE_ABSL_LOG(FATAL) GOOGLE_LOG(FATAL) << "Unsupported syntax; this generator only supports proto2 "
<< "Unsupported syntax; this generator only supports proto2 "
"and proto3 syntax."; "and proto3 syntax.";
return ""; return "";
} }
@ -292,7 +290,7 @@ bool Generator::Generate(const FileDescriptor* file,
} }
std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_ABSL_CHECK(output.get()); GOOGLE_CHECK(output.get());
io::Printer printer(output.get(), '$'); io::Printer printer(output.get(), '$');
printer_ = &printer; printer_ = &printer;
@ -949,7 +947,7 @@ std::string Generator::FieldReferencingExpression(
const std::string& python_dict_name) const { const std::string& python_dict_name) const {
// We should only ever be looking up fields in the current file. // We should only ever be looking up fields in the current file.
// The only things we refer to from other files are message descriptors. // The only things we refer to from other files are message descriptors.
GOOGLE_ABSL_CHECK_EQ(field.file(), file_) GOOGLE_CHECK_EQ(field.file(), file_)
<< field.file()->name() << " vs. " << file_->name(); << field.file()->name() << " vs. " << file_->name();
if (!containing_type) { if (!containing_type) {
return ResolveKeyword(field.name()); return ResolveKeyword(field.name());
@ -1015,7 +1013,7 @@ void Generator::FixForeignFieldsInExtensions() const {
void Generator::FixForeignFieldsInExtension( void Generator::FixForeignFieldsInExtension(
const FieldDescriptor& extension_field) const { const FieldDescriptor& extension_field) const {
GOOGLE_ABSL_CHECK(extension_field.is_extension()); GOOGLE_CHECK(extension_field.is_extension());
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
// Confusingly, for FieldDescriptors that happen to be extensions, // Confusingly, for FieldDescriptors that happen to be extensions,
@ -1230,7 +1228,7 @@ void Generator::PrintSerializedPbInterval(const DescriptorT& descriptor,
std::string sp; std::string sp;
proto.SerializeToString(&sp); proto.SerializeToString(&sp);
int offset = file_descriptor_serialized_.find(sp); int offset = file_descriptor_serialized_.find(sp);
GOOGLE_ABSL_CHECK_GE(offset, 0); GOOGLE_CHECK_GE(offset, 0);
printer_->Print( printer_->Print(
"_globals['$name$']._serialized_start=$serialized_start$\n" "_globals['$name$']._serialized_start=$serialized_start$\n"

@ -32,7 +32,6 @@
#include <algorithm> #include <algorithm>
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"

@ -39,7 +39,6 @@
#include "google/protobuf/compiler/python/generator.h" #include "google/protobuf/compiler/python/generator.h"
#include "google/protobuf/testing/googletest.h" #include "google/protobuf/testing/googletest.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/io/zero_copy_stream.h"
@ -79,7 +78,7 @@ class TestGenerator : public CodeGenerator {
TEST(PythonPluginTest, ImportTest) { TEST(PythonPluginTest, ImportTest) {
// Create files test1.proto and test2.proto with the former importing the // Create files test1.proto and test2.proto with the former importing the
// latter. // latter.
GOOGLE_ABSL_CHECK_OK(File::SetContents(TestTempDir() + "/test1.proto", GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test1.proto",
"syntax = \"proto3\";\n" "syntax = \"proto3\";\n"
"package foo;\n" "package foo;\n"
"import \"test2.proto\";" "import \"test2.proto\";"
@ -87,7 +86,7 @@ TEST(PythonPluginTest, ImportTest) {
" Message2 message_2 = 1;\n" " Message2 message_2 = 1;\n"
"}\n", "}\n",
true)); true));
GOOGLE_ABSL_CHECK_OK(File::SetContents(TestTempDir() + "/test2.proto", GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test2.proto",
"syntax = \"proto3\";\n" "syntax = \"proto3\";\n"
"package foo;\n" "package foo;\n"
"message Message2 {}\n", "message Message2 {}\n",
@ -106,7 +105,7 @@ TEST(PythonPluginTest, ImportTest) {
// Loop over the lines of the generated code and verify that we find an // Loop over the lines of the generated code and verify that we find an
// ordinary Python import but do not find the string "importlib". // ordinary Python import but do not find the string "importlib".
std::string output; std::string output;
GOOGLE_ABSL_CHECK_OK(File::GetContents(TestTempDir() + "/test1_pb2.py", &output, GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/test1_pb2.py", &output,
true)); true));
std::vector<std::string> lines = absl::StrSplit(output, "\n"); std::vector<std::string> lines = absl::StrSplit(output, "\n");
std::string expected_import = "import test2_pb2"; std::string expected_import = "import test2_pb2";

@ -34,8 +34,6 @@
#include <utility> #include <utility>
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
@ -386,7 +384,7 @@ std::string PyiGenerator::GetFieldType(
return name; return name;
} }
default: default:
GOOGLE_ABSL_LOG(FATAL) << "Unsupported field type."; GOOGLE_LOG(FATAL) << "Unsupported field type.";
} }
return ""; return "";
} }
@ -601,7 +599,7 @@ bool PyiGenerator::Generate(const FileDescriptor* file,
} }
std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_ABSL_CHECK(output.get()); GOOGLE_CHECK(output.get());
GeneratedCodeInfo annotations; GeneratedCodeInfo annotations;
io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
&annotations); &annotations);

Loading…
Cancel
Save