diff options
41 files changed, 173 insertions, 74 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8c6f8e64..b81b847e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,13 @@ -nanopb-0.3.3 (2015-04-xx) +nanopb-0.3.4 (2015-09-26) + Fix handling of unsigned 8- and 16-bit enums (issue 164) + Fix generator on systems where python = python3. (issue 155) + Fix compiler warning on GCC 5.x (issue 171) + Make the generator better handle imported .protos (issue 165) + Add packed_enum option to generator. + Add syntax= line to .proto files (issue 167) + Add PlatformIO registry manifest file. (pr 156) + +nanopb-0.3.3 (2015-04-10) Fix missing files in Linux binary package (issue 146) Fix generator bug when oneof is first field in a message. (issue 142) Fix generator error when long_names:false is combined with Oneofs. (issue 147) diff --git a/examples/cmake_simple/simple.c b/examples/cmake_simple/simple.c index 31272301..1f6b1373 100644 --- a/examples/cmake_simple/simple.c +++ b/examples/cmake_simple/simple.c @@ -15,8 +15,11 @@ int main() /* Allocate space on the stack to store the message data. * * Nanopb generates simple struct definitions for all the messages. - * - check out the contents of simple.pb.h! */ - SimpleMessage message; + * - check out the contents of simple.pb.h! + * It is a good idea to always initialize your structures + * so that you do not have garbage data from RAM in there. + */ + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); @@ -44,7 +47,7 @@ int main() { /* Allocate space for the decoded message. */ - SimpleMessage message; + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that reads from the buffer. */ pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); diff --git a/examples/cmake_simple/simple.proto b/examples/cmake_simple/simple.proto index 26e72f46..5c73a3b2 100644 --- a/examples/cmake_simple/simple.proto +++ b/examples/cmake_simple/simple.proto @@ -1,6 +1,8 @@ // A very simple protocol definition, consisting of only // one message. +syntax = "proto2"; + message SimpleMessage { required int32 lucky_number = 1; } diff --git a/examples/network_server/fileproto.proto b/examples/network_server/fileproto.proto index 3e70c492..5640b8d5 100644 --- a/examples/network_server/fileproto.proto +++ b/examples/network_server/fileproto.proto @@ -2,6 +2,8 @@ // // See also the nanopb-specific options in fileproto.options. +syntax = "proto2"; + message ListFilesRequest { optional string path = 1 [default = "/"]; } diff --git a/examples/simple/simple.c b/examples/simple/simple.c index 31272301..1f6b1373 100644 --- a/examples/simple/simple.c +++ b/examples/simple/simple.c @@ -15,8 +15,11 @@ int main() /* Allocate space on the stack to store the message data. * * Nanopb generates simple struct definitions for all the messages. - * - check out the contents of simple.pb.h! */ - SimpleMessage message; + * - check out the contents of simple.pb.h! + * It is a good idea to always initialize your structures + * so that you do not have garbage data from RAM in there. + */ + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); @@ -44,7 +47,7 @@ int main() { /* Allocate space for the decoded message. */ - SimpleMessage message; + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that reads from the buffer. */ pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); diff --git a/examples/simple/simple.proto b/examples/simple/simple.proto index 26e72f46..5c73a3b2 100644 --- a/examples/simple/simple.proto +++ b/examples/simple/simple.proto @@ -1,6 +1,8 @@ // A very simple protocol definition, consisting of only // one message. +syntax = "proto2"; + message SimpleMessage { required int32 lucky_number = 1; } diff --git a/examples/using_double_on_avr/doubleproto.proto b/examples/using_double_on_avr/doubleproto.proto index d8b7f2db..72d3f9c1 100644 --- a/examples/using_double_on_avr/doubleproto.proto +++ b/examples/using_double_on_avr/doubleproto.proto @@ -1,4 +1,6 @@ // A message containing doubles, as used by other applications. +syntax = "proto2"; + message DoubleMessage { required double field1 = 1; required double field2 = 2; diff --git a/examples/using_union_messages/unionproto.proto b/examples/using_union_messages/unionproto.proto index d7c9de2d..209df0d2 100644 --- a/examples/using_union_messages/unionproto.proto +++ b/examples/using_union_messages/unionproto.proto @@ -5,6 +5,8 @@ // but they are commonly implemented by filling out exactly one of // several optional fields. +syntax = "proto2"; + message MsgType1 { required int32 value = 1; diff --git a/extra/FindNanopb.cmake b/extra/FindNanopb.cmake index e65706ac..1fd25334 100644 --- a/extra/FindNanopb.cmake +++ b/extra/FindNanopb.cmake @@ -175,7 +175,7 @@ function(NANOPB_GENERATE_CPP SRCS HDRS) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.c" "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" - COMMAND ${PYTHON2_EXECUTABLE} + COMMAND ${PYTHON_EXECUTABLE} ARGS ${NANOPB_GENERATOR_EXECUTABLE} ${FIL_WE}.pb ${NANOPB_OPTIONS} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb" COMMENT "Running nanopb generator on ${FIL_WE}.pb" @@ -244,17 +244,7 @@ find_file(NANOPB_GENERATOR_EXECUTABLE ) mark_as_advanced(NANOPB_GENERATOR_EXECUTABLE) -# If python3 has already been found, save it and look for python2.6 -if(${PYTHON_VERSION_MAJOR} AND ${PYTHON_VERSION_MAJOR} EQUAL 3) - set(PYTHON3_EXECUTABLE ${PYTHON_EXECUTABLE}) - set(PYTHON_EXECUTABLE PYTHON_EXECUTABLE-NOTFOUND) - find_package(PythonInterp 2.6 REQUIRED) - set(PYTHON2_EXECUTABLE ${PYTHON_EXECUTABLE}) - set(PYTHON_EXECUTABLE ${PYTHON3_EXECUTABLE}) -else() - find_package(PythonInterp 2.6 REQUIRED) - set(PYTHON2_EXECUTABLE ${PYTHON_EXECUTABLE}) -endif() +find_package(PythonInterp REQUIRED) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(NANOPB DEFAULT_MSG diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 3a5fac5a..7fe0db95 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -1,10 +1,13 @@ -#!/usr/bin/python +#!/usr/bin/env python + +from __future__ import unicode_literals '''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.''' -nanopb_version = "nanopb-0.3.4-dev" +nanopb_version = "nanopb-0.3.5-dev" import sys import re +from functools import reduce try: # Add some dummy imports to keep packaging tools happy. @@ -82,7 +85,14 @@ class Names: return '_'.join(self.parts) def __add__(self, other): - if isinstance(other, (str, unicode)): + # The fdesc names are unicode and need to be handled for + # python2 and python3 + try: + realstr = unicode + except NameError: + realstr = str + + if isinstance(other, realstr): return Names(self.parts + (other,)) elif isinstance(other, tuple): return Names(self.parts + other) @@ -123,7 +133,7 @@ class EncodedSize: self.symbols = symbols def __add__(self, other): - if isinstance(other, (int, long)): + if isinstance(other, int): return EncodedSize(self.value + other, self.symbols) elif isinstance(other, (str, Names)): return EncodedSize(self.value, self.symbols + [str(other)]) @@ -133,7 +143,7 @@ class EncodedSize: raise ValueError("Cannot add size: " + repr(other)) def __mul__(self, other): - if isinstance(other, (int, long)): + if isinstance(other, int): return EncodedSize(self.value * other, [str(other) + '*' + s for s in self.symbols]) else: raise ValueError("Cannot multiply size: " + repr(other)) @@ -192,6 +202,24 @@ class Enum: return result +class FieldMaxSize: + def __init__(self, worst = 0, checks = [], field_name = 'undefined'): + if isinstance(worst, list): + self.worst = max(i for i in worst if i is not None) + else: + self.worst = worst + + self.worst_field = field_name + self.checks = checks + + def extend(self, extend, field_name = None): + self.worst = max(self.worst, extend.worst) + + if self.worst == extend.worst: + self.worst_field = extend.worst_field + + self.checks.extend(extend.checks) + class Field: def __init__(self, struct_name, desc, field_options): '''desc is FieldDescriptorProto''' @@ -260,7 +288,7 @@ class Field: raise NotImplementedError(field_options.type) # Decide the C data type to use in the struct. - if datatypes.has_key(desc.type): + if desc.type in datatypes: self.ctype, self.pbtype, self.enc_size, isa = datatypes[desc.type] # Override the field size if user wants to use smaller integers @@ -295,8 +323,8 @@ class Field: else: raise NotImplementedError(desc.type) - def __cmp__(self, other): - return cmp(self.tag, other.tag) + def __lt__(self, other): + return self.tag < other.tag def __str__(self): result = '' @@ -360,12 +388,10 @@ class Field: inner_init = '0' else: if self.pbtype == 'STRING': - inner_init = self.default.encode('utf-8').encode('string_escape') - inner_init = inner_init.replace('"', '\\"') + inner_init = self.default.replace('"', '\\"') inner_init = '"' + inner_init + '"' elif self.pbtype == 'BYTES': - data = str(self.default).decode('string_escape') - data = ['0x%02x' % ord(c) for c in data] + data = ['0x%02x' % ord(c) for c in self.default] if len(data) == 0: inner_init = '{0, {0}}' else: @@ -467,15 +493,18 @@ class Field: def largest_field_value(self): '''Determine if this field needs 16bit or 32bit pb_field_t structure to compile properly. Returns numeric value or a C-expression for assert.''' + check = [] if self.pbtype == 'MESSAGE': if self.rules == 'REPEATED' and self.allocation == 'STATIC': - return 'pb_membersize(%s, %s[0])' % (self.struct_name, self.name) + check.append('pb_membersize(%s, %s[0])' % (self.struct_name, self.name)) elif self.rules == 'ONEOF': - return 'pb_membersize(%s, %s.%s)' % (self.struct_name, self.union_name, self.name) + check.append('pb_membersize(%s, %s.%s)' % (self.struct_name, self.union_name, self.name)) else: - return 'pb_membersize(%s, %s)' % (self.struct_name, self.name) + check.append('pb_membersize(%s, %s)' % (self.struct_name, self.name)) - return max(self.tag, self.max_size, self.max_count) + return FieldMaxSize([self.tag, self.max_size, self.max_count], + check, + ('%s.%s' % (self.struct_name, self.name))) def encoded_size(self, dependencies): '''Return the maximum size that this field can take when encoded, @@ -639,9 +668,6 @@ class OneOf(Field): # Sort by the lowest tag number inside union self.tag = min([f.tag for f in self.fields]) - def __cmp__(self, other): - return cmp(self.tag, other.tag) - def __str__(self): result = '' if self.fields: @@ -675,7 +701,10 @@ class OneOf(Field): return result def largest_field_value(self): - return max([f.largest_field_value() for f in self.fields]) + largest = FieldMaxSize() + for f in self.fields: + largest.extend(f.largest_field_value()) + return largest def encoded_size(self, dependencies): largest = EncodedSize(0) @@ -875,17 +904,17 @@ def toposort2(data): From http://code.activestate.com/recipes/577413-topological-sort/ This function is under the MIT license. ''' - for k, v in data.items(): + for k, v in list(data.items()): v.discard(k) # Ignore self dependencies - extra_items_in_deps = reduce(set.union, data.values(), set()) - set(data.keys()) + extra_items_in_deps = reduce(set.union, list(data.values()), set()) - set(data.keys()) data.update(dict([(item, set()) for item in extra_items_in_deps])) while True: - ordered = set(item for item,dep in data.items() if not dep) + ordered = set(item for item,dep in list(data.items()) if not dep) if not ordered: break for item in sorted(ordered): yield item - data = dict([(item, (dep - ordered)) for item,dep in data.items() + data = dict([(item, (dep - ordered)) for item,dep in list(data.items()) if item not in ordered]) assert not data, "A cyclic dependency exists amongst %r" % data @@ -1136,20 +1165,17 @@ class ProtoFile: 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 = '' - checks = [] + + max_field = FieldMaxSize() checks_msgnames = [] for msg in self.messages: checks_msgnames.append(msg.name) for field in msg.fields: - status = field.largest_field_value() - if isinstance(status, (str, unicode)): - checks.append(status) - elif status > worst: - worst = status - worst_field = str(field.struct_name) + '.' + str(field.name) + max_field.extend(field.largest_field_value()) + + worst = max_field.worst + worst_field = max_field.worst_field + checks = max_field.checks if worst > 255 or checks: yield '\n/* Check that field information fits in pb_field_t */\n' @@ -1237,7 +1263,7 @@ def read_options_file(infile): try: text_format.Merge(parts[1], opts) - except Exception, e: + except Exception as e: sys.stderr.write("%s:%d: " % (infile.name, i + 1) + "Unparseable option line: '%s'. " % line + "Error: %s\n" % str(e)) @@ -1439,14 +1465,15 @@ def main_cli(): def main_plugin(): '''Main function when invoked as a protoc plugin.''' - import sys + import io, sys if sys.platform == "win32": import os, msvcrt # Set stdin and stdout to binary mode msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) - data = sys.stdin.read() + data = io.open(sys.stdin.fileno(), "rb").read() + request = plugin_pb2.CodeGeneratorRequest.FromString(data) try: @@ -1489,7 +1516,7 @@ def main_plugin(): f.name = results['sourcename'] f.content = results['sourcedata'] - sys.stdout.write(response.SerializeToString()) + io.open(sys.stdout.fileno(), "wb").write(response.SerializeToString()) if __name__ == '__main__': # Check if we are running as a plugin under protoc diff --git a/generator/protoc-gen-nanopb b/generator/protoc-gen-nanopb index 6dc468d3..358f97cf 100755 --- a/generator/protoc-gen-nanopb +++ b/generator/protoc-gen-nanopb @@ -10,5 +10,4 @@ # --plugin= on the command line. MYPATH=$(dirname "$0") -PYTHON=$(which python2 || which python) -exec $PYTHON "$MYPATH/nanopb_generator.py" --protoc-plugin +exec "$MYPATH/nanopb_generator.py" --protoc-plugin @@ -50,7 +50,7 @@ /* Version of the nanopb library. Just in case you want to check it in * your own program. */ -#define NANOPB_VERSION nanopb-0.3.4-dev +#define NANOPB_VERSION nanopb-0.3.5-dev /* Include all the system headers needed by nanopb. You will need the * definitions of the following: diff --git a/pb_decode.c b/pb_decode.c index b21bfe37..5cdcbcfb 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -886,7 +886,8 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[ if (PB_HTYPE(iter.pos->type) == PB_HTYPE_REQUIRED && iter.required_field_index < PB_MAX_REQUIRED_FIELDS) { - fields_seen[iter.required_field_index >> 3] |= (uint8_t)(1 << (iter.required_field_index & 7)); + uint8_t tmp = (uint8_t)(1 << (iter.required_field_index & 7)); + fields_seen[iter.required_field_index >> 3] |= tmp; } if (!decode_field(stream, wire_type, &iter)) diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto index 28eaf0be..3995c552 100644 --- a/tests/alltypes/alltypes.proto +++ b/tests/alltypes/alltypes.proto @@ -1,3 +1,6 @@ +syntax = "proto2"; +// package name placeholder + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/backwards_compatibility/alltypes_legacy.proto b/tests/backwards_compatibility/alltypes_legacy.proto index d7631eb6..f5bc35ce 100644 --- a/tests/backwards_compatibility/alltypes_legacy.proto +++ b/tests/backwards_compatibility/alltypes_legacy.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/callbacks/callbacks.proto b/tests/callbacks/callbacks.proto index ccd1edd8..96ac744d 100644 --- a/tests/callbacks/callbacks.proto +++ b/tests/callbacks/callbacks.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { optional string stringvalue = 1; repeated int32 int32value = 2; diff --git a/tests/common/person.proto b/tests/common/person.proto index dafcf934..becefdf3 100644 --- a/tests/common/person.proto +++ b/tests/common/person.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import "nanopb.proto"; message Person { diff --git a/tests/common/unittestproto.proto b/tests/common/unittestproto.proto index 0ecb1f0b..23b5b97f 100644 --- a/tests/common/unittestproto.proto +++ b/tests/common/unittestproto.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message IntegerArray { diff --git a/tests/cyclic_messages/cyclic.proto b/tests/cyclic_messages/cyclic.proto index a9d158cb..8cab0b14 100644 --- a/tests/cyclic_messages/cyclic.proto +++ b/tests/cyclic_messages/cyclic.proto @@ -2,6 +2,8 @@ // These can only be handled in pointer/callback mode, // see associated .options files. +syntax = "proto2"; + message TreeNode { optional int32 leaf = 1; diff --git a/tests/enum_sizes/enumsizes.proto b/tests/enum_sizes/enumsizes.proto index f9ab0b7f..a85d4160 100644 --- a/tests/enum_sizes/enumsizes.proto +++ b/tests/enum_sizes/enumsizes.proto @@ -4,6 +4,8 @@ * a bit of a problem for the encoder/decoder (issue #164). */ +syntax = "proto2"; + import 'nanopb.proto'; option (nanopb_fileopt).long_names = false; diff --git a/tests/extensions/extensions.proto b/tests/extensions/extensions.proto index 79c01245..fcd5b43b 100644 --- a/tests/extensions/extensions.proto +++ b/tests/extensions/extensions.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'alltypes.proto'; extend AllTypes { diff --git a/tests/field_size_16/alltypes.proto b/tests/field_size_16/alltypes.proto index 039391fc..ba1ec383 100644 --- a/tests/field_size_16/alltypes.proto +++ b/tests/field_size_16/alltypes.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/field_size_32/alltypes.proto b/tests/field_size_32/alltypes.proto index 5749e0d4..02ee1a6a 100644 --- a/tests/field_size_32/alltypes.proto +++ b/tests/field_size_32/alltypes.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/fuzztest/SConscript b/tests/fuzztest/SConscript index 35b697f9..973148c2 100644 --- a/tests/fuzztest/SConscript +++ b/tests/fuzztest/SConscript @@ -2,16 +2,19 @@ Import("env", "malloc_env") +def set_pkgname(src, dst, pkgname): + data = open(str(src)).read() + placeholder = '// package name placeholder' + assert placeholder in data + data = data.replace(placeholder, 'package %s;' % pkgname) + open(str(dst), 'w').write(data) + # We want both pointer and static versions of the AllTypes message # Prefix them with package name. env.Command("alltypes_static.proto", "#alltypes/alltypes.proto", - lambda target, source, env: - open(str(target[0]), 'w').write("package alltypes_static;\n" - + open(str(source[0])).read())) + lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_static')) env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto", - lambda target, source, env: - open(str(target[0]), 'w').write("package alltypes_pointer;\n" - + open(str(source[0])).read())) + lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_pointer')) p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"]) p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"]) diff --git a/tests/intsizes/intsizes.proto b/tests/intsizes/intsizes.proto index 236bf183..91444d41 100644 --- a/tests/intsizes/intsizes.proto +++ b/tests/intsizes/intsizes.proto @@ -6,6 +6,8 @@ * otherwise. E.g. uint32 + IS_8 => uint8_t */ +syntax = "proto2"; + import 'nanopb.proto'; message IntSizes { diff --git a/tests/message_sizes/messages1.proto b/tests/message_sizes/messages1.proto index 48af55a3..b66fad71 100644 --- a/tests/message_sizes/messages1.proto +++ b/tests/message_sizes/messages1.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + enum MessageStatus { FAIL = 0; OK = 1; diff --git a/tests/message_sizes/messages2.proto b/tests/message_sizes/messages2.proto index 19fc11ef..67614080 100644 --- a/tests/message_sizes/messages2.proto +++ b/tests/message_sizes/messages2.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; import 'messages1.proto'; diff --git a/tests/missing_fields/missing_fields.proto b/tests/missing_fields/missing_fields.proto index cbb23ba1..cc5e550b 100644 --- a/tests/missing_fields/missing_fields.proto +++ b/tests/missing_fields/missing_fields.proto @@ -1,5 +1,7 @@ /* Test for one missing field among many */ +syntax = "proto2"; + message AllFields { required int32 field1 = 1; diff --git a/tests/multiple_files/multifile1.proto b/tests/multiple_files/multifile1.proto index d804b67d..18f2c672 100644 --- a/tests/multiple_files/multifile1.proto +++ b/tests/multiple_files/multifile1.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { optional string stringvalue = 1; repeated int32 int32value = 2; diff --git a/tests/multiple_files/multifile2.proto b/tests/multiple_files/multifile2.proto index 66cb8a0b..4af45fd9 100644 --- a/tests/multiple_files/multifile2.proto +++ b/tests/multiple_files/multifile2.proto @@ -1,5 +1,7 @@ // Test if including generated header file for this file + implicit include of // multifile2.pb.h still compiles. Used with test_compiles.c. +syntax = "proto2"; + import "multifile1.proto"; message Callback2Message { diff --git a/tests/no_messages/no_messages.proto b/tests/no_messages/no_messages.proto index 279216b0..45bb2e66 100644 --- a/tests/no_messages/no_messages.proto +++ b/tests/no_messages/no_messages.proto @@ -1,5 +1,7 @@ /* Test that a file without any messages works. */ +syntax = "proto2"; + enum Test { First = 1; } diff --git a/tests/oneof/oneof.proto b/tests/oneof/oneof.proto index 00f1ceca..b4fe56f2 100644 --- a/tests/oneof/oneof.proto +++ b/tests/oneof/oneof.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message SubMessage diff --git a/tests/options/options.proto b/tests/options/options.proto index b7050418..aa722b52 100644 --- a/tests/options/options.proto +++ b/tests/options/options.proto @@ -2,6 +2,8 @@ * options.expected lists the patterns that are searched for in the output. */ +syntax = "proto2"; + import "nanopb.proto"; // File level options diff --git a/tests/package_name/SConscript b/tests/package_name/SConscript index 897bc99c..4afc5037 100644 --- a/tests/package_name/SConscript +++ b/tests/package_name/SConscript @@ -3,14 +3,16 @@ Import("env") -# Build a modified alltypes.proto -def modify_proto(target, source, env): - '''Add a "package test.package;" directive to the beginning of the .proto file.''' - data = open(str(source[0]), 'r').read() - open(str(target[0]), 'w').write("package test.package;\n\n" + data) - return 0 +def set_pkgname(src, dst, pkgname): + data = open(str(src)).read() + placeholder = '// package name placeholder' + assert placeholder in data + data = data.replace(placeholder, 'package %s;' % pkgname) + open(str(dst), 'w').write(data) -env.Command("alltypes.proto", "#alltypes/alltypes.proto", modify_proto) +# Build a modified alltypes.proto +env.Command("alltypes.proto", "#alltypes/alltypes.proto", + lambda target, source, env: set_pkgname(source[0], target[0], 'test.package')) env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE")) env.NanopbProto(["alltypes", "alltypes.options"]) diff --git a/tests/regression/issue_118/enumdef.proto b/tests/regression/issue_118/enumdef.proto index 830d2988..46845bc9 100644 --- a/tests/regression/issue_118/enumdef.proto +++ b/tests/regression/issue_118/enumdef.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; enum MyEnum { diff --git a/tests/regression/issue_118/enumuse.proto b/tests/regression/issue_118/enumuse.proto index d778fb8f..4afc4521 100644 --- a/tests/regression/issue_118/enumuse.proto +++ b/tests/regression/issue_118/enumuse.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'enumdef.proto'; message MyMessage { diff --git a/tests/regression/issue_125/extensionbug.proto b/tests/regression/issue_125/extensionbug.proto index c4ac6860..fd1e74f1 100644 --- a/tests/regression/issue_125/extensionbug.proto +++ b/tests/regression/issue_125/extensionbug.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message Message1 { optional uint32 fieldA = 1; diff --git a/tests/regression/issue_141/testproto.proto b/tests/regression/issue_141/testproto.proto index 21598b45..a445c68a 100644 --- a/tests/regression/issue_141/testproto.proto +++ b/tests/regression/issue_141/testproto.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message SubMessage diff --git a/tests/regression/issue_145/comments.proto b/tests/regression/issue_145/comments.proto index 4e86b302..621779f5 100644 --- a/tests/regression/issue_145/comments.proto +++ b/tests/regression/issue_145/comments.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message DummyMessage { required string foo = 1; required string bar = 2; diff --git a/tests/regression/issue_166/enums.proto b/tests/regression/issue_166/enums.proto index a0964ab4..36948044 100644 --- a/tests/regression/issue_166/enums.proto +++ b/tests/regression/issue_166/enums.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + enum SignedEnum { SE_MIN = -1; SE_MAX = 255; diff --git a/tests/special_characters/funny-proto+name has.characters.proto b/tests/special_characters/funny-proto+name has.characters.proto index e69de29b..26b2cb1b 100644 --- a/tests/special_characters/funny-proto+name has.characters.proto +++ b/tests/special_characters/funny-proto+name has.characters.proto @@ -0,0 +1 @@ +syntax="proto2"; |