Skip to contentSkip to conversation

meson: fix Windows build

PATCH Superseded oltolm 3 participants 6 messages May 29, 2025 – Jun 3, 2025 Arm/Amlogic Meson SoC support

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

oltolm

author
#0 lore raw

PATCH v2 1/1 meson: fix Windows build

The build failed when run on Windows. I replaced calls to Unix programs like ´cat´ and ´true´ with calls to ´python´. I wrapped calls to ´os.path.relpath´ in try-except because it can fail when the two paths are on different drives. I made sure to convert the Windows paths to Unix paths to prevent warnings in generated files.

---
 contrib/plugins/meson.build         | 2 +-
 scripts/tracetool/backend/ftrace.py | 9 ++++++++-
 scripts/tracetool/backend/log.py    | 9 ++++++++-
 scripts/tracetool/backend/syslog.py | 9 ++++++++-
 tests/functional/meson.build        | 4 +---
 tests/include/meson.build           | 2 +-
 tests/tcg/plugins/meson.build       | 2 +-
 trace/meson.build                   | 5 +++--
 8 files changed, 31 insertions(+), 11 deletions(-)
contrib/plugins/meson.build +1 -1
index fa8a426c8..1876bc784 100644
@@ -24,7 +24,7 @@ endif
 if t.length() > 0
   alias_target('contrib-plugins', t)
 else
-  run_target('contrib-plugins', command: find_program('true'))
+  run_target('contrib-plugins', command: [python, '-c', ''])
 endif
 
 plugin_modules += t
