diff mbox series

[05/14] qapi: stop hardcoding list of special features

Message ID 20240604153242.251334-6-berrange@redhat.com (mailing list archive)
State New, archived
Headers show
Series Improve mechanism for configuring allowed commands | expand

Commit Message

Daniel P. Berrangé June 4, 2024, 3:32 p.m. UTC
Use the additional list of special features for commands, previously
defined by a pragma, to augment the standard 'unstable' and 'deprecated'
ones.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/qapi/schema.py | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 721c470d2b..b83a9bdcb7 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -932,8 +932,18 @@  def connect_doc(self, doc: Optional[QAPIDoc]) -> None:
 class QAPISchemaFeature(QAPISchemaMember):
     role = 'feature'
 
+    def __init__(
+        self,
+        name: str,
+        info: Optional[QAPISourceInfo],
+        ifcond: Optional[QAPISchemaIfCond] = None,
+        special: bool = False,
+    ):
+        super().__init__(name, info, ifcond)
+        self.special = special
+
     def is_special(self) -> bool:
-        return self.name in ('deprecated', 'unstable')
+        return self.special
 
 
 class QAPISchemaObjectTypeMember(QAPISchemaMember):
@@ -1143,6 +1153,9 @@  def __init__(self, fname: str):
         self._predefining = True
         self._def_predefineds()
         self._predefining = False
+        self._custom_special_features: Dict[str, List[str]] = {
+            'command': parser.info.pragma.command_features
+        }
         self._def_exprs(exprs)
         self.check()
 
@@ -1254,12 +1267,21 @@  def _make_features(
         self,
         features: Optional[List[Dict[str, Any]]],
         info: Optional[QAPISourceInfo],
+        custom_special_features: Optional[List[str]] = [],
     ) -> List[QAPISchemaFeature]:
         if features is None:
             return []
-        return [QAPISchemaFeature(f['name'], info,
-                                  QAPISchemaIfCond(f.get('if')))
-                for f in features]
+        ret = []
+        for f in features:
+            name = f['name']
+            special = name in ["unstable", "deprecated"]
+            if custom_special_features is not None:
+                if name in custom_special_features:
+                    special = True
+            ret.append(QAPISchemaFeature(name, info,
+                                         QAPISchemaIfCond(f.get('if')),
+                                         special))
+        return ret
 
     def _make_enum_member(
         self,
@@ -1430,7 +1452,8 @@  def _def_command(self, expr: QAPIExpression) -> None:
         coroutine = expr.get('coroutine', False)
         ifcond = QAPISchemaIfCond(expr.get('if'))
         info = expr.info
-        features = self._make_features(expr.get('features'), info)
+        features = self._make_features(expr.get('features'), info,
+                                       self._custom_special_features['command'])
         if isinstance(data, OrderedDict):
             data = self._make_implicit_object_type(
                 name, info, ifcond,