qapi: Streamline boilerplate comment generation

Every generator has separate boilerplate for .h and .c, and their
differences are boring.  All of them repeat the license note.

Reduce the repetition as follows.  Move common text like the license
note to common open_output(), next to the existing common text there.
For each generator, replace the two separate descriptions by a single
one.

While there, emit an "automatically generated" note into generated
documentation, too.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20180211093607.27351-3-armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2018-02-11 10:35:40 +01:00 committed by Eric Blake
parent 0dd13589b0
commit c263de3f41
8 changed files with 36 additions and 126 deletions

View File

@ -255,38 +255,18 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() (input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
c_comment = ''' blurb = '''
/* * Schema-defined QAPI/QMP commands
* schema-defined QMP->QAPI command dispatch
* *
* Copyright IBM, Corp. 2011 * Copyright IBM, Corp. 2011
* *
* Authors: * Authors:
* Anthony Liguori <aliguori@us.ibm.com> * Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
'''
h_comment = '''
/*
* schema-defined QAPI function prototypes
*
* Copyright IBM, Corp. 2011
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
''' '''
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
'qmp-marshal.c', 'qmp-commands.h', 'qmp-marshal.c', 'qmp-commands.h',
c_comment, h_comment) blurb)
fdef.write(mcgen(''' fdef.write(mcgen('''

View File

@ -171,38 +171,18 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
c_comment = ''' blurb = '''
/* * Schema-defined QAPI/QMP events
* schema-defined QAPI event functions
* *
* Copyright (c) 2014 Wenchao Xia * Copyright (c) 2014 Wenchao Xia
* *
* Authors: * Authors:
* Wenchao Xia <wenchaoqemu@gmail.com> * Wenchao Xia <wenchaoqemu@gmail.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
'''
h_comment = '''
/*
* schema-defined QAPI event functions
*
* Copyright (c) 2014 Wenchao Xia
*
* Authors:
* Wenchao Xia <wenchaoqemu@gmail.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
''' '''
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
'qapi-event.c', 'qapi-event.h', 'qapi-event.c', 'qapi-event.h',
c_comment, h_comment) blurb)
fdef.write(mcgen(''' fdef.write(mcgen('''
#include "qemu/osdep.h" #include "qemu/osdep.h"

View File

@ -176,32 +176,15 @@ for o, a in opts:
if o in ('-u', '--unmask-non-abi-names'): if o in ('-u', '--unmask-non-abi-names'):
opt_unmask = True opt_unmask = True
c_comment = ''' blurb = '''
/*
* QAPI/QMP schema introspection * QAPI/QMP schema introspection
* *
* Copyright (C) 2015 Red Hat, Inc. * Copyright (C) 2015 Red Hat, Inc.
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
'''
h_comment = '''
/*
* QAPI/QMP schema introspection
*
* Copyright (C) 2015 Red Hat, Inc.
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
''' '''
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
'qmp-introspect.c', 'qmp-introspect.h', 'qmp-introspect.c', 'qmp-introspect.h',
c_comment, h_comment) blurb)
fdef.write(mcgen(''' fdef.write(mcgen('''
#include "qemu/osdep.h" #include "qemu/osdep.h"

View File

@ -250,39 +250,19 @@ for o, a in opts:
if o in ('-b', '--builtins'): if o in ('-b', '--builtins'):
do_builtins = True do_builtins = True
c_comment = ''' blurb = '''
/* * Schema-defined QAPI types
* deallocation functions for schema-defined QAPI types
* *
* Copyright IBM, Corp. 2011 * Copyright IBM, Corp. 2011
* *
* Authors: * Authors:
* Anthony Liguori <aliguori@us.ibm.com> * Anthony Liguori <aliguori@us.ibm.com>
* Michael Roth <mdroth@linux.vnet.ibm.com> * Michael Roth <mdroth@linux.vnet.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
'''
h_comment = '''
/*
* schema-defined QAPI types
*
* Copyright IBM, Corp. 2011
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
''' '''
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
'qapi-types.c', 'qapi-types.h', 'qapi-types.c', 'qapi-types.h',
c_comment, h_comment) blurb)
fdef.write(mcgen(''' fdef.write(mcgen('''
#include "qemu/osdep.h" #include "qemu/osdep.h"

View File

@ -334,38 +334,18 @@ for o, a in opts:
if o in ('-b', '--builtins'): if o in ('-b', '--builtins'):
do_builtins = True do_builtins = True
c_comment = ''' blurb = '''
/* * Schema-defined QAPI visitors
* schema-defined QAPI visitor functions
* *
* Copyright IBM, Corp. 2011 * Copyright IBM, Corp. 2011
* *
* Authors: * Authors:
* Anthony Liguori <aliguori@us.ibm.com> * Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
'''
h_comment = '''
/*
* schema-defined QAPI visitor functions
*
* Copyright IBM, Corp. 2011
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
''' '''
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
'qapi-visit.c', 'qapi-visit.h', 'qapi-visit.c', 'qapi-visit.h',
c_comment, h_comment) blurb)
fdef.write(mcgen(''' fdef.write(mcgen('''
#include "qemu/osdep.h" #include "qemu/osdep.h"

View File

@ -1985,11 +1985,21 @@ def parse_command_line(extra_options='', extra_long_options=[]):
# #
def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, blurb):
c_comment, h_comment):
guard = guardname(prefix + h_file) guard = guardname(prefix + h_file)
c_file = output_dir + prefix + c_file c_file = output_dir + prefix + c_file
h_file = output_dir + prefix + h_file h_file = output_dir + prefix + h_file
comment = mcgen('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
/*
%(blurb)s
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*/
''',
blurb=blurb.strip('\n'))
if output_dir: if output_dir:
try: try:
@ -2007,27 +2017,22 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file,
fdef = maybe_open(do_c, c_file, 'w') fdef = maybe_open(do_c, c_file, 'w')
fdecl = maybe_open(do_h, h_file, 'w') fdecl = maybe_open(do_h, h_file, 'w')
fdef.write(mcgen(''' fdef.write(comment)
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ fdecl.write(comment)
%(comment)s
''',
comment=c_comment))
fdecl.write(mcgen(''' fdecl.write(mcgen('''
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
%(comment)s
#ifndef %(guard)s #ifndef %(guard)s
#define %(guard)s #define %(guard)s
''', ''',
comment=h_comment, guard=guard)) guard=guard))
return (fdef, fdecl) return (fdef, fdecl)
def close_output(fdef, fdecl): def close_output(fdef, fdecl):
fdecl.write(''' fdecl.write(mcgen('''
#endif #endif
''') '''))
fdecl.close() fdecl.close()
fdef.close() fdef.close()

View File

@ -283,7 +283,8 @@ def main(argv):
print("%s: need pragma 'doc-required' " print("%s: need pragma 'doc-required' "
"to generate documentation" % argv[0], file=sys.stderr) "to generate documentation" % argv[0], file=sys.stderr)
sys.exit(1) sys.exit(1)
print(texi_schema(schema)) print('@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n')
print(texi_schema(schema), end='')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,3 +1,5 @@
@c AUTOMATICALLY GENERATED, DO NOT MODIFY
@section Section @section Section
@subsection Subsection @subsection Subsection
@ -231,4 +233,3 @@ If you're bored enough to read this, go see a video of boxed cats
@end deftypefn @end deftypefn