aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-02-15 17:34:48 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-02-15 17:34:48 +0200
commit0cdc623050ac8c76f3a8dbd14675a3b29f18542d (patch)
treec79c52fb8cdfb1595fb73f47933fb394620eb735 /generator
parentf6b08404fa9408e719785f89ee69df8e2457e158 (diff)
Modified nanopb_generator.py to generate includes for other .proto files.
Implementation was suggested by extremeblue99. Fixes issue 4.
Diffstat (limited to 'generator')
-rw-r--r--generator/nanopb_generator.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 337b32a5..2cc92f01 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 <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')