Add syntax specification to .proto files (issue #167)
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sun, 20 Sep 2015 11:12:19 +0000 (14:12 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sun, 20 Sep 2015 11:29:39 +0000 (14:29 +0300)
Eliminates a warning on protoc 3.0.

33 files changed:
examples/cmake_simple/simple.proto
examples/network_server/fileproto.proto
examples/simple/simple.proto
examples/using_double_on_avr/doubleproto.proto
examples/using_union_messages/unionproto.proto
tests/alltypes/alltypes.proto
tests/backwards_compatibility/alltypes_legacy.proto
tests/callbacks/callbacks.proto
tests/common/person.proto
tests/common/unittestproto.proto
tests/cyclic_messages/cyclic.proto
tests/enum_sizes/enumsizes.proto
tests/extensions/extensions.proto
tests/field_size_16/alltypes.proto
tests/field_size_32/alltypes.proto
tests/fuzztest/SConscript
tests/intsizes/intsizes.proto
tests/message_sizes/messages1.proto
tests/message_sizes/messages2.proto
tests/missing_fields/missing_fields.proto
tests/multiple_files/multifile1.proto
tests/multiple_files/multifile2.proto
tests/no_messages/no_messages.proto
tests/oneof/oneof.proto
tests/options/options.proto
tests/package_name/SConscript
tests/regression/issue_118/enumdef.proto
tests/regression/issue_118/enumuse.proto
tests/regression/issue_125/extensionbug.proto
tests/regression/issue_141/testproto.proto
tests/regression/issue_145/comments.proto
tests/regression/issue_166/enums.proto
tests/special_characters/funny-proto+name has.characters.proto

index 26e72f4..5c73a3b 100644 (file)
@@ -1,6 +1,8 @@
 // A very simple protocol definition, consisting of only
 // one message.
 
+syntax = "proto2";
+
 message SimpleMessage {
     required int32 lucky_number = 1;
 }
index 3e70c49..5640b8d 100644 (file)
@@ -2,6 +2,8 @@
 //
 // See also the nanopb-specific options in fileproto.options.
 
+syntax = "proto2";
+
 message ListFilesRequest {
     optional string path = 1 [default = "/"];
 }
index 26e72f4..5c73a3b 100644 (file)
@@ -1,6 +1,8 @@
 // A very simple protocol definition, consisting of only
 // one message.
 
+syntax = "proto2";
+
 message SimpleMessage {
     required int32 lucky_number = 1;
 }
index d8b7f2d..72d3f9c 100644 (file)
@@ -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;
index d7c9de2..209df0d 100644 (file)
@@ -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;
index 28eaf0b..3995c55 100644 (file)
@@ -1,3 +1,6 @@
+syntax = "proto2";
+// package name placeholder
+
 message SubMessage {
     required string substuff1 = 1 [default = "1"];
     required int32 substuff2 = 2 [default = 2];
index d7631eb..f5bc35c 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message SubMessage {
     required string substuff1 = 1 [default = "1"];
     required int32 substuff2 = 2 [default = 2];
index ccd1edd..96ac744 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message SubMessage {
     optional string stringvalue = 1;
     repeated int32 int32value = 2;
index dafcf93..becefdf 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import "nanopb.proto";
 
 message Person {
index 0ecb1f0..23b5b97 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'nanopb.proto';
 
 message IntegerArray {
index a9d158c..8cab0b1 100644 (file)
@@ -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;
index f9ab0b7..a85d416 100644 (file)
@@ -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;
index 79c0124..fcd5b43 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'alltypes.proto';
 
 extend AllTypes {
index 039391f..ba1ec38 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message SubMessage {
     required string substuff1 = 1 [default = "1"];
     required int32 substuff2 = 2 [default = 2];
index 5749e0d..02ee1a6 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message SubMessage {
     required string substuff1 = 1 [default = "1"];
     required int32 substuff2 = 2 [default = 2];
index 35b697f..973148c 100644 (file)
@@ -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"])
index 236bf18..91444d4 100644 (file)
@@ -6,6 +6,8 @@
  * otherwise. E.g. uint32 + IS_8 => uint8_t
  */
 
+syntax = "proto2";
+
 import 'nanopb.proto';
 
 message IntSizes {
index 48af55a..b66fad7 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 enum MessageStatus {
     FAIL = 0;
     OK = 1;
index 19fc11e..6761408 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'nanopb.proto';
 import 'messages1.proto';
 
index cbb23ba..cc5e550 100644 (file)
@@ -1,5 +1,7 @@
 /* Test for one missing field among many */
 
+syntax = "proto2";
+
 message AllFields
 {
     required int32 field1 = 1;
index d804b67..18f2c67 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message SubMessage {
     optional string stringvalue = 1;
     repeated int32 int32value = 2;
index 66cb8a0..4af45fd 100644 (file)
@@ -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 {
index 279216b..45bb2e6 100644 (file)
@@ -1,5 +1,7 @@
 /* Test that a file without any messages works. */
 
+syntax = "proto2";
+
 enum Test {
     First = 1;
 }
index 00f1cec..b4fe56f 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'nanopb.proto';
 
 message SubMessage
index b705041..aa722b5 100644 (file)
@@ -2,6 +2,8 @@
  * options.expected lists the patterns that are searched for in the output.
  */
 
+syntax = "proto2";
+
 import "nanopb.proto";
 
 // File level options
index 897bc99..4afc503 100644 (file)
@@ -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"])
 
index 830d298..46845bc 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'nanopb.proto';
 
 enum MyEnum {
index d778fb8..4afc452 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'enumdef.proto';
 
 message MyMessage {
index c4ac686..fd1e74f 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message Message1
 {
        optional uint32 fieldA = 1;
index 21598b4..a445c68 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 import 'nanopb.proto';
 
 message SubMessage
index 4e86b30..621779f 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 message DummyMessage {
     required string foo = 1;
     required string bar = 2;
index a0964ab..3694804 100644 (file)
@@ -1,3 +1,5 @@
+syntax = "proto2";
+
 enum SignedEnum {
     SE_MIN = -1;
     SE_MAX = 255;