Enable comments generation by default and add test case (#85, #645)
Comments from .proto file are now included automatically when .proto
file is passed directly to nanopb_generator.py, and also when using
protoc --nanopb_out=. When using --descriptor_out=, --include_source_info
will need to be added to protoc command line.
Added a simple test case for the comment generation.
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 485f5c9..cc4ed40 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -2190,7 +2190,7 @@
if filename.endswith(".proto"):
with TemporaryDirectory() as tmpdir:
tmpname = os.path.join(tmpdir, os.path.basename(filename) + ".pb")
- status = invoke_protoc(["protoc"] + include_path + ['--include_imports', '-o' + tmpname, filename])
+ status = invoke_protoc(["protoc"] + include_path + ['--include_imports', '--include_source_info', '-o' + tmpname, filename])
if status != 0: sys.exit(status)
data = open(tmpname, 'rb').read()
else:
diff --git a/tests/comments/SConscript b/tests/comments/SConscript
new file mode 100644
index 0000000..14641f0
--- /dev/null
+++ b/tests/comments/SConscript
@@ -0,0 +1,8 @@
+# Test comment inclusion from .proto to .pb.h
+
+Import("env")
+
+env.NanopbProto("comments")
+env.Object("comments.pb.c")
+env.Match(['comments.pb.h', 'comments.expected'])
+
diff --git a/tests/comments/comments.expected b/tests/comments/comments.expected
new file mode 100644
index 0000000..0017cda
--- /dev/null
+++ b/tests/comments/comments.expected
@@ -0,0 +1,6 @@
+Enum1Comment
+LeadingEnumComment
+ENUMVAL2.*TrailingEnumComment
+Message1Comment
+member2.*TrailingMemberComment
+
diff --git a/tests/comments/comments.proto b/tests/comments/comments.proto
new file mode 100644
index 0000000..e4825c6
--- /dev/null
+++ b/tests/comments/comments.proto
@@ -0,0 +1,17 @@
+syntax = "proto2";
+
+// Message1Comment
+message Message1
+{
+ // LeadingMemberComment
+ required int32 member1 = 1;
+ required int32 member2 = 2; // TrailingMemberComment
+}
+
+// Enum1Comment
+enum Enum1
+{
+ // LeadingEnumComment
+ ENUMVAL1 = 1;
+ ENUMVAL2 = 2; // TrailingEnumComment
+}