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(a)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(a)'.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(a)-structs'.format(proto['name'])),
+ '--regenerate',
+ ],
+ env: runutf8,
+ depends: [ lib ])
endforeach
endif
endif
--
2.48.1