[PATCH 0/2] src: make it easier to updat the protocol structs files

This introduces a new target: ninja -C build regen-admin_protocol and equiv for other protocol files Daniel P. Berrangé (2): src: normalize whitespace in protocol structs files src: add new target for regenerating protocol structs files scripts/check-remote-protocol.py | 27 ++++++++++++++++++++++++++- src/admin_protocol-structs | 2 +- src/meson.build | 14 ++++++++++++++ src/qemu_protocol-structs | 2 +- src/remote_protocol-structs | 6 +++--- 5 files changed, 45 insertions(+), 6 deletions(-) -- 2.48.1

This makes the output match what current pdwtags will emit, modulo some whitespace changes made by the check script before comparison. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/admin_protocol-structs | 2 +- src/qemu_protocol-structs | 2 +- src/remote_protocol-structs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs index 8caac59824..f6988cf76d 100644 --- a/src/admin_protocol-structs +++ b/src/admin_protocol-structs @@ -167,5 +167,5 @@ enum admin_procedure { ADMIN_PROC_CONNECT_SET_LOGGING_OUTPUTS = 16, ADMIN_PROC_CONNECT_SET_LOGGING_FILTERS = 17, ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18, - ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19, + ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19, }; diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs index ea0854385f..7c78e5ab5a 100644 --- a/src/qemu_protocol-structs +++ b/src/qemu_protocol-structs @@ -62,5 +62,5 @@ enum qemu_procedure { QEMU_PROC_CONNECT_DOMAIN_MONITOR_EVENT_REGISTER = 4, QEMU_PROC_CONNECT_DOMAIN_MONITOR_EVENT_DEREGISTER = 5, QEMU_PROC_DOMAIN_MONITOR_EVENT = 6, - QEMU_PROC_DOMAIN_MONITOR_COMMAND_WITH_FILES = 7, + QEMU_PROC_DOMAIN_MONITOR_COMMAND_WITH_FILES = 7, }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 4d3dc2d249..ed7e2fbcb0 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -569,7 +569,7 @@ struct remote_domain_save_params_args { u_int params_len; remote_typed_param * params_val; } params; - u_int flags; + u_int flags; }; struct remote_domain_restore_args { remote_nonnull_string from; @@ -1115,7 +1115,7 @@ struct remote_network_create_xml_ret { }; struct remote_network_create_xml_flags_args { remote_nonnull_string xml; - u_int flags; + u_int flags; }; struct remote_network_create_xml_flags_ret { remote_nonnull_network net; @@ -1128,7 +1128,7 @@ struct remote_network_define_xml_ret { }; struct remote_network_define_xml_flags_args { remote_nonnull_string xml; - u_int flags; + u_int flags; }; struct remote_network_define_xml_flags_ret { remote_nonnull_network net; -- 2.48.1

On Thu, Mar 13, 2025 at 03:57:36PM +0000, Daniel P. Berrangé wrote:
This makes the output match what current pdwtags will emit, modulo some whitespace changes made by the check script before comparison.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

Introduce a new ninja target ninja -C build regen-{PROTO} eg ninja -C build regen-admin_protocol that will re-create the reference output file based on what the current pdwtags command emits. A small change is made to squash whitespace on enum declarations so that introducing a new longer enum name dosn't trigger re-indent of all existing enum names. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- scripts/check-remote-protocol.py | 27 ++++++++++++++++++++++++++- src/meson.build | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/scripts/check-remote-protocol.py b/scripts/check-remote-protocol.py index 40c4b481be..9de0a4a93d 100644 --- a/scripts/check-remote-protocol.py +++ b/scripts/check-remote-protocol.py @@ -36,6 +36,9 @@ targetname = sys.argv[2] libpath = sys.argv[3] pdwtags = sys.argv[4] expected = sys.argv[5] +regen = False +if len(sys.argv) == 7 and sys.argv[6] == "--regenerate": + regen = True builddir = os.path.dirname(libpath) libname = os.path.basename(libpath) @@ -128,7 +131,29 @@ actualstr = "\n".join(actual) + "\n" # know our RPC structs are suitably aligned to not need # packing, so we can just trim the attribute. actualstr = re.sub(r'''} __attribute__\(\(__packed__\)\);''', "};", actualstr) +actualstr = re.sub(r'''([A-Z0-9]+)\s+=\s+(\d)''', r'''\1 = \2''', actualstr) diff.communicate(input=actualstr.encode("utf-8")) -sys.exit(diff.returncode) +if diff.returncode != 0: + if regen: + with open(expected, "w") as fh: + print(actualstr, file=fh, end='') + + print("") + print("WARNING: reference output was re-generated to apply") + print("WARNING: the above diff. Validate the changes are") + print("WARNING: expected and correct before committing") + print("") + sys.exit(0) + else: + print("") + print("WARNING: validate the above protocol changes are") + print("WARNING: expected and correct. To re-generate the") + print("WARNING: reference output invoke") + print("") + print(" $ ninja regen-%s" % name) + + sys.exit(diff.returncode) +else: + sys.exit(0) diff --git a/src/meson.build b/src/meson.build index 9413192a55..9a818dab50 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1088,6 +1088,20 @@ if tests_enabled[0] depends: [ lib ], suite: 'script' ) + + run_target( + 'regen-@0@'.format(proto['name']), + command: [python3_prog, + check_remote_protocol_prog.full_path(), + proto['name'], + lib.name(), + lib.full_path(), + pdwtags_prog.full_path(), + files('@0@-structs'.format(proto['name'])), + '--regenerate', + ], + env: runutf8, + depends: [ lib ]) endforeach endif endif -- 2.48.1

On Thu, Mar 13, 2025 at 03:57:37PM +0000, Daniel P. Berrangé wrote:
Introduce a new ninja target
ninja -C build regen-{PROTO}
eg
ninja -C build regen-admin_protocol
that will re-create the reference output file based on what the current pdwtags command emits. A small change is made to squash whitespace on enum declarations so that introducing a new longer enum name dosn't trigger re-indent of all existing enum names.
s/dos/does/ Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
participants (2)
-
Daniel P. Berrangé
-
Martin Kletzander