From nobody Tue Feb 10 15:01:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517589346947738.9020719793634; Fri, 2 Feb 2018 08:35:46 -0800 (PST) Received: from localhost ([::1]:39002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eheJW-0005f7-4s for importer@patchew.org; Fri, 02 Feb 2018 11:35:46 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehdMe-0002k9-CO for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:36:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehdLV-0004dr-KC for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:34:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58932) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ehdLU-0004cB-VR for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:33:45 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FE567F7B9; Fri, 2 Feb 2018 13:04:34 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6200D6F115; Fri, 2 Feb 2018 13:03:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 93DF81138646; Fri, 2 Feb 2018 14:03:36 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 2 Feb 2018 14:03:16 +0100 Message-Id: <20180202130336.24719-2-armbru@redhat.com> In-Reply-To: <20180202130336.24719-1-armbru@redhat.com> References: <20180202130336.24719-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 02 Feb 2018 13:04:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 01/21] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 existintg 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=C3=A9 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 26c56c5062..25ac52503a 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -255,38 +255,18 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D parse_command_line() =20 -c_comment =3D ''' -/* - * schema-defined QMP->QAPI command dispatch +blurb =3D ''' + * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ -''' -h_comment =3D ''' -/* - * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ ''' =20 (fdef, fdecl) =3D open_output(output_dir, do_c, do_h, prefix, 'qmp-marshal.c', 'qmp-commands.h', - c_comment, h_comment) + blurb) =20 fdef.write(mcgen(''' =20 diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 9d7134658d..31faedc689 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -171,38 +171,18 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): =20 (input_file, output_dir, do_c, do_h, prefix, dummy) =3D parse_command_line= () =20 -c_comment =3D ''' -/* - * schema-defined QAPI event functions +blurb =3D ''' + * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ -''' -h_comment =3D ''' -/* - * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ ''' =20 (fdef, fdecl) =3D open_output(output_dir, do_c, do_h, prefix, 'qapi-event.c', 'qapi-event.h', - c_comment, h_comment) + blurb) =20 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 =3D True =20 -c_comment =3D ''' -/* +blurb =3D ''' * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ -''' -h_comment =3D ''' -/* - * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ ''' =20 (fdef, fdecl) =3D open_output(output_dir, do_c, do_h, prefix, 'qmp-introspect.c', 'qmp-introspect.h', - c_comment, h_comment) + blurb) =20 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 =3D True =20 -c_comment =3D ''' -/* - * deallocation functions for schema-defined QAPI types +blurb =3D ''' + * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ -''' -h_comment =3D ''' -/* - * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ ''' =20 (fdef, fdecl) =3D open_output(output_dir, do_c, do_h, prefix, 'qapi-types.c', 'qapi-types.h', - c_comment, h_comment) + blurb) =20 fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 7e1cfc13f0..9f7127e548 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 =3D True =20 -c_comment =3D ''' -/* - * schema-defined QAPI visitor functions +blurb =3D ''' + * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ -''' -h_comment =3D ''' -/* - * 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 l= ater. - * See the COPYING.LIB file in the top-level directory. - * - */ ''' =20 (fdef, fdecl) =3D open_output(output_dir, do_c, do_h, prefix, 'qapi-visit.c', 'qapi-visit.h', - c_comment, h_comment) + blurb) =20 fdef.write(mcgen(''' #include "qemu/osdep.h" diff --git a/scripts/qapi.py b/scripts/qapi.py index 43a54bf40f..2e4b2bc9eb 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1975,11 +1975,21 @@ def parse_command_line(extra_options=3D'', extra_lo= ng_options=3D[]): # =20 =20 -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 =3D guardname(prefix + h_file) c_file =3D output_dir + prefix + c_file h_file =3D output_dir + prefix + h_file + comment =3D mcgen('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ + +/* +%(blurb)s + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +''', + blurb=3Dblurb.strip('\n')) =20 if output_dir: try: @@ -1998,27 +2008,22 @@ def open_output(output_dir, do_c, do_h, prefix, c_f= ile, h_file, fdef =3D maybe_open(do_c, c_file, 'w') fdecl =3D maybe_open(do_h, h_file, 'w') =20 - fdef.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ -%(comment)s -''', - comment=3Dc_comment)) - + fdef.write(comment) + fdecl.write(comment) fdecl.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ -%(comment)s #ifndef %(guard)s #define %(guard)s =20 ''', - comment=3Dh_comment, guard=3Dguard)) + guard=3Dguard)) =20 return (fdef, fdecl) =20 =20 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 92e2af2cd6..924b374cd3 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -282,7 +282,8 @@ def main(argv): print >>sys.stderr, ("%s: need pragma 'doc-required' " "to generate documentation" % argv[0]) sys.exit(1) - print texi_schema(schema) + print '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n' + print texi_schema(schema), =20 =20 if __name__ =3D=3D '__main__': diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi 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 =20 @subsection Subsection @@ -231,4 +233,3 @@ If you're bored enough to read this, go see a video of = boxed cats =20 @end deftypefn =20 - --=20 2.13.6