From: Marc-André Lureau <marcandre.lureau@redhat.com>
Make the resulting code even prettier, if possible.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
scripts/qapi/gen.py | 15 ++++++++++++++-
scripts/qapi/introspect.py | 2 ++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index b5a8d03e8e..c0ec9aa412 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -14,6 +14,7 @@
from contextlib import contextmanager
import os
import re
+import subprocess
from typing import (
Dict,
Iterator,
@@ -133,6 +134,7 @@ def build_params(arg_type: Optional[QAPISchemaObjectType],
class QAPIGenCCode(QAPIGen):
def __init__(self, fname: str):
super().__init__(fname)
+ self.skip_format: bool = False
self._start_if: Optional[Tuple[QAPISchemaIfCond, str, str]] = None
def start_if(self, ifcond: QAPISchemaIfCond) -> None:
@@ -149,7 +151,18 @@ def end_if(self) -> None:
def get_content(self) -> str:
assert self._start_if is None
- return super().get_content()
+
+ text = super().get_content()
+ if not self.skip_format:
+ try:
+ text = subprocess.run(["clang-format"],
+ input=text,
+ text=True,
+ capture_output=True,
+ check=True).stdout
+ except FileNotFoundError:
+ pass
+ return text
class QAPIGenC(QAPIGenCCode):
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 67c7d89aae..1a8cac37ef 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -174,6 +174,8 @@ def __init__(self, prefix: str, unmask: bool):
super().__init__(
prefix, 'qapi-introspect',
' * QAPI/QMP schema introspection', __doc__)
+ # for some reasons, the generated code is making clang-format go crazy
+ self._genc.skip_format = True
self._unmask = unmask
self._schema: Optional[QAPISchema] = None
self._trees: List[Annotated[SchemaInfo]] = []
--
2.39.2