mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
protoc-c: add no_generate option
Allows suppression of .pb-c.{c,h} file generation on a .proto file basis. protobuf-c.proto: Use the new option in itself, because the options are never used by protobuf-c runtime, only by the protoc-gen-c compiler. t/test-full.proto: import protobuf-c.proto to test that protobuf-c.pb-c.h dependency does not get included in test-full.pb-c.h.
This commit is contained in:
parent
0e060260f0
commit
883b1acc1b
@ -164,7 +164,8 @@ noinst_PROGRAMS += \
|
||||
|
||||
t_generated_code2_cxx_generate_packed_data_SOURCES = \
|
||||
t/generated-code2/cxx-generate-packed-data.cc \
|
||||
t/test-full.pb.cc
|
||||
t/test-full.pb.cc \
|
||||
protobuf-c/protobuf-c.pb.cc
|
||||
$(t_generated_code2_cxx_generate_packed_data_OBJECTS): t/test-full.pb.h
|
||||
t_generated_code2_cxx_generate_packed_data_CXXFLAGS = \
|
||||
$(AM_CXXFLAGS) \
|
||||
|
@ -30,7 +30,13 @@
|
||||
syntax = "proto2";
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
// We never need to generate protobuf-c.pb-c.{c,h}, the options are used
|
||||
// only by protoc-gen-c, never by the protobuf-c runtime itself
|
||||
option (pb_c_file).no_generate = true;
|
||||
|
||||
message ProtobufCFileOptions {
|
||||
// Suppresses pb-c.{c,h} file output completely.
|
||||
optional bool no_generate = 1 [default = false];
|
||||
}
|
||||
|
||||
extend google.protobuf.FileOptions {
|
||||
|
@ -157,9 +157,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
|
||||
"protoc_version", SimpleItoa(PROTOBUF_C_VERSION_NUMBER));
|
||||
|
||||
for (int i = 0; i < file_->dependency_count(); i++) {
|
||||
printer->Print(
|
||||
"#include \"$dependency$.pb-c.h\"\n",
|
||||
"dependency", StripProto(file_->dependency(i)->name()));
|
||||
const ProtobufCFileOptions opt =
|
||||
file_->dependency(i)->options().GetExtension(pb_c_file);
|
||||
if (!opt.no_generate()) {
|
||||
printer->Print(
|
||||
"#include \"$dependency$.pb-c.h\"\n",
|
||||
"dependency", StripProto(file_->dependency(i)->name()));
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print("\n");
|
||||
|
@ -106,6 +106,9 @@ bool CGenerator::Generate(const FileDescriptor* file,
|
||||
const std::string& parameter,
|
||||
OutputDirectory* output_directory,
|
||||
std::string* error) const {
|
||||
if (file->options().GetExtension(pb_c_file).no_generate())
|
||||
return true;
|
||||
|
||||
std::vector<std::pair<std::string, std::string> > options;
|
||||
ParseOptions(parameter, &options);
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package foo;
|
||||
|
||||
import "protobuf-c/protobuf-c.proto";
|
||||
|
||||
message SubMess {
|
||||
required int32 test = 4;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user