From 8c14e736034b82d65b43db529161dd281a37816a Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sun, 22 Mar 2015 11:17:57 +0200 Subject: Use make_identifier() to create the name for FOO_MESSAGES define. This handles special charaters like in "my-file.proto" properly. Also use headerbasename instead of full path, so that compiling files with relative path doesn't create symbols like FOO/BAR/BAZ_MESSAGES. --- generator/nanopb_generator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'generator') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index d316fad..4673ac6 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -920,7 +920,7 @@ def make_identifier(headername): result += '_' return result -def generate_header(noext, dependencies, headername, enums, messages, extensions, options): +def generate_header(dependencies, headername, enums, messages, extensions, options): '''Generate content for a header file. Generates strings, which should be concatenated and stored to file. ''' @@ -1014,7 +1014,8 @@ def generate_header(noext, dependencies, headername, enums, messages, extensions yield '#define PB_MSG_%d %s\n' % (msg.msgid, msg.name) yield '\n' - yield '#define %s_MESSAGES \\\n' % (noext.upper()) + symbol = make_identifier(headername.split('.')[0]) + yield '#define %s_MESSAGES \\\n' % symbol for msg in messages: m = "-1" @@ -1313,7 +1314,7 @@ def process_file(filename, fdesc, options): excludes = ['nanopb.proto', 'google/protobuf/descriptor.proto'] + options.exclude dependencies = [d for d in fdesc.dependency if d not in excludes] - headerdata = ''.join(generate_header(noext,dependencies, headerbasename, enums, + headerdata = ''.join(generate_header(dependencies, headerbasename, enums, messages, extensions, options)) sourcedata = ''.join(generate_source(headerbasename, enums, -- cgit 1.2.3-korg