From 0cdc623050ac8c76f3a8dbd14675a3b29f18542d Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Wed, 15 Feb 2012 17:34:48 +0200 Subject: Modified nanopb_generator.py to generate includes for other .proto files. Implementation was suggested by extremeblue99. Fixes issue 4. --- generator/nanopb_generator.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 337b32a..2cc92f0 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -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 \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') -- cgit 1.2.3-korg