aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/common.py
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-02-18 14:23:13 +0000
committerPeter Maydell <peter.maydell@linaro.org>2019-02-18 14:23:13 +0000
commita0430dd8abb8a2f31c5ee919daab2e3d76353c04 (patch)
tree601f2da2585768ec18e5201bda9acbf0c0bbe021 /scripts/qapi/common.py
parent1c5d9d8f111b9cfc0722c7edcdc3b090736972e5 (diff)
parent183e4281a30962729b760dfe8bed5aab27238b0c (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2019-02-18' into staging
QAPI patches for 2019-02-18 # gpg: Signature made Mon 18 Feb 2019 13:44:30 GMT # gpg: using RSA key 3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2019-02-18: qapi: move RTC_CHANGE to the target schema qmp: Deprecate query-events in favor of query-qmp-schema Revert "qapi-events: add 'if' condition to implicit event enum" qapi: remove qmp_unregister_command() qapi: make query-cpu-definitions depend on specific targets qapi: make query-cpu-model-expansion depend on s390 or x86 qapi: make query-gic-capabilities depend on TARGET_ARM target.json: add a note about query-cpu* not being s390x-specific qapi: make s390 commands depend on TARGET_S390X qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386 qapi: New module target.json build: Deal with all of QAPI's .o in qapi/Makefile.objs build-sys: move qmp-introspect per target qapi: Generate QAPIEvent stuff into separate files qapi: Prepare for system modules other than 'builtin' qapi: Clean up modular built-in code generation a bit qapi: Fix up documentation for recent commit a95291007b2 qapi: Belatedly document modular code generation Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts/qapi/common.py')
-rw-r--r--scripts/qapi/common.py55
1 files changed, 41 insertions, 14 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index c89edc0cb0..c327ae5036 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1868,6 +1868,7 @@ class QAPISchema(object):
def visit(self, visitor):
visitor.visit_begin(self)
module = None
+ visitor.visit_module(module)
for entity in self._entity_list:
if visitor.visit_needed(entity):
if entity.module != module:
@@ -2321,47 +2322,73 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
self._what = what
self._blurb = blurb
self._pydoc = pydoc
+ self._genc = None
+ self._genh = None
self._module = {}
self._main_module = None
+ @staticmethod
+ def _is_user_module(name):
+ return name and not name.startswith('./')
+
+ @staticmethod
+ def _is_builtin_module(name):
+ return not name
+
def _module_basename(self, what, name):
- if name is None:
- return re.sub(r'-', '-builtin-', what)
- basename = os.path.join(os.path.dirname(name),
- self._prefix + what)
- if name == self._main_module:
- return basename
- return basename + '-' + os.path.splitext(os.path.basename(name))[0]
+ ret = '' if self._is_builtin_module(name) else self._prefix
+ if self._is_user_module(name):
+ dirname, basename = os.path.split(name)
+ ret += what
+ if name != self._main_module:
+ ret += '-' + os.path.splitext(basename)[0]
+ ret = os.path.join(dirname, ret)
+ else:
+ name = name[2:] if name else 'builtin'
+ ret += re.sub(r'-', '-' + name + '-', what)
+ return ret
def _add_module(self, name, blurb):
- if self._main_module is None and name is not None:
- self._main_module = name
genc = QAPIGenC(blurb, self._pydoc)
genh = QAPIGenH(blurb, self._pydoc)
self._module[name] = (genc, genh)
self._set_module(name)
+ def _add_user_module(self, name, blurb):
+ assert self._is_user_module(name)
+ if self._main_module is None:
+ self._main_module = name
+ self._add_module(name, blurb)
+
+ def _add_system_module(self, name, blurb):
+ self._add_module(name and './' + name, blurb)
+
def _set_module(self, name):
self._genc, self._genh = self._module[name]
def write(self, output_dir, opt_builtins=False):
for name in self._module:
- if name is None and not opt_builtins:
+ if self._is_builtin_module(name) and not opt_builtins:
continue
basename = self._module_basename(self._what, name)
(genc, genh) = self._module[name]
genc.write(output_dir, basename + '.c')
genh.write(output_dir, basename + '.h')
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
pass
def visit_module(self, name):
if name in self._module:
self._set_module(name)
- return
- self._add_module(name, self._blurb)
- self._begin_module(name)
+ elif self._is_builtin_module(name):
+ # The built-in module has not been created. No code may
+ # be generated.
+ self._genc = None
+ self._genh = None
+ else:
+ self._add_user_module(name, self._blurb)
+ self._begin_user_module(name)
def visit_include(self, name, info):
basename = self._module_basename(self._what, name)