>From f5c30c922ce1cf755ef78887f4015c131d8d6841 Mon Sep 17 00:00:00 2001 From: Anthony Liguori
Date: Thu, 12 May 2011 10:56:29 -0500 Subject: [PATCH 1/1] qdev: add centralized documentation for qdev (v2) This adds a -qdev-verify option that will confirm that the documentation matches the code. It returns a non-zero exit status if any errors are detected. Signed-off-by: Anthony Liguori --- Makefile | 2 + Makefile.doc | 5 ++ Makefile.objs | 2 +- qdev-doc.h | 23 +++++++++++ qdev-doc.json | 16 ++++++++ qemu-options.hx | 10 +++++ scripts/qdev-doc-to-c.py | 30 ++++++++++++++ scripts/qdev-doc-to-html.py | 40 +++++++++++++++++++ vl.c | 89 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 216 insertions(+), 1 deletions(-) create mode 100644 Makefile.doc create mode 100644 qdev-doc.h create mode 100644 qdev-doc.json create mode 100644 scripts/qdev-doc-to-c.py create mode 100644 scripts/qdev-doc-to-html.py diff --git a/Makefile b/Makefile index 2b0438c..fddb261 100644 --- a/Makefile +++ b/Makefile @@ -341,5 +341,7 @@ tarbin: $(mandir)/man1/qemu-img.1 \ $(mandir)/man8/qemu-nbd.8 +include $(SRC_PATH)/Makefile.doc + # Include automatically generated dependency files -include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d ui/*.d) diff --git a/Makefile.doc b/Makefile.doc new file mode 100644 index 0000000..c1cf74a --- /dev/null +++ b/Makefile.doc @@ -0,0 +1,5 @@ +qdev-doc.html: $(SRC_PATH)/qdev-doc.json $(SRC_PATH)/scripts/qdev-doc-to-html.py + python $(SRC_PATH)/scripts/qdev-doc-to-html.py < $< > $@ + +qdev-doc.c: $(SRC_PATH)/qdev-doc.json $(SRC_PATH)/scripts/qdev-doc-to-c.py + python $(SRC_PATH)/scripts/qdev-doc-to-c.py < $< > $@ diff --git a/Makefile.objs b/Makefile.objs index 4478c61..9547ab1 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -97,7 +97,7 @@ common-obj-y += bt-hci-csr.o common-obj-y += buffered_file.o migration.o migration-tcp.o common-obj-y += qemu-char.o savevm.o #aio.o common-obj-y += msmouse.o ps2.o -common-obj-y += qdev.o qdev-properties.o +common-obj-y += qdev.o qdev-properties.o qdev-doc.o common-obj-y += block-migration.o iohandler.o common-obj-y += pflib.o common-obj-y += bitmap.o bitops.o diff --git a/qdev-doc.h b/qdev-doc.h new file mode 100644 index 0000000..401e03e --- /dev/null +++ b/qdev-doc.h @@ -0,0 +1,23 @@ +#ifndef QDEV_DOC_H +#define QDEV_DOC_H + +#include "qemu-common.h" + +typedef struct PropertyDocumentation +{ + const char *name; + const char *type; + const char *docs; +} PropertyDocumentation; + +typedef struct DeviceStateDocumentation +{ + const char *name; + PropertyDocumentation *properties; +} DeviceStateDocumentation; + +extern DeviceStateDocumentation device_docs[]; + +bool qdev_verify_docs(void); + +#endif diff --git a/qdev-doc.json b/qdev-doc.json new file mode 100644 index 0000000..a798bff --- /dev/null +++ b/qdev-doc.json @@ -0,0 +1,16 @@ +# -*- Mode: Python -*- + +[ { "device": "isa-serial", + "parent": "ISADevice", + "properties": { + "index": { "type": "uint32", + "doc": "A value from 0-3 that describes which IO regions to expose the device on. This sets appropriate values for iobase and irq." }, + "iobase": { "type": "hex32", + "doc": "The base IO address to expose the device on." }, + "irq": { "type": "uint32", + "doc": "The IRQ to use for the device." }, + "chardev": { "type": "chr", + "doc": "The name of a character device to specify." } + } + } + ] diff --git a/qemu-options.hx b/qemu-options.hx index 9f121ad..a6abab4 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2378,6 +2378,16 @@ Specify a trace file to log output traces to. ETEXI #endif +DEF("qdev-verify", 0, QEMU_OPTION_qdev_verify, + "-qdev-verify\n" + " Verify qdev properties match documentation\n", + QEMU_ARCH_ALL) +STEXI address@hidden -qdev-verify address@hidden -qdev-verify +Verify qdev properties match documentation. +ETEXI + HXCOMM This is the last statement. Insert new options before this line! STEXI @end table diff --git a/scripts/qdev-doc-to-c.py b/scripts/qdev-doc-to-c.py new file mode 100644 index 0000000..eb7ee59 --- /dev/null +++ b/scripts/qdev-doc-to-c.py @@ -0,0 +1,30 @@ +#!/usr/bin/python + +import sys + +data = sys.stdin.read() + +docs = eval(data) + +sys.stdout.write(''' +#include "qdev-doc.h" + +DeviceStateDocumentation device_docs[] = {''') + +for item in docs: + sys.stdout.write(''' + { + .name = "%(device)s", + .properties = (PropertyDocumentation[]){''' % item) + for prop in item["properties"]: + sys.stdout.write(''' + { "%s", "%s", "%s" },''' % (prop, item["properties"][prop]['type'], item["properties"][prop]['doc'])) + + sys.stdout.write(''' + { } }, + },''') + +sys.stdout.write(''' + { } +}; +''') diff --git a/scripts/qdev-doc-to-html.py b/scripts/qdev-doc-to-html.py new file mode 100644 index 0000000..a25fe35 --- /dev/null +++ b/scripts/qdev-doc-to-html.py @@ -0,0 +1,40 @@ +#!/usr/bin/python + +import sys + +data = sys.stdin.read() + +docs = eval(data) + +sys.stdout.write(''' + + +Name | Type | Comments | +
---|---|---|
%s | %s | %s | +