diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-07-05 20:02:06 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-07-05 20:02:06 +0300 |
commit | d8bddabb8372d1c684d7cd7cf4bb04131acb9ff1 (patch) | |
tree | a9c1c36d7f3c2c64db109d7c07ca247ea4102aff /generator | |
parent | 01a155689828574047a8377d595a0ad038c48917 (diff) |
Fix bug with .proto without messages (again), and add a test case for it.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/nanopb_generator.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 1923cc1..b9018ae 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -414,15 +414,16 @@ def generate_header(dependencies, headername, enums, messages): for msg in messages: yield msg.fields_declaration() + '\n' - count_required_fields = lambda m: len([f for f in msg.fields if f.htype == 'PB_HTYPE_REQUIRED']) - largest_msg = max(messages, key = count_required_fields) - largest_count = count_required_fields(largest_msg) - if largest_count > 64: - yield '\n/* Check that missing required fields will be properly detected */\n' - yield '#if PB_MAX_REQUIRED_FIELDS < %d\n' % largest_count - yield '#error Properly detecting missing required fields in %s requires \\\n' % largest_msg.name - yield ' setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count - yield '#endif\n' + if messages: + count_required_fields = lambda m: len([f for f in msg.fields if f.htype == 'PB_HTYPE_REQUIRED']) + largest_msg = max(messages, key = count_required_fields) + largest_count = count_required_fields(largest_msg) + if largest_count > 64: + yield '\n/* Check that missing required fields will be properly detected */\n' + yield '#if PB_MAX_REQUIRED_FIELDS < %d\n' % largest_count + yield '#error Properly detecting missing required fields in %s requires \\\n' % largest_msg.name + yield ' setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count + yield '#endif\n' worst = 0 worst_field = '' |