Skip to contentSkip to conversation

meson: fix Windows build

PATCH Superseded oltolm 2 participants 3 messages May 23, 2025 – May 24, 2025 Arm/Amlogic Meson SoC support

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

oltolm

author
#0 lore raw

PATCH 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        | 2 +-
 tests/include/meson.build           | 2 +-
 tests/tcg/plugins/meson.build       | 2 +-
 trace/meson.build                   | 4 ++--
 8 files changed, 30 insertions(+), 9 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 -1
index 52b4706cf..2e3bd4057 100644
@@ -413,4 +413,4 @@ endforeach
 
 run_target('precache-functional',
            depends: precache_all,
-           command: ['true'])
+           command: [python, '-c', ''])
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 +2 -2
index 3df454935..3a318713c 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()
@@ -60,7 +60,7 @@ endforeach
 trace_events_all = custom_target('trace-events-all',
                                  output: 'trace-events-all',
                                  input: trace_events_files,
-                                 command: [ 'cat', '@INPUT@' ],
+                                 command: [ python, '-c', 'import fileinput;[print(line) for line in fileinput.input()]', '@INPUT@' ],
                                  capture: true,
                                  install: get_option('trace_backends') != [ 'nop' ],
                                  install_dir: qemu_datadir)
Signature · 1 line
2.49.0.windows.1
#1 lore raw
Quoted 5 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.

Thanks for the patch! The Windows build configurations that we support currently are cross-building from Linux and native build with MSYS2. MSYS2 is sufficiently POSIX-like, and also has a nice package manager.

Can you share how you set up your build environment, and especially where you get all the dependencies? Generally we'd prefer to have it covered in CI to avoid that it breaks again.

Some more comments below.

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

Quoted 13 lines

import os.path

scripts/tracetool/backend/ftrace.py +5 -0
+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

Can this actually happen during the build? (Same for other backends)

tests/functional/meson.build endforeach · line 416

Quoted 10 lines
tests/functional/meson.build +1 -1
index 52b4706cf..2e3bd4057 100644
@@ -413,4 +413,4 @@ endforeach
 
  run_target('precache-functional',
             depends: precache_all,
-           command: ['true'])
+           command: [python, '-c', ''])

I wonder if this can be replaced with alias_target() too; and also the pre-existing code suggests that alias_target needs at least one target, but is that really true?

So, maybe all or most uses of 'true' can just go away.

trace/meson.build trace_events_files = [] · line 7

Quoted 10 lines
trace/meson.build +1 -1
index 3df454935..3a318713c 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()

Even better.

trace/meson.build endforeach · line 63

Quoted 5 lines
trace/meson.build +1 -1
  trace_events_all = custom_target('trace-events-all',
                                   output: 'trace-events-all',
                                   input: trace_events_files,
-                                 command: [ 'cat', '@INPUT@' ],
+                                 command: [ python, '-c', 'import fileinput;[print(line) for line in fileinput.input()]', '@INPUT@' ],

Maybe put the command in a variable name cat, like

cat = [ python, '-c',
'import fileinput;[print(line) for line in fileinput.input()]']

Thanks,

Paolo

#2 lore raw

Am Fr., 23. Mai 2025 um 23:28 Uhr schrieb Paolo Bonzini <[email protected]>:

Quoted 8 lines

Thanks for the patch! The Windows build configurations that we support currently are cross-building from Linux and native build with MSYS2. MSYS2 is sufficiently POSIX-like, and also has a nice package manager.

Can you share how you set up your build environment, and especially where you get all the dependencies? Generally we'd prefer to have it covered in CI to avoid that it breaks again.

I use MSYS2, but I only use bash it to run configure initially and afterwards I use cmd.exe for running Meson and Ninja.

Quoted 11 lines

Some more comments below.

Quoted 9 lines

import os.path

scripts/tracetool/backend/ftrace.py +1 -0
+from pathlib import PurePath
 
  from tracetool import out
@@ -30,6 +31,12 @@ def generate_h(event, group):
      if len(event.args) > 0:
          argnames = ", " + argnames
 
Quoted 6 lines

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

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

Can this actually happen during the build? (Same for other backends)

I only tested with the log backend.

[18/1577] Generating trace/trace-crypto.h with a custom command
FAILED: trace/trace-crypto.h
"C:\msys64\mingw64\bin\python.exe" "C:/src/qemu/scripts/tracetool.py" "--backend=log" "--group=crypto" "--format=h" "C:/src/qemu/crypto/trace-events" "trace/trace-crypto.h"
Traceback (most recent call last):
File "C:/src/qemu/scripts/tracetool.py", line 140, in <module>
main(sys.argv)
File "C:/src/qemu/scripts/tracetool.py", line 134, in main
tracetool.generate(events, arg_group, arg_format, arg_backends,
File "C:\src\qemu\scripts\tracetool\__init__.py", line 449, in generate
tracetool.format.generate(events, format, backend, group)
File "C:\src\qemu\scripts\tracetool\format\__init__.py", line 84, in generate
func(events, backend, group)
File "C:\src\qemu\scripts\tracetool\format\h.py", line 70, in generate
backend.generate(e, group)
File "C:\src\qemu\scripts\tracetool\backend\__init__.py", line 119,
in generate
self._run_function("generate_%s", event, group)
File "C:\src\qemu\scripts\tracetool\backend\__init__.py", line 113,
in _run_function

    func(*args, **kwargs)
  File "C:\src\qemu\scripts\tracetool\backend\log.py", line 58, in generate_h
    event_filename=os.path.relpath(event.filename),
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "<frozen ntpath>", line 808, in relpath
ValueError: path is on mount 'C:', start on mount 'E:'

Quoted 15 lines

tests/functional/meson.build endforeach · line 416

Quoted 10 lines
tests/functional/meson.build +1 -1
index 52b4706cf..2e3bd4057 100644
@@ -413,4 +413,4 @@ endforeach
 
  run_target('precache-functional',
             depends: precache_all,
-           command: ['true'])
+           command: [python, '-c', ''])

I wonder if this can be replaced with alias_target() too; and also the pre-existing code suggests that alias_target needs at least one target, but is that really true?

Quoted 1 line

So, maybe all or most uses of 'true' can just go away.

I could replace this one with alias_target(), but it does need at least one dependency so I could not replace the others.

Best regards
Oleg Tolmatcev