From: Petteri Aimonen Date: Fri, 3 Apr 2015 17:43:13 +0000 (+0300) Subject: Improve comment support in .options files. X-Git-Tag: 5.0.2~186^2~139 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=88f2dc5810b88f88b516bb6f11fc3cba1c255655;p=apps%2Fagl-service-can-low-level.git Improve comment support in .options files. Update issue 145 Status: FixedInGit --- diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index eebe5404..b1ee04e0 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -4,6 +4,7 @@ nanopb_version = "nanopb-0.3.3-dev" import sys +import re try: # Add some dummy imports to keep packaging tools happy. @@ -1164,9 +1165,13 @@ def read_options_file(infile): [(namemask, options), ...] ''' results = [] - for i, line in enumerate(infile): + data = infile.read() + data = re.sub('/\*.*?\*/', '', data, flags = re.MULTILINE) + data = re.sub('//.*?$', '', data, flags = re.MULTILINE) + data = re.sub('#.*?$', '', data, flags = re.MULTILINE) + for i, line in enumerate(data.split('\n')): line = line.strip() - if not line or line.startswith('//') or line.startswith('#'): + if not line: continue parts = line.split(None, 1) diff --git a/tests/regression/issue_145/SConscript b/tests/regression/issue_145/SConscript new file mode 100644 index 00000000..0b793a7a --- /dev/null +++ b/tests/regression/issue_145/SConscript @@ -0,0 +1,9 @@ +# Regression test for Issue 145: Allow /* */ and // comments in .options files + +Import("env") + +env.NanopbProto(["comments", "comments.options"]) +env.Object('comments.pb.c') + +env.Match(['comments.pb.h', 'comments.expected']) + diff --git a/tests/regression/issue_145/comments.expected b/tests/regression/issue_145/comments.expected new file mode 100644 index 00000000..7f874587 --- /dev/null +++ b/tests/regression/issue_145/comments.expected @@ -0,0 +1,3 @@ +char foo\[5\]; +char bar\[16\]; + diff --git a/tests/regression/issue_145/comments.options b/tests/regression/issue_145/comments.options new file mode 100644 index 00000000..89959ba2 --- /dev/null +++ b/tests/regression/issue_145/comments.options @@ -0,0 +1,6 @@ +/* Block comment */ +# Line comment +// Line comment +DummyMessage.foo /* Block comment */ max_size:5 +DummyMessage.bar max_size:16 # Line comment ### + diff --git a/tests/regression/issue_145/comments.proto b/tests/regression/issue_145/comments.proto new file mode 100644 index 00000000..4e86b302 --- /dev/null +++ b/tests/regression/issue_145/comments.proto @@ -0,0 +1,5 @@ +message DummyMessage { + required string foo = 1; + required string bar = 2; +} +