aboutsummaryrefslogtreecommitdiff
path: root/scripts/tracetool
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2020-08-27 15:29:12 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2021-01-04 14:24:58 +0000
commitc05012a365c2d7d42d205b1efa895bf2144bab88 (patch)
treeb7a25025de22f351f41d84dfdf621d16dc87fa3b /scripts/tracetool
parent6745c8a01f759b64d3c4cd1e0a69bb793cead268 (diff)
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>
Diffstat (limited to 'scripts/tracetool')
-rw-r--r--scripts/tracetool/__init__.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 3ee54be223..a6013389a0 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -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