mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-29 05:13:54 -06:00
qapi: Fix code generation for sub-modules in other directories
The #include directives to pull in sub-modules use file names relative
to the main module. Works only when all modules are in the same
directory, or the main module's output directory is in the compiler's
include path. Use relative file names instead.
The dummy variable we generate to avoid empty .o files has an invalid
name for sub-modules in other directories. Fix that.
Both messed up in commit 252dc3105f
"qapi: Generate separate .h, .c
for each module". Escaped testing because tests/qapi-schema-test.json
doesn't cover sub-modules in other directories, only
tests/qapi-schema/include-relpath.json does, and we generate and
compile C code only for the former, not the latter. Fold the latter
into the former. This would have caught the mistakes fixed in this
commit.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190301154051.23317-5-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
dddee4d7ba
commit
709395f8f6
13 changed files with 91 additions and 42 deletions
|
@ -2017,8 +2017,8 @@ def mcgen(code, **kwds):
|
|||
return cgen(code, **kwds)
|
||||
|
||||
|
||||
def guardname(filename):
|
||||
return re.sub(r'[^A-Za-z0-9_]', '_', filename).upper()
|
||||
def c_fname(filename):
|
||||
return re.sub(r'[^A-Za-z0-9_]', '_', filename)
|
||||
|
||||
|
||||
def guardstart(name):
|
||||
|
@ -2027,7 +2027,7 @@ def guardstart(name):
|
|||
#define %(name)s
|
||||
|
||||
''',
|
||||
name=guardname(name))
|
||||
name=c_fname(name).upper())
|
||||
|
||||
|
||||
def guardend(name):
|
||||
|
@ -2035,7 +2035,7 @@ def guardend(name):
|
|||
|
||||
#endif /* %(name)s */
|
||||
''',
|
||||
name=guardname(name))
|
||||
name=c_fname(name).upper())
|
||||
|
||||
|
||||
def gen_if(ifcond):
|
||||
|
@ -2281,9 +2281,9 @@ class QAPIGenC(QAPIGenCCode):
|
|||
return mcgen('''
|
||||
|
||||
/* Dummy declaration to prevent empty .o file */
|
||||
char dummy_%(name)s;
|
||||
char qapi_dummy_%(name)s;
|
||||
''',
|
||||
name=c_name(self.fname))
|
||||
name=c_fname(self.fname))
|
||||
|
||||
|
||||
class QAPIGenH(QAPIGenC):
|
||||
|
@ -2337,21 +2337,29 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
|
|||
def _is_builtin_module(name):
|
||||
return not name
|
||||
|
||||
def _module_dirname(self, what, name):
|
||||
if self._is_user_module(name):
|
||||
return os.path.dirname(name)
|
||||
return ''
|
||||
|
||||
def _module_basename(self, what, name):
|
||||
ret = '' if self._is_builtin_module(name) else self._prefix
|
||||
if self._is_user_module(name):
|
||||
dirname, basename = os.path.split(name)
|
||||
basename = os.path.basename(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 _module_filename(self, what, name):
|
||||
return os.path.join(self._module_dirname(what, name),
|
||||
self._module_basename(what, name))
|
||||
|
||||
def _add_module(self, name, blurb):
|
||||
basename = self._module_basename(self._what, name)
|
||||
basename = self._module_filename(self._what, name)
|
||||
genc = QAPIGenC(basename + '.c', blurb, self._pydoc)
|
||||
genh = QAPIGenH(basename + '.h', blurb, self._pydoc)
|
||||
self._module[name] = (genc, genh)
|
||||
|
@ -2393,8 +2401,9 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
|
|||
self._begin_user_module(name)
|
||||
|
||||
def visit_include(self, name, info):
|
||||
basename = self._module_basename(self._what, name)
|
||||
relname = os.path.relpath(self._module_filename(self._what, name),
|
||||
os.path.dirname(self._genh.fname))
|
||||
self._genh.preamble_add(mcgen('''
|
||||
#include "%(basename)s.h"
|
||||
#include "%(relname)s.h"
|
||||
''',
|
||||
basename=basename))
|
||||
relname=relname))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue