Skip to content
Snippets Groups Projects
Commit 3b099800 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

Merge pull request #6238 from gwvo/master

Some additional fixes to make the C++ codegen not depend on protobuf.
parents 8cc7332b b695b9b0
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, c ...@@ -86,7 +86,7 @@ void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, c
} }
} }
grpc::string GetHeaderPrologue(File *file, const Parameters &params) { grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) {
grpc::string output; grpc::string output;
{ {
// Scope the output stream so it closes and finalizes output to the string. // Scope the output stream so it closes and finalizes output to the string.
...@@ -96,6 +96,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) { ...@@ -96,6 +96,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) {
vars["filename"] = file->filename(); vars["filename"] = file->filename();
vars["filename_identifier"] = FilenameIdentifier(file->filename()); vars["filename_identifier"] = FilenameIdentifier(file->filename());
vars["filename_base"] = file->filename_without_ext(); vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = file->message_header_ext();
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
printer->Print(vars, printer->Print(vars,
...@@ -104,7 +105,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) { ...@@ -104,7 +105,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) {
printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n");
printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n");
printer->Print(vars, "\n"); printer->Print(vars, "\n");
printer->Print(vars, "#include \"$filename_base$.pb.h\"\n"); printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, "\n"); printer->Print(vars, "\n");
} }
return output; return output;
...@@ -794,8 +795,7 @@ grpc::string GetHeaderServices(File *file, ...@@ -794,8 +795,7 @@ grpc::string GetHeaderServices(File *file,
return output; return output;
} }
grpc::string GetHeaderEpilogue(File *file, grpc::string GetHeaderEpilogue(File *file, const Parameters & /*params*/) {
const Parameters &params) {
grpc::string output; grpc::string output;
{ {
// Scope the output stream so it closes and finalizes output to the string. // Scope the output stream so it closes and finalizes output to the string.
...@@ -821,8 +821,7 @@ grpc::string GetHeaderEpilogue(File *file, ...@@ -821,8 +821,7 @@ grpc::string GetHeaderEpilogue(File *file,
return output; return output;
} }
grpc::string GetSourcePrologue(File *file, grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) {
const Parameters &params) {
grpc::string output; grpc::string output;
{ {
// Scope the output stream so it closes and finalizes output to the string. // Scope the output stream so it closes and finalizes output to the string.
...@@ -831,13 +830,16 @@ grpc::string GetSourcePrologue(File *file, ...@@ -831,13 +830,16 @@ grpc::string GetSourcePrologue(File *file,
vars["filename"] = file->filename(); vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext(); vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = file->message_header_ext();
vars["service_header_ext"] = file->service_header_ext();
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
printer->Print(vars, printer->Print(vars,
"// If you make any local change, they will be lost.\n"); "// If you make any local change, they will be lost.\n");
printer->Print(vars, "// source: $filename$\n\n"); printer->Print(vars, "// source: $filename$\n\n");
printer->Print(vars, "#include \"$filename_base$.pb.h\"\n"); printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
printer->Print(vars, file->additional_headers().c_str());
printer->Print(vars, "\n"); printer->Print(vars, "\n");
} }
return output; return output;
...@@ -1180,8 +1182,7 @@ grpc::string GetSourceServices(File *file, ...@@ -1180,8 +1182,7 @@ grpc::string GetSourceServices(File *file,
return output; return output;
} }
grpc::string GetSourceEpilogue(File *file, grpc::string GetSourceEpilogue(File *file, const Parameters & /*params*/) {
const Parameters &params) {
grpc::string temp; grpc::string temp;
if (!file->package().empty()) { if (!file->package().empty()) {
......
...@@ -106,8 +106,11 @@ struct File { ...@@ -106,8 +106,11 @@ struct File {
virtual grpc::string filename() const = 0; virtual grpc::string filename() const = 0;
virtual grpc::string filename_without_ext() const = 0; virtual grpc::string filename_without_ext() const = 0;
virtual grpc::string message_header_ext() const = 0;
virtual grpc::string service_header_ext() const = 0;
virtual grpc::string package() const = 0; virtual grpc::string package() const = 0;
virtual std::vector<grpc::string> package_parts() const = 0; virtual std::vector<grpc::string> package_parts() const = 0;
virtual grpc::string additional_headers() const = 0;
virtual int service_count() const = 0; virtual int service_count() const = 0;
virtual std::unique_ptr<const Service> service(int i) const = 0; virtual std::unique_ptr<const Service> service(int i) const = 0;
......
...@@ -120,11 +120,16 @@ class ProtoBufFile : public grpc_cpp_generator::File { ...@@ -120,11 +120,16 @@ class ProtoBufFile : public grpc_cpp_generator::File {
return grpc_generator::StripProto(filename()); return grpc_generator::StripProto(filename());
} }
grpc::string message_header_ext() const { return ".pb.h"; }
grpc::string service_header_ext() const { return ".grpc.pb.h"; }
grpc::string package() const { return file_->package(); } grpc::string package() const { return file_->package(); }
std::vector<grpc::string> package_parts() const { std::vector<grpc::string> package_parts() const {
return grpc_generator::tokenize(package(), "."); return grpc_generator::tokenize(package(), ".");
} }
grpc::string additional_headers() const { return ""; }
int service_count() const { return file_->service_count(); }; int service_count() const { return file_->service_count(); };
std::unique_ptr<const grpc_cpp_generator::Service> service(int i) const { std::unique_ptr<const grpc_cpp_generator::Service> service(int i) const {
return std::unique_ptr<const grpc_cpp_generator::Service> ( return std::unique_ptr<const grpc_cpp_generator::Service> (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment