Internal changes

PiperOrigin-RevId: 494875036
pull/11237/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent d7610a4a32
commit 2e0145b240
  1. 18
      src/google/protobuf/compiler/python/generator.cc
  2. 1
      src/google/protobuf/compiler/python/helpers.cc
  3. 31
      src/google/protobuf/compiler/python/plugin_unittest.cc
  4. 6
      src/google/protobuf/compiler/python/pyi_generator.cc

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

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

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

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

Loading…
Cancel
Save