From patchwork Sun Feb 11 09:35:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 10211217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B56B60467 for ; Sun, 11 Feb 2018 09:44:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CED428DB9 for ; Sun, 11 Feb 2018 09:44:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F84528EBB; Sun, 11 Feb 2018 09:44:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 728D528EAE for ; Sun, 11 Feb 2018 09:44:46 +0000 (UTC) Received: from localhost ([::1]:40780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekoBh-0005lE-Kz for patchwork-qemu-devel@patchwork.kernel.org; Sun, 11 Feb 2018 04:44:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eko3e-00072i-Mr for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eko3Y-0006Lv-44 for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:26 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44346 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eko3X-0006Ha-GP for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D7CD40FB62E; Sun, 11 Feb 2018 09:36:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-43.ams2.redhat.com [10.36.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD4D310A9DD0; Sun, 11 Feb 2018 09:36:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 87C691138648; Sun, 11 Feb 2018 10:36:07 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sun, 11 Feb 2018 10:35:40 +0100 Message-Id: <20180211093607.27351-3-armbru@redhat.com> In-Reply-To: <20180211093607.27351-1-armbru@redhat.com> References: <20180211093607.27351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 11 Feb 2018 09:36:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 11 Feb 2018 09:36:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 02/29] qapi: Streamline boilerplate comment generation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau --- scripts/qapi-commands.py | 26 +++----------------------- scripts/qapi-event.py | 26 +++----------------------- scripts/qapi-introspect.py | 21 ++------------------- scripts/qapi-types.py | 26 +++----------------------- scripts/qapi-visit.py | 26 +++----------------------- scripts/qapi.py | 31 ++++++++++++++++++------------- scripts/qapi2texi.py | 3 ++- tests/qapi-schema/doc-good.texi | 3 ++- 8 files changed, 36 insertions(+), 126 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index f89d748ba4..8e8da7c796 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -255,38 +255,18 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): (input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() -c_comment = ''' -/* - * schema-defined QMP->QAPI command dispatch +blurb = ''' + * Schema-defined QAPI/QMP commands * * Copyright IBM, Corp. 2011 * * Authors: * Anthony Liguori - * - * 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 - * - * 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, 'qmp-marshal.c', 'qmp-commands.h', - c_comment, h_comment) + blurb) fdef.write(mcgen(''' diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index c710968dc2..2b7d720c08 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -171,38 +171,18 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() -c_comment = ''' -/* - * schema-defined QAPI event functions +blurb = ''' + * Schema-defined QAPI/QMP events * * Copyright (c) 2014 Wenchao Xia * * Authors: * Wenchao Xia - * - * 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 - * - * 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, 'qapi-event.c', 'qapi-event.h', - c_comment, h_comment) + blurb) fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea491..83da2bdb94 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -176,32 +176,15 @@ for o, a in opts: if o in ('-u', '--unmask-non-abi-names'): opt_unmask = True -c_comment = ''' -/* +blurb = ''' * 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. - * - */ -''' -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, 'qmp-introspect.c', 'qmp-introspect.h', - c_comment, h_comment) + blurb) fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 7e3051dbb9..86afc57f92 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -250,39 +250,19 @@ for o, a in opts: if o in ('-b', '--builtins'): do_builtins = True -c_comment = ''' -/* - * deallocation functions for schema-defined QAPI types +blurb = ''' + * Schema-defined QAPI types * * Copyright IBM, Corp. 2011 * * Authors: * Anthony Liguori * Michael Roth - * - * 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 - * - * 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, 'qapi-types.c', 'qapi-types.h', - c_comment, h_comment) + blurb) fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index bc2b8b581a..0a367072fb 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -334,38 +334,18 @@ for o, a in opts: if o in ('-b', '--builtins'): do_builtins = True -c_comment = ''' -/* - * schema-defined QAPI visitor functions +blurb = ''' + * Schema-defined QAPI visitors * * Copyright IBM, Corp. 2011 * * Authors: * Anthony Liguori - * - * 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 - * - * 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, 'qapi-visit.c', 'qapi-visit.h', - c_comment, h_comment) + blurb) fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi.py b/scripts/qapi.py index 58f995b07f..2e5a1ce6a8 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -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, - c_comment, h_comment): +def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, blurb): guard = guardname(prefix + h_file) c_file = output_dir + prefix + c_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: 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') fdecl = maybe_open(do_h, h_file, 'w') - fdef.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ -%(comment)s -''', - comment=c_comment)) - + fdef.write(comment) + fdecl.write(comment) fdecl.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ -%(comment)s #ifndef %(guard)s #define %(guard)s ''', - comment=h_comment, guard=guard)) + guard=guard)) return (fdef, fdecl) def close_output(fdef, fdecl): - fdecl.write(''' + fdecl.write(mcgen(''' + #endif -''') +''')) fdecl.close() fdef.close() diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index bf1c57b2e2..8a604d86a6 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -283,7 +283,8 @@ def main(argv): print("%s: need pragma 'doc-required' " "to generate documentation" % argv[0], file=sys.stderr) sys.exit(1) - print(texi_schema(schema)) + print('@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n') + print(texi_schema(schema), end='') if __name__ == '__main__': diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.texi index 1778312581..0aed2300a5 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -1,3 +1,5 @@ +@c AUTOMATICALLY GENERATED, DO NOT MODIFY + @section Section @subsection Subsection @@ -231,4 +233,3 @@ If you're bored enough to read this, go see a video of boxed cats @end deftypefn -