Modified nanopb_generator.py to generate includes for other .proto files.
Implementation was suggested by extremeblue99. Fixes issue 4.
This commit is contained in:
@@ -347,7 +347,7 @@ def sort_dependencies(messages):
|
|||||||
if msgname in message_by_name:
|
if msgname in message_by_name:
|
||||||
yield message_by_name[msgname]
|
yield message_by_name[msgname]
|
||||||
|
|
||||||
def generate_header(headername, enums, messages):
|
def generate_header(dependencies, headername, enums, messages):
|
||||||
'''Generate content for a header file.
|
'''Generate content for a header file.
|
||||||
Generates strings, which should be concatenated and stored to 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 '#define _PB_%s_\n' % symbol
|
||||||
yield '#include <pb.h>\n\n'
|
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'
|
yield '/* Enum definitions */\n'
|
||||||
for enum in enums:
|
for enum in enums:
|
||||||
yield str(enum) + '\n\n'
|
yield str(enum) + '\n\n'
|
||||||
@@ -415,8 +420,13 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print "Writing to " + headername + " and " + sourcename
|
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')
|
header = open(headername, 'w')
|
||||||
for part in generate_header(headerbasename, enums, messages):
|
for part in generate_header(dependencies, headerbasename, enums, messages):
|
||||||
header.write(part)
|
header.write(part)
|
||||||
|
|
||||||
source = open(sourcename, 'w')
|
source = open(sourcename, 'w')
|
||||||
|
|||||||
Reference in New Issue
Block a user