Modified nanopb_generator.py to generate includes for other .proto files.

Implementation was suggested by extremeblue99.
Fixes issue 4.
This commit is contained in:
Petteri Aimonen
2012-02-15 17:34:48 +02:00
parent f6b08404fa
commit 0cdc623050

View File

@@ -347,7 +347,7 @@ def sort_dependencies(messages):
if msgname in message_by_name:
yield message_by_name[msgname]
def generate_header(headername, enums, messages):
def generate_header(dependencies, headername, enums, messages):
'''Generate content for a header file.
Generates strings, which should be concatenated and stored to file.
'''
@@ -359,6 +359,11 @@ def generate_header(headername, enums, messages):
yield '#define _PB_%s_\n' % symbol
yield '#include <pb.h>\n\n'
for dependency in dependencies:
noext = os.path.splitext(dependency)[0]
yield '#include "%s.pb.h"\n' % noext
yield '\n'
yield '/* Enum definitions */\n'
for enum in enums:
yield str(enum) + '\n\n'
@@ -415,8 +420,13 @@ if __name__ == '__main__':
print "Writing to " + headername + " and " + sourcename
# List of .proto files that should not be included in the C header file
# even if they are mentioned in the source .proto.
excludes = ['nanopb.proto']
dependencies = [d for d in fdesc.file[0].dependency if d not in excludes]
header = open(headername, 'w')
for part in generate_header(headerbasename, enums, messages):
for part in generate_header(dependencies, headerbasename, enums, messages):
header.write(part)
source = open(sourcename, 'w')