scripts/tracetool/backend/ftrace.py +8 -1
index baed2ae61..81a5f93b3 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 
@@ -30,6 +31,12 @@ def generate_h(event, group):
     if len(event.args) > 0:
         argnames = ", " + argnames
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
     out('    {',
         '        char ftrace_buf[MAX_TRACE_STRLEN];',
         '        int unused __attribute__ ((unused));',
@@ -47,7 +54,7 @@ def generate_h(event, group):
         args=event.args,
         event_id="TRACE_" + event.name.upper(),
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
 
scripts/tracetool/backend/log.py +8 -1
index de27b7e62..241fbbbd0 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 
@@ -37,6 +38,12 @@ def generate_h(event, group):
     else:
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
     out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
         '        if (message_with_timestamp) {',
         '            struct timeval _now;',
@@ -55,7 +62,7 @@ def generate_h(event, group):
         '    }',
         cond=cond,
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         name=event.name,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
scripts/tracetool/backend/syslog.py +8 -1
index 012970f6c..2e010e7c9 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 
@@ -36,6 +37,12 @@ def generate_h(event, group):
     else:
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
     out('    if (%(cond)s) {',
         '#line %(event_lineno)d "%(event_filename)s"',
         '        syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
@@ -43,7 +50,7 @@ def generate_h(event, group):
         '    }',
         cond=cond,
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         name=event.name,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
tests/functional/meson.build +1 -3
index 52b4706cf..ee222888f 100644
@@ -411,6 +411,4 @@ foreach speed : ['quick', 'thorough']
   endforeach
 endforeach
 
-run_target('precache-functional',
-           depends: precache_all,
-           command: ['true'])
+alias_target('precache-functional', precache_all)
tests/include/meson.build +1 -1
index 9abba308f..8e8d1ec4e 100644
@@ -13,4 +13,4 @@ test_qapi_outputs_extra = [
 test_qapi_files_extra = custom_target('QAPI test (include)',
                                       output: test_qapi_outputs_extra,
                                       input: test_qapi_files,
-                                      command: 'true')
+                                      command: [python, '-c', ''])
tests/tcg/plugins/meson.build +1 -1
index 41f02f2c7..029342282 100644
@@ -17,7 +17,7 @@ endif
 if t.length() > 0
   alias_target('test-plugins', t)
 else
-  run_target('test-plugins', command: find_program('true'))
+  run_target('test-plugins', command: [python, '-c', ''])
 endif
 
 plugin_modules += t
trace/meson.build +3 -2
index 3df454935..ebce0154c 100644
@@ -4,7 +4,7 @@ trace_events_files = []
 foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
   if item in qapi_trace_events
     trace_events_file = item
-    group_name = item.full_path().split('/')[-1].underscorify()
+    group_name = fs.name(item).underscorify()
   else
     trace_events_file = meson.project_source_root() / item / 'trace-events'
     group_name = item == '.' ? 'root' : item.underscorify()
@@ -57,10 +57,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
   endif
 endforeach
 
+cat = [ python, '-c', 'import fileinput;[print(line) for line in fileinput.input()]', '@INPUT@' ]
 trace_events_all = custom_target('trace-events-all',
                                  output: 'trace-events-all',
                                  input: trace_events_files,
-                                 command: [ 'cat', '@INPUT@' ],
+                                 command: [ cat ],
                                  capture: true,
                                  install: get_option('trace_backends') != [ 'nop' ],
                                  install_dir: qemu_datadir)
Signature · 1 line
2.49.0.windows.1
#1 lore raw

(Cc'ing maintainers)

Quoted 194 lines · oltolm

The build failed when run on Windows. I replaced calls to Unix programs like ´cat´ and ´true´ with calls to ´python´. I wrapped calls to ´os.path.relpath´ in try-except because it can fail when the two paths are on different drives. I made sure to convert the Windows paths to Unix paths to prevent warnings in generated files.

---
  contrib/plugins/meson.build         | 2 +-
  scripts/tracetool/backend/ftrace.py | 9 ++++++++-
  scripts/tracetool/backend/log.py    | 9 ++++++++-
  scripts/tracetool/backend/syslog.py | 9 ++++++++-
  tests/functional/meson.build        | 4 +---
  tests/include/meson.build           | 2 +-
  tests/tcg/plugins/meson.build       | 2 +-
  trace/meson.build                   | 5 +++--
  8 files changed, 31 insertions(+), 11 deletions(-)
contrib/plugins/meson.build +1 -1
index fa8a426c8..1876bc784 100644
@@ -24,7 +24,7 @@ endif
  if t.length() > 0
    alias_target('contrib-plugins', t)
  else
-  run_target('contrib-plugins', command: find_program('true'))
+  run_target('contrib-plugins', command: [python, '-c', ''])
  endif
 
  plugin_modules += t
scripts/tracetool/backend/ftrace.py +8 -1
index baed2ae61..81a5f93b3 100644
@@ -13,6 +13,7 @@
 
 
  import os.path
+from pathlib import PurePath
 
  from tracetool import out
 
@@ -30,6 +31,12 @@ def generate_h(event, group):
      if len(event.args) > 0:
          argnames = ", " + argnames
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
      out('    {',
          '        char ftrace_buf[MAX_TRACE_STRLEN];',
          '        int unused __attribute__ ((unused));',
@@ -47,7 +54,7 @@ def generate_h(event, group):
          args=event.args,
          event_id="TRACE_" + event.name.upper(),
          event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
          fmt=event.fmt.rstrip("\n"),
          argnames=argnames)
 
scripts/tracetool/backend/log.py +8 -1
index de27b7e62..241fbbbd0 100644
@@ -13,6 +13,7 @@
 
 
  import os.path
+from pathlib import PurePath
 
  from tracetool import out
 
@@ -37,6 +38,12 @@ def generate_h(event, group):
      else:
          cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
      out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
          '        if (message_with_timestamp) {',
          '            struct timeval _now;',
@@ -55,7 +62,7 @@ def generate_h(event, group):
          '    }',
          cond=cond,
          event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
          name=event.name,
          fmt=event.fmt.rstrip("\n"),
          argnames=argnames)
scripts/tracetool/backend/syslog.py +8 -1
index 012970f6c..2e010e7c9 100644
@@ -13,6 +13,7 @@
 
 
  import os.path
+from pathlib import PurePath
 
  from tracetool import out
 
@@ -36,6 +37,12 @@ def generate_h(event, group):
      else:
          cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
      out('    if (%(cond)s) {',
          '#line %(event_lineno)d "%(event_filename)s"',
          '        syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
@@ -43,7 +50,7 @@ def generate_h(event, group):
          '    }',
          cond=cond,
          event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
          name=event.name,
          fmt=event.fmt.rstrip("\n"),
          argnames=argnames)
tests/functional/meson.build +1 -3
index 52b4706cf..ee222888f 100644
@@ -411,6 +411,4 @@ foreach speed : ['quick', 'thorough']
    endforeach
  endforeach
 
-run_target('precache-functional',
-           depends: precache_all,
-           command: ['true'])
+alias_target('precache-functional', precache_all)
tests/include/meson.build +1 -1
index 9abba308f..8e8d1ec4e 100644
@@ -13,4 +13,4 @@ test_qapi_outputs_extra = [
  test_qapi_files_extra = custom_target('QAPI test (include)',
                                        output: test_qapi_outputs_extra,
                                        input: test_qapi_files,
-                                      command: 'true')
+                                      command: [python, '-c', ''])
tests/tcg/plugins/meson.build +1 -1
index 41f02f2c7..029342282 100644
@@ -17,7 +17,7 @@ endif
  if t.length() > 0
    alias_target('test-plugins', t)
  else
-  run_target('test-plugins', command: find_program('true'))
+  run_target('test-plugins', command: [python, '-c', ''])
  endif
 
  plugin_modules += t
trace/meson.build +3 -2
index 3df454935..ebce0154c 100644
@@ -4,7 +4,7 @@ trace_events_files = []
  foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
    if item in qapi_trace_events
      trace_events_file = item
-    group_name = item.full_path().split('/')[-1].underscorify()
+    group_name = fs.name(item).underscorify()
    else
      trace_events_file = meson.project_source_root() / item / 'trace-events'
      group_name = item == '.' ? 'root' : item.underscorify()
@@ -57,10 +57,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
    endif
  endforeach
 
+cat = [ python, '-c', 'import fileinput;[print(line) for line in fileinput.input()]', '@INPUT@' ]
  trace_events_all = custom_target('trace-events-all',
                                   output: 'trace-events-all',
                                   input: trace_events_files,
-                                 command: [ 'cat', '@INPUT@' ],
+                                 command: [ cat ],
                                   capture: true,
                                   install: get_option('trace_backends') != [ 'nop' ],
                                   install_dir: qemu_datadir)
#2 lore raw
In reply to oltolm
Quoted 45 lines · oltolm

The build failed when run on Windows. I replaced calls to Unix programs like ´cat´ and ´true´ with calls to ´python´. I wrapped calls to ´os.path.relpath´ in try-except because it can fail when the two paths are on different drives. I made sure to convert the Windows paths to Unix paths to prevent warnings in generated files.

---
 contrib/plugins/meson.build         | 2 +-
 scripts/tracetool/backend/ftrace.py | 9 ++++++++-
 scripts/tracetool/backend/log.py    | 9 ++++++++-
 scripts/tracetool/backend/syslog.py | 9 ++++++++-
 tests/functional/meson.build        | 4 +---
 tests/include/meson.build           | 2 +-
 tests/tcg/plugins/meson.build       | 2 +-
 trace/meson.build                   | 5 +++--
 8 files changed, 31 insertions(+), 11 deletions(-)
contrib/plugins/meson.build +1 -1
index fa8a426c8..1876bc784 100644
@@ -24,7 +24,7 @@ endif
 if t.length() > 0
   alias_target('contrib-plugins', t)
 else
-  run_target('contrib-plugins', command: find_program('true'))
+  run_target('contrib-plugins', command: [python, '-c', ''])
 endif
 
 plugin_modules += t
scripts/tracetool/backend/ftrace.py +1 -0
index baed2ae61..81a5f93b3 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 

scripts/tracetool/backend/ftrace.py def generate_h(event, group): · line 38

Quoted 8 lines
scripts/tracetool/backend/ftrace.py +5 -0
@@ -30,6 +31,12 @@ def generate_h(event, group):
     if len(event.args) > 0:
         argnames = ", " + argnames
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()

Please do this in one place to avoid code duplication in the backends. Perhaps event.filename or a new field can hold the properly formatted value so backends don't need to call relpath() themselves.

I noticed that out_filename is also emitted with #line but, unlike event.filename, no special processing (relpath() or as_posix()) is used there. Is it possible to drop relpath() and avoid the whole issue?

Quoted 146 lines
scripts/tracetool/backend/ftrace.py +2 -1
+
     out('    {',
         '        char ftrace_buf[MAX_TRACE_STRLEN];',
         '        int unused __attribute__ ((unused));',
@@ -47,7 +54,7 @@ def generate_h(event, group):
         args=event.args,
         event_id="TRACE_" + event.name.upper(),
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
 
scripts/tracetool/backend/log.py +8 -1
index de27b7e62..241fbbbd0 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 
@@ -37,6 +38,12 @@ def generate_h(event, group):
     else:
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
     out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
         '        if (message_with_timestamp) {',
         '            struct timeval _now;',
@@ -55,7 +62,7 @@ def generate_h(event, group):
         '    }',
         cond=cond,
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         name=event.name,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
scripts/tracetool/backend/syslog.py +8 -1
index 012970f6c..2e010e7c9 100644
@@ -13,6 +13,7 @@
 
 
 import os.path
+from pathlib import PurePath
 
 from tracetool import out
 
@@ -36,6 +37,12 @@ def generate_h(event, group):
     else:
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()
+
     out('    if (%(cond)s) {',
         '#line %(event_lineno)d "%(event_filename)s"',
         '        syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
@@ -43,7 +50,7 @@ def generate_h(event, group):
         '    }',
         cond=cond,
         event_lineno=event.lineno,
-        event_filename=os.path.relpath(event.filename),
+        event_filename=event_filename,
         name=event.name,
         fmt=event.fmt.rstrip("\n"),
         argnames=argnames)
tests/functional/meson.build +1 -3
index 52b4706cf..ee222888f 100644
@@ -411,6 +411,4 @@ foreach speed : ['quick', 'thorough']
   endforeach
 endforeach
 
-run_target('precache-functional',
-           depends: precache_all,
-           command: ['true'])
+alias_target('precache-functional', precache_all)
tests/include/meson.build +1 -1
index 9abba308f..8e8d1ec4e 100644
@@ -13,4 +13,4 @@ test_qapi_outputs_extra = [
 test_qapi_files_extra = custom_target('QAPI test (include)',
                                       output: test_qapi_outputs_extra,
                                       input: test_qapi_files,
-                                      command: 'true')
+                                      command: [python, '-c', ''])
tests/tcg/plugins/meson.build +1 -1
index 41f02f2c7..029342282 100644
@@ -17,7 +17,7 @@ endif
 if t.length() > 0
   alias_target('test-plugins', t)
 else
-  run_target('test-plugins', command: find_program('true'))
+  run_target('test-plugins', command: [python, '-c', ''])
 endif
 
 plugin_modules += t
trace/meson.build +3 -3
index 3df454935..ebce0154c 100644
@@ -4,7 +4,7 @@ trace_events_files = []
 foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
   if item in qapi_trace_events
     trace_events_file = item
-    group_name = item.full_path().split('/')[-1].underscorify()
+    group_name = fs.name(item).underscorify()
   else
     trace_events_file = meson.project_source_root() / item / 'trace-events'
     group_name = item == '.' ? 'root' : item.underscorify()
@@ -57,10 +57,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
   endif
 endforeach
 
+cat = [ python, '-c', 'import fileinput;[print(line) for line in fileinput.input()]', '@INPUT@' ]
 trace_events_all = custom_target('trace-events-all',
                                  output: 'trace-events-all',
                                  input: trace_events_files,
-                                 command: [ 'cat', '@INPUT@' ],
+                                 command: [ cat ],
                                  capture: true,
                                  install: get_option('trace_backends') != [ 'nop' ],
                                  install_dir: qemu_datadir)
--

2.49.0.windows.1

#3 lore raw

Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <[email protected]>:

Quoted 10 lines

scripts/tracetool/backend/ftrace.py def generate_h(event, group): · line 38

Quoted 6 lines
scripts/tracetool/backend/ftrace.py +5 -0
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()

Please do this in one place to avoid code duplication in the backends. Perhaps event.filename or a new field can hold the properly formatted value so backends don't need to call relpath() themselves.

I'll move the code to "tracetool/__init__.py".

Quoted 4 lines

I noticed that out_filename is also emitted with #line but, unlike event.filename, no special processing (relpath() or as_posix()) is used there. Is it possible to drop relpath() and avoid the whole issue?

"out_filename" is not a problem because it is a relative path in POSIX format. "relpath" was introduced in this commit 9d672e290475001fcecdcc9dc79ad088ff89d17f. I can not decide whether it should be dropped or not.

#4 lore raw
Quoted 20 lines · Oleg Tolmatcev

Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <[email protected]>:

Quoted 10 lines

scripts/tracetool/backend/ftrace.py def generate_h(event, group): · line 38

Quoted 6 lines
scripts/tracetool/backend/ftrace.py +5 -0
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()

Please do this in one place to avoid code duplication in the backends. Perhaps event.filename or a new field can hold the properly formatted value so backends don't need to call relpath() themselves.

I'll move the code to "tracetool/__init__.py".

Quoted 4 lines

I noticed that out_filename is also emitted with #line but, unlike event.filename, no special processing (relpath() or as_posix()) is used there. Is it possible to drop relpath() and avoid the whole issue?

Quoted 4 lines

"out_filename" is not a problem because it is a relative path in POSIX format. "relpath" was introduced in this commit 9d672e290475001fcecdcc9dc79ad088ff89d17f. I can not decide whether it should be dropped or not.

out_filename is the last argument in sys.argv[] and Event.filename comes from the previous arguments in sys.argv[].

Tracetool's sys.argv[] comes from trace/meson.build where the trace-events filenames are built like this:
trace_events_file = meson.project_source_root() / item / 'trace-events'

The output filename (sys.argv[-1]) happens to be built as a relative path:
fmt = '@0@-' + group_name + '.@1@'
...
output: fmt.format('trace', 'h')

It's inconsistent that out_filename is assumed to be a relative POSIX filename whereas the trace-events filenames are made relative by the code.

I think it's more robust for tracetool to make filenames relative than to assume whoever is invoking tracetool.py has already done that. It's also easier for meson.build to be able to pass an absolute path if it wants.

That line of thinking results in the following:
1. Add a posix_relpath() helper function to tracetool/__init__.py.
2. Use posix_relpath() whenever a #line filename is required.
3. Also use posix_relpath() on #line out_filename for consistency.

How does that sound?

Stefan

#5 lore raw

Am Di., 3. Juni 2025 um 19:56 Uhr schrieb Stefan Hajnoczi <[email protected]>:

Quoted 48 lines · Oleg Tolmatcev
Quoted 20 lines

Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <[email protected]>:

Quoted 10 lines

scripts/tracetool/backend/ftrace.py def generate_h(event, group): · line 38

Quoted 6 lines
scripts/tracetool/backend/ftrace.py +5 -0
+    try:
+        event_filename = os.path.relpath(event.filename)
+    except ValueError:
+        event_filename = event.filename
+    event_filename = PurePath(event_filename).as_posix()

Please do this in one place to avoid code duplication in the backends. Perhaps event.filename or a new field can hold the properly formatted value so backends don't need to call relpath() themselves.

I'll move the code to "tracetool/__init__.py".

Quoted 4 lines

I noticed that out_filename is also emitted with #line but, unlike event.filename, no special processing (relpath() or as_posix()) is used there. Is it possible to drop relpath() and avoid the whole issue?

Quoted 4 lines

"out_filename" is not a problem because it is a relative path in POSIX format. "relpath" was introduced in this commit 9d672e290475001fcecdcc9dc79ad088ff89d17f. I can not decide whether it should be dropped or not.

out_filename is the last argument in sys.argv[] and Event.filename comes from the previous arguments in sys.argv[].

Tracetool's sys.argv[] comes from trace/meson.build where the trace-events filenames are built like this:
trace_events_file = meson.project_source_root() / item / 'trace-events'

The output filename (sys.argv[-1]) happens to be built as a relative path:
fmt = '@0@-' + group_name + '.@1@'
...
output: fmt.format('trace', 'h')

It's inconsistent that out_filename is assumed to be a relative POSIX filename whereas the trace-events filenames are made relative by the code.

I think it's more robust for tracetool to make filenames relative than to assume whoever is invoking tracetool.py has already done that. It's also easier for meson.build to be able to pass an absolute path if it wants.

Quoted 6 lines

That line of thinking results in the following:
1. Add a posix_relpath() helper function to tracetool/__init__.py.
2. Use posix_relpath() whenever a #line filename is required.
3. Also use posix_relpath() on #line out_filename for consistency.

How does that sound?

Sounds good.
Oleg