mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
xen-analysis.py: Use named group for tag regex
Use named group for the regex matching a tag identifier, this is done to ease retrieving the matching group instead of using an index. Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
1 parent
8c5e4ce145
commit
ddd6696fc6
3 files changed
+15
-15
No files matched your search
@@ -41,7 +41,7 @@ def __generate_suppression_list(out_file):
|
||||
# The following lambda function will return a file if it contains lines with
|
||||
# a comment containing "cppcheck-suppress[*]" on a single line.
|
||||
grep_action = lambda x: utils.grep(x,
|
||||
r'^[ \t]*/\* cppcheck-suppress\[(.*)\] \*/$')
|
||||
r'^[ \t]*/\* cppcheck-suppress\[(?P<id>.*)\] \*/$')
|
||||
# Look for a list of .h files that matches the condition above
|
||||
headers = utils.recursive_find_file(settings.xen_dir, r'.*\.h$',
|
||||
grep_action)
|
||||
@@ -97,7 +97,7 @@ def __generate_suppression_list(out_file):
|
||||
if (not comment_section) and comment_line_starts:
|
||||
comment_section = True
|
||||
if (len(line.strip()) != 0) and (not comment_section):
|
||||
cppcheck_violation_id = entry["matches"][line_num][0]
|
||||
cppcheck_violation_id = entry["matches"][line_num]['id']
|
||||
break
|
||||
if comment_section and comment_line_stops:
|
||||
comment_section = False
|
||||
|
||||
@@ -18,11 +18,12 @@ tool_syntax = {
|
||||
|
||||
|
||||
def get_xen_tag_index_type_regex(tool):
|
||||
return r'^SAF-(\d+)-(safe|false-positive-' + tool + ')$'
|
||||
return rf'^SAF-(?P<id>\d+)-(?P<type>safe|false-positive-{tool})$'
|
||||
|
||||
|
||||
def get_xen_tag_comment_regex(tool):
|
||||
return r'^[ \t]*/\* +(SAF-\d+-(?:safe|false-positive-' + tool + ')).*\*/$'
|
||||
tag=rf'(?P<tag>SAF-\d+-(?:safe|false-positive-{tool}))'
|
||||
return rf'^[ \t]*/\* +{tag}.*\*/$'
|
||||
|
||||
|
||||
# Returns a data structure containing dictionaries for safe and false-positive-*
|
||||
@@ -60,12 +61,11 @@ def load_tag_database(tool, input_files, data_struct = None, schema = "safe"):
|
||||
if proprietary_id != "":
|
||||
comment=tool_syntax[tool].replace("VID",proprietary_id)
|
||||
# Regex to capture the index of the Xen tag and the schema
|
||||
xen_tag = re.compile(get_xen_tag_index_type_regex(tool))\
|
||||
.match(entry["id"])
|
||||
if xen_tag and xen_tag.group(1) and xen_tag.group(2):
|
||||
xen_tag = re.match(get_xen_tag_index_type_regex(tool), entry["id"])
|
||||
if xen_tag and xen_tag.group('id') and xen_tag.group('type'):
|
||||
# Save in safe or false-positive-* the key {#id: "comment"}
|
||||
id_number = int(xen_tag.group(1))
|
||||
key = xen_tag.group(2)
|
||||
id_number = int(xen_tag.group('id'))
|
||||
key = xen_tag.group('type')
|
||||
ret[key][id_number] = "/* {} */\n".format(comment)
|
||||
else:
|
||||
raise TagDatabaseError(
|
||||
@@ -95,11 +95,11 @@ def substitute_tags(tool, input_file, grep_struct, subs_rules):
|
||||
# information access the subs_rules dictionary to see if there is
|
||||
# a match
|
||||
for line_number in grep_struct["matches"]:
|
||||
xen_tag = grep_struct["matches"][line_number][0]
|
||||
xen_tag_regex_obj = re.compile(
|
||||
get_xen_tag_index_type_regex(tool)).match(xen_tag)
|
||||
id_number = int(xen_tag_regex_obj.group(1))
|
||||
key = xen_tag_regex_obj.group(2)
|
||||
xen_tag = grep_struct["matches"][line_number]['tag']
|
||||
xen_tag_regex_obj = re.match(get_xen_tag_index_type_regex(tool),
|
||||
xen_tag)
|
||||
id_number = int(xen_tag_regex_obj.group('id'))
|
||||
key = xen_tag_regex_obj.group('type')
|
||||
if id_number in subs_rules[key]:
|
||||
parsed_content[line_number-1] = subs_rules[key][id_number]
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def grep(filepath, regex):
|
||||
for line in f:
|
||||
match = regObj.match(line)
|
||||
if match:
|
||||
res["matches"][line_number] = match.groups()
|
||||
res["matches"][line_number] = match
|
||||
line_number = line_number + 1
|
||||
except Exception as e:
|
||||
print("WARNING: Can't open {}: {}".format(filepath, e))
|
||||
|
||||