aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

code generator doesn't produce #include when importing another proto file #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. add import "some_other.proto" to the current proto file
2. run code generator

What is the expected output? What do you see instead?
i expect the generated header file should also include the header file of the 
imported file, but this is not the case. As a result, compilation breaks. 

What version of the product are you using? On what operating system?
0.1.1.

Great job on the project by the way. 

Original issue reported on code.google.com by extremeb...@gmail.com on 11 Feb 2012 at 9:08

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 0cdc623050ac.

Original comment by Petteri.Aimonen on 15 Feb 2012 at 3:36

GoogleCodeExporter commented 9 years ago
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