From 3277400723e5366edee169e5f611665bff20e61d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 9 Mar 2018 10:28:28 -0500 Subject: [PATCH] qapi: Move qapi-schema.json to qapi/, rename generated files Move qapi-schema.json to qapi/, so it's next to its modules, and all files get generated to qapi/, not just the ones generated for modules. Consistently name the generated files qapi-MODULE.EXT: qmp-commands.[ch] become qapi-commands.[ch], qapi-event.[ch] become qapi-events.[ch], and qmp-introspect.[ch] become qapi-introspect.[ch]. This gets rid of the temporary hacks in scripts/qapi/commands.py, scripts/qapi/events.py, and scripts/qapi/common.py. Backports commit eb815e248f50cde9ab86eddd57eca5019b71ca78 from qemu --- .gitignore | 8 +++---- msvc/unicorn/{ => qapi}/qapi-builtin-types.c | 0 msvc/unicorn/{ => qapi}/qapi-builtin-types.h | 0 msvc/unicorn/{ => qapi}/qapi-builtin-visit.c | 0 msvc/unicorn/{ => qapi}/qapi-builtin-visit.h | 0 msvc/unicorn/{ => qapi}/qapi-types.c | 0 msvc/unicorn/{ => qapi}/qapi-types.h | 0 msvc/unicorn/{ => qapi}/qapi-visit.c | 0 msvc/unicorn/{ => qapi}/qapi-visit.h | 0 msvc/unicorn/unicorn/unicorn.vcxproj | 16 +++++++------- msvc/unicorn/unicorn/unicorn.vcxproj.filters | 16 +++++++------- .../unicorn_static/unicorn_static.vcxproj | 16 +++++++------- .../unicorn_static.vcxproj.filters | 16 +++++++------- qemu/Makefile | 22 +++++++++---------- qemu/Makefile.objs | 8 ++++--- qemu/include/qapi/error.h | 2 +- qemu/include/qapi/qmp/qlit.h | 1 - qemu/include/qapi/qmp/qobject.h | 2 +- qemu/include/qapi/visitor.h | 2 +- qemu/include/qom/object.h | 2 +- qemu/{ => qapi}/qapi-schema.json | 4 ++-- qemu/qom/object.c | 2 +- qemu/scripts/qapi/common.py | 5 ++--- qemu/scripts/qapi/events.py | 9 +------- qemu/scripts/qapi/types.py | 6 ++--- qemu/scripts/qapi/visit.py | 6 ++--- 26 files changed, 68 insertions(+), 75 deletions(-) rename msvc/unicorn/{ => qapi}/qapi-builtin-types.c (100%) rename msvc/unicorn/{ => qapi}/qapi-builtin-types.h (100%) rename msvc/unicorn/{ => qapi}/qapi-builtin-visit.c (100%) rename msvc/unicorn/{ => qapi}/qapi-builtin-visit.h (100%) rename msvc/unicorn/{ => qapi}/qapi-types.c (100%) rename msvc/unicorn/{ => qapi}/qapi-types.h (100%) rename msvc/unicorn/{ => qapi}/qapi-visit.c (100%) rename msvc/unicorn/{ => qapi}/qapi-visit.h (100%) rename qemu/{ => qapi}/qapi-schema.json (97%) diff --git a/.gitignore b/.gitignore index 377e0a28..f71ae210 100644 --- a/.gitignore +++ b/.gitignore @@ -28,13 +28,13 @@ qemu/sparc-softmmu/ qemu/i386-softmmu/ qemu/x86_64-softmmu/ -qemu/qapi-builtin-types.[ch] -qemu/qapi-builtin-visit.[ch] +qemu/qapi/qapi-builtin-types.[ch] +qemu/qapi/qapi-builtin-visit.[ch] qemu/qapi/qapi-types-common.[ch] qemu/qapi/qapi-types-misc.[ch] qemu/qapi/qapi-visit-common.[ch] -qemu/qapi-types.[ch] -qemu/qapi-visit.[ch] +qemu/qapi/qapi-types.[ch] +qemu/qapi/qapi-visit.[ch] qemu/qapi/qapi-visit-misc.[ch] qemu/qapi-gen-timestamp tags diff --git a/msvc/unicorn/qapi-builtin-types.c b/msvc/unicorn/qapi/qapi-builtin-types.c similarity index 100% rename from msvc/unicorn/qapi-builtin-types.c rename to msvc/unicorn/qapi/qapi-builtin-types.c diff --git a/msvc/unicorn/qapi-builtin-types.h b/msvc/unicorn/qapi/qapi-builtin-types.h similarity index 100% rename from msvc/unicorn/qapi-builtin-types.h rename to msvc/unicorn/qapi/qapi-builtin-types.h diff --git a/msvc/unicorn/qapi-builtin-visit.c b/msvc/unicorn/qapi/qapi-builtin-visit.c similarity index 100% rename from msvc/unicorn/qapi-builtin-visit.c rename to msvc/unicorn/qapi/qapi-builtin-visit.c diff --git a/msvc/unicorn/qapi-builtin-visit.h b/msvc/unicorn/qapi/qapi-builtin-visit.h similarity index 100% rename from msvc/unicorn/qapi-builtin-visit.h rename to msvc/unicorn/qapi/qapi-builtin-visit.h diff --git a/msvc/unicorn/qapi-types.c b/msvc/unicorn/qapi/qapi-types.c similarity index 100% rename from msvc/unicorn/qapi-types.c rename to msvc/unicorn/qapi/qapi-types.c diff --git a/msvc/unicorn/qapi-types.h b/msvc/unicorn/qapi/qapi-types.h similarity index 100% rename from msvc/unicorn/qapi-types.h rename to msvc/unicorn/qapi/qapi-types.h diff --git a/msvc/unicorn/qapi-visit.c b/msvc/unicorn/qapi/qapi-visit.c similarity index 100% rename from msvc/unicorn/qapi-visit.c rename to msvc/unicorn/qapi/qapi-visit.c diff --git a/msvc/unicorn/qapi-visit.h b/msvc/unicorn/qapi/qapi-visit.h similarity index 100% rename from msvc/unicorn/qapi-visit.h rename to msvc/unicorn/qapi/qapi-visit.h diff --git a/msvc/unicorn/unicorn/unicorn.vcxproj b/msvc/unicorn/unicorn/unicorn.vcxproj index 535a3f67..17809ca8 100644 --- a/msvc/unicorn/unicorn/unicorn.vcxproj +++ b/msvc/unicorn/unicorn/unicorn.vcxproj @@ -236,14 +236,14 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ - - + + - - + + false false @@ -368,14 +368,14 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ - - + + - - + + diff --git a/msvc/unicorn/unicorn/unicorn.vcxproj.filters b/msvc/unicorn/unicorn/unicorn.vcxproj.filters index ee881a74..cf21bc7d 100644 --- a/msvc/unicorn/unicorn/unicorn.vcxproj.filters +++ b/msvc/unicorn/unicorn/unicorn.vcxproj.filters @@ -129,13 +129,13 @@ qemu\qom - + qemu - + qemu - + qemu @@ -150,7 +150,7 @@ qemu - + qemu @@ -241,13 +241,13 @@ qemu - + qemu - + qemu - + qemu @@ -262,7 +262,7 @@ qemu - + qemu diff --git a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj index 547ab6d9..19a15377 100644 --- a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj +++ b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj @@ -64,12 +64,12 @@ - - + + - - + + @@ -181,14 +181,14 @@ - - + + - - + + {B6EFD6D7-C2D4-4FBB-B363-2E08CE09CC96} diff --git a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters index f038b658..397ad815 100644 --- a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters +++ b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters @@ -199,16 +199,16 @@ qemu\util - + qemu - + qemu - + qemu - + qemu @@ -530,16 +530,16 @@ qemu - + qemu - + qemu - + qemu - + qemu diff --git a/qemu/Makefile b/qemu/Makefile index 9d7abf6c..bad0c41b 100644 --- a/qemu/Makefile +++ b/qemu/Makefile @@ -47,12 +47,12 @@ endif include $(SRC_PATH)/rules.mak GENERATED_FILES = config-host.h -GENERATED_FILES += qapi-builtin-types.h qapi-builtin-types.c -GENERATED_FILES += qapi-types.h qapi-types.c +GENERATED_FILES += qapi/qapi-builtin-types.h qapi/qapi-builtin-types.c +GENERATED_FILES += qapi/qapi-types.h qapi/qapi-types.c GENERATED_FILES += qapi/qapi-types-common.h qapi/qapi-types-common.c GENERATED_FILES += qapi/qapi-types-misc.h qapi/qapi-types-misc.c -GENERATED_FILES += qapi-builtin-visit.h qapi-builtin-visit.c -GENERATED_FILES += qapi-visit.h qapi-visit.c +GENERATED_FILES += qapi/qapi-builtin-visit.h qapi/qapi-builtin-visit.c +GENERATED_FILES += qapi/qapi-visit.h qapi/qapi-visit.c GENERATED_FILES += qapi/qapi-visit-misc.h qapi/qapi-visit-misc.c GENERATED_FILES += qapi/qapi-visit-common.h qapi/qapi-visit-common.c @@ -135,7 +135,7 @@ $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak subdir-%: $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,) -$(SUBDIR_RULES): qapi-types.c qapi-types.h qapi-visit.c qapi-visit.h $(common-obj-y) $(util-obj-y) +$(SUBDIR_RULES): qapi/qapi-types.c qapi/qapi-types.h qapi/qapi-visit.c qapi/qapi-visit.h $(common-obj-y) $(util-obj-y) ALL_SUBDIRS=$(TARGET_DIRS) @@ -156,24 +156,24 @@ $(SRC_PATH)/scripts/ordereddict.py \ $(SRC_PATH)/scripts/qapi-gen.py qapi-modules = \ -$(SRC_PATH)/qapi-schema.json \ +$(SRC_PATH)/qapi/qapi-schema.json \ $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/misc.json -qapi-builtin-types.c qapi-builtin-types.h \ -qapi-types.c qapi-types.h \ +qapi/qapi-builtin-types.c qapi/qapi-builtin-types.h \ +qapi/qapi-types.c qapi/qapi-types.h \ qapi/qapi-types-common.c qapi/qapi-types-common.h \ qapi/qapi-types-misc.c qapi/qapi-types-misc.h \ -qapi-builtin-visit.c qapi-builtin-visit.h \ -qapi-visit.c qapi-visit.h \ +qapi/qapi-builtin-visit.c qapi/qapi-builtin-visit.h \ +qapi/qapi-visit.c qapi/qapi-visit.h \ qapi/qapi-visit-common.c qapi/qapi-visit-common.h \ qapi/qapi-visit-misc.c qapi/qapi-visit-misc.h \ qapi-doc.texi: \ qapi-gen-timestamp ; qapi-gen-timestamp: $(qapi-modules) $(qapi-py) $(call quiet-command,$(PYTHON_UTF8) $(SRC_PATH)/scripts/qapi-gen.py \ - -o "." -b $<, \ + -o "qapi" -b $<, \ "GEN","$(@:%-timestamp=%)") @>$@ diff --git a/qemu/Makefile.objs b/qemu/Makefile.objs index 917e9452..d60fdfb1 100644 --- a/qemu/Makefile.objs +++ b/qemu/Makefile.objs @@ -1,9 +1,11 @@ ####################################################################### # Common libraries for tools and emulators -util-obj-y = util/ qobject/ qapi/ qapi-types.o qapi-visit.o -util-obj-y += qapi-builtin-types.o -util-obj-y += qapi-builtin-visit.o +util-obj-y = util/ qobject/ qapi/ +util-obj-y += qapi/qapi-types.o +util-obj-y += qapi/qapi-builtin-types.o +util-obj-y += qapi/qapi-builtin-visit.o util-obj-y += qapi/qapi-types-misc.o +util-obj-y += qapi/qapi-visit.o util-obj-y += qapi/qapi-visit-misc.o ####################################################################### diff --git a/qemu/include/qapi/error.h b/qemu/include/qapi/error.h index 3a328cb3..c6da15d8 100644 --- a/qemu/include/qapi/error.h +++ b/qemu/include/qapi/error.h @@ -109,7 +109,7 @@ #define ERROR_H #include "qemu/compiler.h" -#include "qapi-types.h" +#include "qapi/qapi-types.h" #include "unicorn/platform.h" /* diff --git a/qemu/include/qapi/qmp/qlit.h b/qemu/include/qapi/qmp/qlit.h index b18406bc..56f9d97b 100644 --- a/qemu/include/qapi/qmp/qlit.h +++ b/qemu/include/qapi/qmp/qlit.h @@ -14,7 +14,6 @@ #ifndef QLIT_H #define QLIT_H -#include "qapi-types.h" #include "qobject.h" typedef struct QLitDictEntry QLitDictEntry; diff --git a/qemu/include/qapi/qmp/qobject.h b/qemu/include/qapi/qmp/qobject.h index d5cf320b..6ff239ed 100644 --- a/qemu/include/qapi/qmp/qobject.h +++ b/qemu/include/qapi/qmp/qobject.h @@ -32,7 +32,7 @@ #ifndef QOBJECT_H #define QOBJECT_H -#include "qapi-builtin-types.h" +#include "qapi/qapi-builtin-types.h" struct QObject { QType type; diff --git a/qemu/include/qapi/visitor.h b/qemu/include/qapi/visitor.h index 73d9f4b5..374eb963 100644 --- a/qemu/include/qapi/visitor.h +++ b/qemu/include/qapi/visitor.h @@ -14,7 +14,7 @@ #ifndef QAPI_VISITOR_H #define QAPI_VISITOR_H -#include "qapi-builtin-types.h" +#include "qapi/qapi-builtin-types.h" /* * The QAPI schema defines both a set of C data types, and a QMP wire diff --git a/qemu/include/qom/object.h b/qemu/include/qom/object.h index 17746f65..7e9abc6a 100644 --- a/qemu/include/qom/object.h +++ b/qemu/include/qom/object.h @@ -16,7 +16,7 @@ #include "glib_compat.h" #include "unicorn/platform.h" -#include "qapi-builtin-types.h" +#include "qapi/qapi-builtin-types.h" #include "qemu/queue.h" #include "qemu/typedefs.h" #include "qapi/error.h" diff --git a/qemu/qapi-schema.json b/qemu/qapi/qapi-schema.json similarity index 97% rename from qemu/qapi-schema.json rename to qemu/qapi/qapi-schema.json index 71268a1e..5b4d1999 100644 --- a/qemu/qapi-schema.json +++ b/qemu/qapi/qapi-schema.json @@ -73,5 +73,5 @@ ] } } # QAPI common definitions -{ 'include': 'qapi/common.json' } -{ 'include': 'qapi/misc.json' } +{ 'include': 'common.json' } +{ 'include': 'misc.json' } diff --git a/qemu/qom/object.c b/qemu/qom/object.c index b160c4e8..f459276a 100644 --- a/qemu/qom/object.c +++ b/qemu/qom/object.c @@ -16,7 +16,7 @@ #include "qemu/cutils.h" #include "qapi/visitor.h" #include "qapi/string-input-visitor.h" -#include "qapi-builtin-visit.h" +#include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" /* TODO: replace QObject with a simpler visitor to avoid a dependency diff --git a/qemu/scripts/qapi/common.py b/qemu/scripts/qapi/common.py index 4f5d76bc..77e0be72 100644 --- a/qemu/scripts/qapi/common.py +++ b/qemu/scripts/qapi/common.py @@ -1784,11 +1784,10 @@ def c_enum_const(type_name, const_name, prefix=None): type_name = prefix return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper() -# Temporary HACK for '/': if hasattr(str, 'maketrans'): - c_name_trans = str.maketrans('.-/', '___') + c_name_trans = str.maketrans('.-', '__') else: - c_name_trans = string.maketrans('.-/', '___') + c_name_trans = string.maketrans('.-', '__') # Map @name to a valid C identifier. diff --git a/qemu/scripts/qapi/events.py b/qemu/scripts/qapi/events.py index a8c2d3bd..480c95d9 100644 --- a/qemu/scripts/qapi/events.py +++ b/qemu/scripts/qapi/events.py @@ -157,19 +157,12 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): self._enum_name = c_name(prefix + 'QAPIEvent', protect=False) self._event_names = [] - # Temporary HACK: - def _module_basename(self, what, name): - basename = QAPISchemaModularCVisitor._module_basename(self, what, name) - if name == self._main_module: - return re.sub(r'qapi-events', 'qapi-event', basename) - return basename - def _begin_module(self, name): types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' #include "qemu-common.h" -#include "%(prefix)sqapi-event.h" +#include "%(prefix)sqapi-events.h" #include "%(visit)s.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" diff --git a/qemu/scripts/qapi/types.py b/qemu/scripts/qapi/types.py index dfc6cf6a..839cd23b 100644 --- a/qemu/scripts/qapi/types.py +++ b/qemu/scripts/qapi/types.py @@ -177,8 +177,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" -#include "qapi-builtin-types.h" -#include "qapi-builtin-visit.h" +#include "qapi/qapi-builtin-types.h" +#include "qapi/qapi-builtin-visit.h" ''')) self._genh.preamble_add(mcgen(''' /* #include "qapi/util.h" */ @@ -195,7 +195,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): ''', types=types, visit=visit)) self._genh.preamble_add(mcgen(''' -#include "qapi-builtin-types.h" +#include "qapi/qapi-builtin-types.h" ''')) def visit_begin(self, schema): diff --git a/qemu/scripts/qapi/visit.py b/qemu/scripts/qapi/visit.py index eec1973e..74cf7a36 100644 --- a/qemu/scripts/qapi/visit.py +++ b/qemu/scripts/qapi/visit.py @@ -274,11 +274,11 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): #include "qemu/osdep.h" #include "qemu-common.h" #include "qapi/error.h" -#include "qapi-builtin-visit.h" +#include "qapi/qapi-builtin-visit.h" ''')) self._genh.preamble_add(mcgen(''' #include "qapi/visitor.h" -#include "qapi-builtin-types.h" +#include "qapi/qapi-builtin-types.h" ''', prefix=prefix)) @@ -295,7 +295,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): ''', visit=visit, prefix=self._prefix)) self._genh.preamble_add(mcgen(''' -#include "qapi-builtin-visit.h" +#include "qapi/qapi-builtin-visit.h" #include "%(types)s.h" ''',