diff mbox series

[RFC,2/3] qapi: always expose TARGET_* or CONFIG_KVM code

Message ID 20250424183350.1798746-3-pierrick.bouvier@linaro.org
State New
Headers show
Series single-binary: make QAPI generated files common | expand

Commit Message

Pierrick Bouvier April 24, 2025, 6:33 p.m. UTC
As this point, we don't do anything to hide target specific commands, as
the TODO mentions in the commit.

All other CONFIG_* are based on config-host, so we can safely generate
ifdefs.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 scripts/qapi/commands.py | 4 ++++
 scripts/qapi/common.py   | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 79142273828..1dddf008d26 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -405,6 +405,10 @@  def visit_command(self,
             if self._gen_tracing:
                 self._gen_trace_events.add(gen_trace(name))
         with self._temp_module('./init'):
+            # TODO: This if guard should be implemented as a runtime check
+            # instead of #ifdef based ifcond.
+            # "#if TARGET_S390X && CONFIG_KVM" will become:
+            # "if (target_s390x() || kvm_enabled()) {"
             with ifcontext(ifcond, self._genh, self._genc):
                 self._genc.add(gen_register_command(
                     name, features, success_response, allow_oob,
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index d7c8aa3365c..98272653303 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -206,6 +206,8 @@  def gen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]],
     def do_gen(ifcond: Union[str, Dict[str, Any]],
                need_parens: bool) -> str:
         if isinstance(ifcond, str):
+            if ifcond.startswith('TARGET_') or ifcond == 'CONFIG_KVM':
+                return '1 /*' + ifcond + '*/'
             return cond_fmt % ifcond
         assert isinstance(ifcond, dict) and len(ifcond) == 1
         if 'not' in ifcond:
@@ -247,7 +249,7 @@  def gen_endif(cond: str) -> str:
     if not cond:
         return ''
     return mcgen('''
-#endif /* %(cond)s */
+#endif // %(cond)s
 ''', cond=cond)