Closed GoogleCodeExporter closed 9 years ago
This is a bit problematic, as not all .proto include files should result in an
include in the C header. For example, nanopb.proto or
google/protobuf/descriptor.proto should not be included in the C code. Except
that someone might want to parse FileDescriptorSet using nanopb, and then it
suddenly needs to include descriptor.pb.h.
It is probably best to make an inclusion list. I.e. there could be a command
line option to the generator, '-i foo.pb.h' which would add the specified
include.
Original comment by Petteri.Aimonen
on 12 Feb 2012 at 9:04
Both official protobuf c++ and protobuf-c always generate #include header for
any import file even if it's descriptor.proto. I think using '-i" can be
annoying and error prone since the user now needs to match the "import"
statements with -i. There is already a field called "repeated string
dependency" available in FileDescriptorProto. protobuf c++ and protobuf-c
simply iterate thru this list to output "#include" for each import file.
Since we don't technically need the nanopb.h, we can just either have an empty
nanopb.h or make the python generator not to include it programmatically.
Original comment by extremeb...@gmail.com
on 12 Feb 2012 at 10:06
I simply added the following code to nanopb_generator.py, where dependencies is
fdesc.dependency. I then defined a dummy (empty) nanopb.pb.h.
def generate_header(dependencies, headername, enums, messages):
....
yield '#include <pb.h>\n'
for dependency in dependencies:
noext = os.path.splitext(dependency)[0]
yield '#include "%s.pb.h"\n' % noext
yield '\n'
....
Original comment by extremeb...@gmail.com
on 13 Feb 2012 at 9:23
This issue was closed by revision 0cdc623050ac.
Original comment by Petteri.Aimonen
on 15 Feb 2012 at 3:36
Thanks for the suggestion. I added it to the repo, with the small addition that
I made an exclusion list for 'nanopb.proto'. I think it is cleaner to have it
excluded than having a dummy empty file.
If need arises, it will be easy add some -x foo.proto switch for excluding
files on the command line.
Original comment by Petteri.Aimonen
on 15 Feb 2012 at 3:38
Original issue reported on code.google.com by
extremeb...@gmail.com
on 11 Feb 2012 at 9:08