summary refs log tree commit diff stats
path: root/scripts/tracetool/__init__.py
diff options
context:
space:
mode:
authoroltolm <oleg.tolmatcev@gmail.com>2025-06-13 00:15:22 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2025-06-16 13:16:27 -0400
commit9761ad5f65d23f080b5a3479e52196fbce2e1506 (patch)
treebf023c2913bdd1855f0f83d1e46a2350d24a5af9 /scripts/tracetool/__init__.py
parenta6f02277595136832c9e9bcaf447ab574f7b1128 (diff)
downloadfocaccia-qemu-9761ad5f65d23f080b5a3479e52196fbce2e1506.tar.gz
focaccia-qemu-9761ad5f65d23f080b5a3479e52196fbce2e1506.zip
meson: fix Windows build
The build fails on Windows. Replace calls to Unix programs like ´cat´,
´sed´ and ´true´ with calls to ´python´ and wrap calls to
´os.path.relpath´ in try-except because it can fail when the two paths
are on different drives. Make sure to convert the Windows paths to Unix
paths to prevent warnings in generated files.

Signed-off-by: oltolm <oleg.tolmatcev@gmail.com>
Message-id: 20250612221521.1109-2-oleg.tolmatcev@gmail.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'scripts/tracetool/__init__.py')
-rw-r--r--scripts/tracetool/__init__.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index bc03238c0f..6dfcbf71e1 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -12,12 +12,14 @@ __maintainer__ = "Stefan Hajnoczi"
 __email__      = "stefanha@redhat.com"
 
 
+import os
 import re
 import sys
 import weakref
+from pathlib import PurePath
 
-import tracetool.format
 import tracetool.backend
+import tracetool.format
 
 
 def error_write(*lines):
@@ -36,7 +38,7 @@ out_fobj = sys.stdout
 
 def out_open(filename):
     global out_filename, out_fobj
-    out_filename = filename
+    out_filename = posix_relpath(filename)
     out_fobj = open(filename, 'wt')
 
 def out(*lines, **kwargs):
@@ -308,7 +310,7 @@ class Event(object):
             fmt = [fmt_trans, fmt]
         args = Arguments.build(groups["args"])
 
-        return Event(name, props, fmt, args, lineno, filename)
+        return Event(name, props, fmt, args, lineno, posix_relpath(filename))
 
     def __repr__(self):
         """Evaluable string representation for this object."""
@@ -447,3 +449,10 @@ def generate(events, group, format, backends,
     tracetool.backend.dtrace.PROBEPREFIX = probe_prefix
 
     tracetool.format.generate(events, format, backend, group)
+
+def posix_relpath(path, start=None):
+    try:
+        path = os.path.relpath(path, start)
+    except ValueError:
+        pass
+    return PurePath(path).as_posix()