tracetool: add output filename command-line argument

The tracetool.py script writes to stdout. This means the output filename
is not available to the script. Add the output filename to the
command-line so that the script has access to the filename.

This also simplifies the tracetool.py invocation. It's no longer
necessary to use meson's custom_build(capture : true) to save output.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200827142915.108730-2-stefanha@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2020-08-27 15:29:12 +01:00
parent 6745c8a01f
commit c05012a365
5 changed files with 33 additions and 24 deletions

View file

@ -31,14 +31,28 @@ def error(*lines):
sys.exit(1)
out_filename = '<none>'
out_fobj = sys.stdout
def out_open(filename):
global out_filename, out_fobj
out_filename = filename
out_fobj = open(filename, 'wt')
def out(*lines, **kwargs):
"""Write a set of output lines.
You can use kwargs as a shorthand for mapping variables when formatting all
the strings in lines.
The 'out_filename' kwarg is automatically added with the output filename.
"""
lines = [ l % kwargs for l in lines ]
sys.stdout.writelines("\n".join(lines) + "\n")
output = []
for l in lines:
kwargs['out_filename'] = out_filename
output.append(l % kwargs)
out_fobj.writelines("\n".join(output) + "\n")
# We only want to allow standard C types or fixed sized
# integer types. We don't want QEMU specific types