21 #include <unordered_set>
24 #include <google/protobuf/compiler/code_generator.h>
25 #include <google/protobuf/compiler/command_line_interface.h>
26 #include <google/protobuf/compiler/importer.h>
27 #include <google/protobuf/compiler/python/python_generator.h>
28 #include <google/protobuf/descriptor.h>
29 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
50 "Generate Python source file.");
56 "Generate Python source file.");
58 return cli.
Run(argc, argv);
66 const std::vector<const FileDescriptor*>& parsed_files,
67 std::vector<std::pair<std::string, std::string>>* files_out)
87 std::vector<const ::google::protobuf::FileDescriptor*>*
output) {
92 std::vector<std::pair<std::string, std::string>>*
files_;
99 std::vector<::grpc_tools::ProtocWarning>* warnings)
113 std::vector<::grpc_tools::ProtocError>*
errors_;
119 std::vector<const FileDescriptor*>* transitive_closure,
120 std::unordered_set<const ::google::protobuf::FileDescriptor*>*
visited) {
135 const std::vector<std::string>* include_paths,
136 std::vector<std::pair<std::string, std::string>>* files_out,
137 std::vector<::grpc_tools::ProtocError>*
errors,
138 std::vector<::grpc_tools::ProtocWarning>* warnings) {
139 std::unique_ptr<internal::ErrorCollectorImpl> error_collector(
141 std::unique_ptr<DiskSourceTree> source_tree(
new DiskSourceTree());
142 for (
const auto& include_path : *include_paths) {
143 source_tree->MapPath(
"", include_path);
145 Importer importer(source_tree.get(), error_collector.get());
146 const FileDescriptor* parsed_file = importer.Import(protobuf_path);
147 if (parsed_file ==
nullptr) {
150 std::vector<const FileDescriptor*> transitive_closure;
151 std::unordered_set<const FileDescriptor*>
visited;
157 for (
const auto descriptor : transitive_closure) {
164 char* protobuf_path,
const std::vector<std::string>* include_paths,
165 std::vector<std::pair<std::string, std::string>>* files_out,
166 std::vector<::grpc_tools::ProtocError>*
errors,
167 std::vector<::grpc_tools::ProtocWarning>* warnings) {
169 return generate_code(&python_generator, protobuf_path, include_paths,
170 files_out,
errors, warnings);
174 char* protobuf_path,
const std::vector<std::string>* include_paths,
175 std::vector<std::pair<std::string, std::string>>* files_out,
176 std::vector<::grpc_tools::ProtocError>*
errors,
177 std::vector<::grpc_tools::ProtocWarning>* warnings) {
180 return generate_code(&grpc_py_generator, protobuf_path, include_paths,
181 files_out,
errors, warnings);