scripts: group-qemu-caps: Add capability name as comment to capability string

Add a cross reference of the enum value name with the string
representation. This allows a quick cross-reference of the values
without having to open the header and implementation files separately.

To achieve this the checker code at first obtains a list of the
flags and cross-references them when checking the grouping in
syntax-check, thus we are guaranteed to stay in sync.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa
2021-07-27 13:14:51 +02:00
parent 0a8e44bc9f
commit 42e7f6a35b
2 changed files with 448 additions and 411 deletions

View File

@@ -27,8 +27,33 @@ import subprocess
import sys
def load_caps_flags(filename, start_regex, end_regex):
capsflags = []
game_on = False
with open(filename, "r") as fh:
for line in fh:
line = line.rstrip("\n")
if game_on:
if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
continue
if re.search(r'''^\s*$''', line):
continue
match = re.search(r'''[ ]+([A-Z0-9_]+)''', line)
if match:
capsflags.append(match[1])
if re.search(start_regex, line):
game_on = True
elif game_on and re.search(end_regex, line):
game_on = False
return capsflags
def regroup_caps(check, filename, start_regex, end_regex,
trailing_newline, counter_prefix):
trailing_newline, counter_prefix, capsflags):
step = 5
original = []
@@ -68,6 +93,12 @@ def regroup_caps(check, filename, start_regex, end_regex,
game_on = False
# ensure that flag names in the .c file have the correct flag in the comment
if game_on and capsflags:
flagname = re.search(r'''.*".*",''', line)
if flagname:
line = flagname[0] + " /* %s */" % capsflags[counter - 1]
fixed.append(line + "\n")
if check:
@@ -100,12 +131,17 @@ args = parser.parse_args()
errs = False
capsflags = load_caps_flags(args.prefix + 'src/qemu/qemu_capabilities.h',
r'virQEMUCapsFlags grouping marker',
r'QEMU_CAPS_LAST \/\* this must')
if not regroup_caps(args.check,
args.prefix + 'src/qemu/qemu_capabilities.c',
r'virQEMUCaps grouping marker',
r'\);',
0,
" "):
" ",
capsflags):
errs = True
if not regroup_caps(args.check,
@@ -113,7 +149,8 @@ if not regroup_caps(args.check,
r'virQEMUCapsFlags grouping marker',
r'QEMU_CAPS_LAST \/\* this must',
1,
" "):
" ",
None):
errs = True
if errs: