px4events: add @skip-file tag

This commit is contained in:
Beat Küng
2022-09-20 09:06:39 +02:00
committed by Daniel Agar
parent 54c97db8b2
commit e8ac9b266b
3 changed files with 15 additions and 6 deletions
+11 -5
View File
@@ -92,7 +92,7 @@ class SourceParser(object):
re_comment_start = re.compile(r'^\/\*\s*EVENT$') re_comment_start = re.compile(r'^\/\*\s*EVENT$')
re_events_send = re.compile(r'^events::send[<\(]') re_events_send = re.compile(r'^events::send[<\(]')
re_comment_content = re.compile(r'^\*\s*(.*)') re_comment_content = re.compile(r'^\*\s*(.*)')
re_comment_tag = re.compile(r'^@([a-zA-Z][a-zA-Z0-9_]*):?\s*(.*)') re_comment_tag = re.compile(r'^@([a-zA-Z][a-zA-Z0-9_-]*):?\s*(.*)')
re_comment_end = re.compile(r'(.*?)\s*\*\/$') re_comment_end = re.compile(r'(.*?)\s*\*\/$')
re_code_end = re.compile(r'(.*?)\s*;$') re_code_end = re.compile(r'(.*?)\s*;$')
re_template_args = re.compile(r'([a-zA-Z0-9_:\.]+)\s*<([a-zA-Z0-9_,\s:]+)\s*>\s*\((.*)\);$') re_template_args = re.compile(r'([a-zA-Z0-9_:\.]+)\s*<([a-zA-Z0-9_,\s:]+)\s*>\s*\((.*)\);$')
@@ -107,7 +107,7 @@ class SourceParser(object):
""" dict of 'group': [Event] list """ """ dict of 'group': [Event] list """
return self._events return self._events
def Parse(self, contents): def Parse(self, contents, path):
""" """
Incrementally parse program contents and append all found events Incrementally parse program contents and append all found events
to the list. to the list.
@@ -117,7 +117,7 @@ class SourceParser(object):
# names. # names.
state = None state = None
def finalize_current_tag(event, tag, value): def finalize_current_tag(event, tag, value):
if tag is None: return if tag is None: return True
if tag == "description": if tag == "description":
descr = value.strip() descr = value.strip()
# merge continued lines (but not e.g. enumerations) # merge continued lines (but not e.g. enumerations)
@@ -133,6 +133,9 @@ class SourceParser(object):
"If this is not a typo, add the new group to the script".format(event.group, known_groups)) "If this is not a typo, add the new group to the script".format(event.group, known_groups))
elif tag == "type": elif tag == "type":
event.type = value.strip() event.type = value.strip()
elif tag == "skip-file":
print("Skipping file: {:}".format(path))
return False
elif tag.startswith("arg"): elif tag.startswith("arg"):
arg_index = int(tag[3:])-1 arg_index = int(tag[3:])-1
arg_name = value.strip() arg_name = value.strip()
@@ -140,6 +143,7 @@ class SourceParser(object):
event.add_argument(None, arg_name) event.add_argument(None, arg_name)
else: else:
raise Exception("Invalid tag: {}\nvalue: {}".format(tag, value)) raise Exception("Invalid tag: {}\nvalue: {}".format(tag, value))
return True
for line in self.re_split_lines.split(contents): for line in self.re_split_lines.split(contents):
line = line.strip() line = line.strip()
@@ -267,7 +271,8 @@ class SourceParser(object):
comment_content = m.group(1) comment_content = m.group(1)
m = self.re_comment_tag.match(comment_content) m = self.re_comment_tag.match(comment_content)
if m: if m:
finalize_current_tag(event, current_tag, current_value) if not finalize_current_tag(event, current_tag, current_value):
return True # skip file
current_tag, current_value = m.group(1, 2) current_tag, current_value = m.group(1, 2)
elif current_tag is not None: elif current_tag is not None:
current_value += "\n"+comment_content current_value += "\n"+comment_content
@@ -277,7 +282,8 @@ class SourceParser(object):
# "*" or "*/". # "*" or "*/".
raise Exception("Excpected a comment, got '{}'".format(line)) raise Exception("Excpected a comment, got '{}'".format(line))
if last_comment_line: if last_comment_line:
finalize_current_tag(event, current_tag, current_value) if not finalize_current_tag(event, current_tag, current_value):
return True # skip file
state = "parse-command" state = "parse-command"
return True return True
+1 -1
View File
@@ -46,7 +46,7 @@ class SourceScanner(object):
print('Failed reading file: %s, skipping content.' % path) print('Failed reading file: %s, skipping content.' % path)
pass pass
try: try:
return parser.Parse(contents) return parser.Parse(contents, path)
except Exception as e: except Exception as e:
print("Exception while parsing file {}".format(path)) print("Exception while parsing file {}".format(path))
raise raise
@@ -43,6 +43,9 @@ using namespace time_literals;
// to run: make tests TESTFILTER=HealthAndArmingChecks // to run: make tests TESTFILTER=HealthAndArmingChecks
/* EVENT
* @skip-file
*/
class ReporterTest : public ::testing::Test class ReporterTest : public ::testing::Test