qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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>

authored by

Markus Armbruster and committed by
Eric Blake
c263de3f 0dd13589

+36 -126
+3 -23
scripts/qapi-commands.py
··· 255 255 256 256 (input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() 257 257 258 - c_comment = ''' 259 - /* 260 - * schema-defined QMP->QAPI command dispatch 261 - * 262 - * Copyright IBM, Corp. 2011 263 - * 264 - * Authors: 265 - * Anthony Liguori <aliguori@us.ibm.com> 266 - * 267 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 268 - * See the COPYING.LIB file in the top-level directory. 269 - * 270 - */ 271 - ''' 272 - h_comment = ''' 273 - /* 274 - * schema-defined QAPI function prototypes 258 + blurb = ''' 259 + * Schema-defined QAPI/QMP commands 275 260 * 276 261 * Copyright IBM, Corp. 2011 277 262 * 278 263 * Authors: 279 264 * Anthony Liguori <aliguori@us.ibm.com> 280 - * 281 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 282 - * See the COPYING.LIB file in the top-level directory. 283 - * 284 - */ 285 265 ''' 286 266 287 267 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, 288 268 'qmp-marshal.c', 'qmp-commands.h', 289 - c_comment, h_comment) 269 + blurb) 290 270 291 271 fdef.write(mcgen(''' 292 272
+3 -23
scripts/qapi-event.py
··· 171 171 172 172 (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() 173 173 174 - c_comment = ''' 175 - /* 176 - * schema-defined QAPI event functions 174 + blurb = ''' 175 + * Schema-defined QAPI/QMP events 177 176 * 178 177 * Copyright (c) 2014 Wenchao Xia 179 178 * 180 179 * Authors: 181 180 * Wenchao Xia <wenchaoqemu@gmail.com> 182 - * 183 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 184 - * See the COPYING.LIB file in the top-level directory. 185 - * 186 - */ 187 - ''' 188 - h_comment = ''' 189 - /* 190 - * schema-defined QAPI event functions 191 - * 192 - * Copyright (c) 2014 Wenchao Xia 193 - * 194 - * Authors: 195 - * Wenchao Xia <wenchaoqemu@gmail.com> 196 - * 197 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 198 - * See the COPYING.LIB file in the top-level directory. 199 - * 200 - */ 201 181 ''' 202 182 203 183 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, 204 184 'qapi-event.c', 'qapi-event.h', 205 - c_comment, h_comment) 185 + blurb) 206 186 207 187 fdef.write(mcgen(''' 208 188 #include "qemu/osdep.h"
+2 -19
scripts/qapi-introspect.py
··· 176 176 if o in ('-u', '--unmask-non-abi-names'): 177 177 opt_unmask = True 178 178 179 - c_comment = ''' 180 - /* 179 + blurb = ''' 181 180 * QAPI/QMP schema introspection 182 181 * 183 182 * Copyright (C) 2015 Red Hat, Inc. 184 - * 185 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 186 - * See the COPYING.LIB file in the top-level directory. 187 - * 188 - */ 189 - ''' 190 - h_comment = ''' 191 - /* 192 - * QAPI/QMP schema introspection 193 - * 194 - * Copyright (C) 2015 Red Hat, Inc. 195 - * 196 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 197 - * See the COPYING.LIB file in the top-level directory. 198 - * 199 - */ 200 183 ''' 201 184 202 185 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, 203 186 'qmp-introspect.c', 'qmp-introspect.h', 204 - c_comment, h_comment) 187 + blurb) 205 188 206 189 fdef.write(mcgen(''' 207 190 #include "qemu/osdep.h"
+3 -23
scripts/qapi-types.py
··· 250 250 if o in ('-b', '--builtins'): 251 251 do_builtins = True 252 252 253 - c_comment = ''' 254 - /* 255 - * deallocation functions for schema-defined QAPI types 253 + blurb = ''' 254 + * Schema-defined QAPI types 256 255 * 257 256 * Copyright IBM, Corp. 2011 258 257 * 259 258 * Authors: 260 259 * Anthony Liguori <aliguori@us.ibm.com> 261 260 * Michael Roth <mdroth@linux.vnet.ibm.com> 262 - * 263 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 264 - * See the COPYING.LIB file in the top-level directory. 265 - * 266 - */ 267 - ''' 268 - h_comment = ''' 269 - /* 270 - * schema-defined QAPI types 271 - * 272 - * Copyright IBM, Corp. 2011 273 - * 274 - * Authors: 275 - * Anthony Liguori <aliguori@us.ibm.com> 276 - * 277 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 278 - * See the COPYING.LIB file in the top-level directory. 279 - * 280 - */ 281 261 ''' 282 262 283 263 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, 284 264 'qapi-types.c', 'qapi-types.h', 285 - c_comment, h_comment) 265 + blurb) 286 266 287 267 fdef.write(mcgen(''' 288 268 #include "qemu/osdep.h"
+3 -23
scripts/qapi-visit.py
··· 334 334 if o in ('-b', '--builtins'): 335 335 do_builtins = True 336 336 337 - c_comment = ''' 338 - /* 339 - * schema-defined QAPI visitor functions 340 - * 341 - * Copyright IBM, Corp. 2011 342 - * 343 - * Authors: 344 - * Anthony Liguori <aliguori@us.ibm.com> 345 - * 346 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 347 - * See the COPYING.LIB file in the top-level directory. 348 - * 349 - */ 350 - ''' 351 - h_comment = ''' 352 - /* 353 - * schema-defined QAPI visitor functions 337 + blurb = ''' 338 + * Schema-defined QAPI visitors 354 339 * 355 340 * Copyright IBM, Corp. 2011 356 341 * 357 342 * Authors: 358 343 * Anthony Liguori <aliguori@us.ibm.com> 359 - * 360 - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 361 - * See the COPYING.LIB file in the top-level directory. 362 - * 363 - */ 364 344 ''' 365 345 366 346 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, 367 347 'qapi-visit.c', 'qapi-visit.h', 368 - c_comment, h_comment) 348 + blurb) 369 349 370 350 fdef.write(mcgen(''' 371 351 #include "qemu/osdep.h"
+18 -13
scripts/qapi.py
··· 1985 1985 # 1986 1986 1987 1987 1988 - def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, 1989 - c_comment, h_comment): 1988 + def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, blurb): 1990 1989 guard = guardname(prefix + h_file) 1991 1990 c_file = output_dir + prefix + c_file 1992 1991 h_file = output_dir + prefix + h_file 1992 + comment = mcgen('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ 1993 + 1994 + /* 1995 + %(blurb)s 1996 + * 1997 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 1998 + * See the COPYING.LIB file in the top-level directory. 1999 + */ 2000 + 2001 + ''', 2002 + blurb=blurb.strip('\n')) 1993 2003 1994 2004 if output_dir: 1995 2005 try: ··· 2007 2017 fdef = maybe_open(do_c, c_file, 'w') 2008 2018 fdecl = maybe_open(do_h, h_file, 'w') 2009 2019 2010 - fdef.write(mcgen(''' 2011 - /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ 2012 - %(comment)s 2013 - ''', 2014 - comment=c_comment)) 2015 - 2020 + fdef.write(comment) 2021 + fdecl.write(comment) 2016 2022 fdecl.write(mcgen(''' 2017 - /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ 2018 - %(comment)s 2019 2023 #ifndef %(guard)s 2020 2024 #define %(guard)s 2021 2025 2022 2026 ''', 2023 - comment=h_comment, guard=guard)) 2027 + guard=guard)) 2024 2028 2025 2029 return (fdef, fdecl) 2026 2030 2027 2031 2028 2032 def close_output(fdef, fdecl): 2029 - fdecl.write(''' 2033 + fdecl.write(mcgen(''' 2034 + 2030 2035 #endif 2031 - ''') 2036 + ''')) 2032 2037 fdecl.close() 2033 2038 fdef.close()
+2 -1
scripts/qapi2texi.py
··· 283 283 print("%s: need pragma 'doc-required' " 284 284 "to generate documentation" % argv[0], file=sys.stderr) 285 285 sys.exit(1) 286 - print(texi_schema(schema)) 286 + print('@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n') 287 + print(texi_schema(schema), end='') 287 288 288 289 289 290 if __name__ == '__main__':
+2 -1
tests/qapi-schema/doc-good.texi
··· 1 + @c AUTOMATICALLY GENERATED, DO NOT MODIFY 2 + 1 3 @section Section 2 4 3 5 @subsection Subsection ··· 231 233 232 234 @end deftypefn 233 235 234 -