Code Review
/
apps
/
agl-service-can-low-level.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Update API reference to match headers
[apps/agl-service-can-low-level.git]
/
generator
/
nanopb_generator.py
diff --git
a/generator/nanopb_generator.py
b/generator/nanopb_generator.py
index
0748e63
..
501affa
100755
(executable)
--- a/
generator/nanopb_generator.py
+++ b/
generator/nanopb_generator.py
@@
-3,7
+3,7
@@
from __future__ import unicode_literals
'''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.'''
from __future__ import unicode_literals
'''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.'''
-nanopb_version = "nanopb-0.3.
5
-dev"
+nanopb_version = "nanopb-0.3.
6
-dev"
import sys
import re
import sys
import re
@@
-197,6
+197,10
@@
class Enum:
result += ' %s;' % self.names
result += ' %s;' % self.names
+ result += '\n#define _%s_MIN %s' % (self.names, self.values[0][0])
+ result += '\n#define _%s_MAX %s' % (self.names, self.values[-1][0])
+ result += '\n#define _%s_ARRAYSIZE ((%s)(%s+1))' % (self.names, self.names, self.values[-1][0])
+
if not self.options.long_names:
# Define the long names always so that enum value references
# from other files work properly.
if not self.options.long_names:
# Define the long names always so that enum value references
# from other files work properly.
@@
-809,9
+813,10
@@
class Message:
if not self.ordered_fields:
# Empty structs are not allowed in C standard.
# Therefore add a dummy field if an empty message occurs.
if not self.ordered_fields:
# Empty structs are not allowed in C standard.
# Therefore add a dummy field if an empty message occurs.
- result += '
uint8_t
dummy_field;'
+ result += '
char
dummy_field;'
result += '\n'.join([str(f) for f in self.ordered_fields])
result += '\n'.join([str(f) for f in self.ordered_fields])
+ result += '\n/* @@protoc_insertion_point(struct:%s) */' % self.name
result += '\n}'
if self.packed:
result += '\n}'
if self.packed:
@@
-1055,6
+1060,8
@@
class ProtoFile:
yield options.genformat % (noext + options.extension + '.h')
yield '\n'
yield options.genformat % (noext + options.extension + '.h')
yield '\n'
+ yield '/* @@protoc_insertion_point(includes) */\n'
+
yield '#if PB_PROTO_HEADER_VERSION != 30\n'
yield '#error Regenerate this file with the current version of nanopb generator.\n'
yield '#endif\n'
yield '#if PB_PROTO_HEADER_VERSION != 30\n'
yield '#error Regenerate this file with the current version of nanopb generator.\n'
yield '#endif\n'
@@
-1112,9
+1119,11
@@
class ProtoFile:
yield '/* Maximum encoded size of messages (where known) */\n'
for msg in self.messages:
msize = msg.encoded_size(self.dependencies)
yield '/* Maximum encoded size of messages (where known) */\n'
for msg in self.messages:
msize = msg.encoded_size(self.dependencies)
+ identifier = '%s_size' % msg.name
if msize is not None:
if msize is not None:
- identifier = '%s_size' % msg.name
yield '#define %-40s %s\n' % (identifier, msize)
yield '#define %-40s %s\n' % (identifier, msize)
+ else:
+ yield '/* %s depends on runtime parameters */\n' % identifier
yield '\n'
yield '/* Message IDs (where set with "msgid" option) */\n'
yield '\n'
yield '/* Message IDs (where set with "msgid" option) */\n'
@@
-1149,6
+1158,7
@@
class ProtoFile:
yield '#endif\n'
# End of header
yield '#endif\n'
# End of header
+ yield '/* @@protoc_insertion_point(eof) */\n'
yield '\n#endif\n'
def generate_source(self, headername, options):
yield '\n#endif\n'
def generate_source(self, headername, options):
@@
-1161,6
+1171,7
@@
class ProtoFile:
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
yield options.genformat % (headername)
yield '\n'
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
yield options.genformat % (headername)
yield '\n'
+ yield '/* @@protoc_insertion_point(includes) */\n'
yield '#if PB_PROTO_HEADER_VERSION != 30\n'
yield '#error Regenerate this file with the current version of nanopb generator.\n'
yield '#if PB_PROTO_HEADER_VERSION != 30\n'
yield '#error Regenerate this file with the current version of nanopb generator.\n'
@@
-1253,6
+1264,7
@@
class ProtoFile:
yield 'PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
yield '\n'
yield 'PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
yield '\n'
+ yield '/* @@protoc_insertion_point(eof) */\n'
# ---------------------------------------------------------------------------
# Options parsing for the .proto files
# ---------------------------------------------------------------------------
# Options parsing for the .proto files
@@
-1357,6
+1369,9
@@
optparser.add_option("-f", "--options-file", dest="options_file", metavar="FILE"
optparser.add_option("-I", "--options-path", dest="options_path", metavar="DIR",
action="append", default = [],
help="Search for .options files additionally in this path")
optparser.add_option("-I", "--options-path", dest="options_path", metavar="DIR",
action="append", default = [],
help="Search for .options files additionally in this path")
+optparser.add_option("-D", "--output-dir", dest="output_dir",
+ metavar="OUTPUTDIR", default=None,
+ help="Output directory of .pb.h and .pb.c files")
optparser.add_option("-Q", "--generated-include-format", dest="genformat",
metavar="FORMAT", default='#include "%s"\n',
help="Set format string to use for including other .pb.h files. [default: %default]")
optparser.add_option("-Q", "--generated-include-format", dest="genformat",
metavar="FORMAT", default='#include "%s"\n',
help="Set format string to use for including other .pb.h files. [default: %default]")
@@
-1473,17
+1488,29
@@
def main_cli():
if options.quiet:
options.verbose = False
if options.quiet:
options.verbose = False
- Globals.verbose_options = options.verbose
+ if options.output_dir and not os.path.exists(options.output_dir):
+ optparser.print_help()
+ sys.stderr.write("\noutput_dir does not exist: %s\n" % options.output_dir)
+ sys.exit(1)
+
+ Globals.verbose_options = options.verbose
for filename in filenames:
results = process_file(filename, None, options)
for filename in filenames:
results = process_file(filename, None, options)
+ base_dir = options.output_dir or ''
+ to_write = [
+ (os.path.join(base_dir, results['headername']), results['headerdata']),
+ (os.path.join(base_dir, results['sourcename']), results['sourcedata']),
+ ]
+
if not options.quiet:
if not options.quiet:
- sys.stderr.write("Writing to " + results['headername'] + " and "
-
+ results['sourcename'] + "\n"
)
+ paths = " and ".join([x[0] for x in to_write])
+
sys.stderr.write("Writing to %s\n" % paths
)
- open(results['headername'], 'w').write(results['headerdata'])
- open(results['sourcename'], 'w').write(results['sourcedata'])
+ for path, data in to_write:
+ with open(path, 'w') as f:
+ f.write(data)
def main_plugin():
'''Main function when invoked as a protoc plugin.'''
def main_plugin():
'''Main function when invoked as a protoc plugin.'''
@@
-1547,4
+1574,3
@@
if __name__ == '__main__':
main_plugin()
else:
main_cli()
main_plugin()
else:
main_cli()
-