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>
This commit is contained in:
oltolm 2025-06-13 00:15:22 +02:00 committed by Stefan Hajnoczi
parent a6f0227759
commit 9761ad5f65
10 changed files with 23 additions and 19 deletions

View file

@ -24,7 +24,7 @@ endif
if t.length() > 0 if t.length() > 0
alias_target('contrib-plugins', t) alias_target('contrib-plugins', t)
else else
run_target('contrib-plugins', command: find_program('true')) run_target('contrib-plugins', command: [python, '-c', ''])
endif endif
plugin_modules += t plugin_modules += t

View file

@ -33,7 +33,7 @@ if host_os == 'windows'
input: qemu_plugin_symbols, input: qemu_plugin_symbols,
output: 'qemu_plugin_api.def', output: 'qemu_plugin_api.def',
capture: true, capture: true,
command: ['sed', '-e', '0,/^/s//EXPORTS/; s/[{};]//g', '@INPUT@']) command: [python, '-c', 'import fileinput, re; print("EXPORTS", end=""); [print(re.sub(r"[{};]", "", line), end="") for line in fileinput.input()]', '@INPUT@'])
# then use dlltool to assemble a delaylib. # then use dlltool to assemble a delaylib.
# The delaylib will have an "imaginary" name (qemu.exe), that is used by the # The delaylib will have an "imaginary" name (qemu.exe), that is used by the

View file

@ -12,12 +12,14 @@ __maintainer__ = "Stefan Hajnoczi"
__email__ = "stefanha@redhat.com" __email__ = "stefanha@redhat.com"
import os
import re import re
import sys import sys
import weakref import weakref
from pathlib import PurePath
import tracetool.format
import tracetool.backend import tracetool.backend
import tracetool.format
def error_write(*lines): def error_write(*lines):
@ -36,7 +38,7 @@ out_fobj = sys.stdout
def out_open(filename): def out_open(filename):
global out_filename, out_fobj global out_filename, out_fobj
out_filename = filename out_filename = posix_relpath(filename)
out_fobj = open(filename, 'wt') out_fobj = open(filename, 'wt')
def out(*lines, **kwargs): def out(*lines, **kwargs):
@ -308,7 +310,7 @@ class Event(object):
fmt = [fmt_trans, fmt] fmt = [fmt_trans, fmt]
args = Arguments.build(groups["args"]) 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): def __repr__(self):
"""Evaluable string representation for this object.""" """Evaluable string representation for this object."""
@ -447,3 +449,10 @@ def generate(events, group, format, backends,
tracetool.backend.dtrace.PROBEPREFIX = probe_prefix tracetool.backend.dtrace.PROBEPREFIX = probe_prefix
tracetool.format.generate(events, format, backend, group) 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()

View file

@ -12,8 +12,6 @@ __maintainer__ = "Stefan Hajnoczi"
__email__ = "stefanha@redhat.com" __email__ = "stefanha@redhat.com"
import os.path
from tracetool import out from tracetool import out
@ -47,7 +45,7 @@ def generate_h(event, group):
args=event.args, args=event.args,
event_id="TRACE_" + event.name.upper(), event_id="TRACE_" + event.name.upper(),
event_lineno=event.lineno, event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename), event_filename=event.filename,
fmt=event.fmt.rstrip("\n"), fmt=event.fmt.rstrip("\n"),
argnames=argnames) argnames=argnames)

View file

@ -12,8 +12,6 @@ __maintainer__ = "Stefan Hajnoczi"
__email__ = "stefanha@redhat.com" __email__ = "stefanha@redhat.com"
import os.path
from tracetool import out from tracetool import out
@ -55,7 +53,7 @@ def generate_h(event, group):
' }', ' }',
cond=cond, cond=cond,
event_lineno=event.lineno, event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename), event_filename=event.filename,
name=event.name, name=event.name,
fmt=event.fmt.rstrip("\n"), fmt=event.fmt.rstrip("\n"),
argnames=argnames) argnames=argnames)

View file

@ -12,8 +12,6 @@ __maintainer__ = "Stefan Hajnoczi"
__email__ = "stefanha@redhat.com" __email__ = "stefanha@redhat.com"
import os.path
from tracetool import out from tracetool import out
@ -43,7 +41,7 @@ def generate_h(event, group):
' }', ' }',
cond=cond, cond=cond,
event_lineno=event.lineno, event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename), event_filename=event.filename,
name=event.name, name=event.name,
fmt=event.fmt.rstrip("\n"), fmt=event.fmt.rstrip("\n"),
argnames=argnames) argnames=argnames)

View file

@ -416,4 +416,4 @@ endforeach
run_target('precache-functional', run_target('precache-functional',
depends: precache_all, depends: precache_all,
command: ['true']) command: [python, '-c', ''])

View file

@ -13,4 +13,4 @@ test_qapi_outputs_extra = [
test_qapi_files_extra = custom_target('QAPI test (include)', test_qapi_files_extra = custom_target('QAPI test (include)',
output: test_qapi_outputs_extra, output: test_qapi_outputs_extra,
input: test_qapi_files, input: test_qapi_files,
command: 'true') command: [python, '-c', ''])

View file

@ -17,7 +17,7 @@ endif
if t.length() > 0 if t.length() > 0
alias_target('test-plugins', t) alias_target('test-plugins', t)
else else
run_target('test-plugins', command: find_program('true')) run_target('test-plugins', command: [python, '-c', ''])
endif endif
plugin_modules += t plugin_modules += t

View file

@ -4,7 +4,7 @@ trace_events_files = []
foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
if item in qapi_trace_events if item in qapi_trace_events
trace_events_file = item trace_events_file = item
group_name = item.full_path().split('/')[-1].underscorify() group_name = fs.name(item).underscorify()
else else
trace_events_file = meson.project_source_root() / item / 'trace-events' trace_events_file = meson.project_source_root() / item / 'trace-events'
group_name = item == '.' ? 'root' : item.underscorify() group_name = item == '.' ? 'root' : item.underscorify()
@ -57,10 +57,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
endif endif
endforeach endforeach
cat = [ python, '-c', 'import fileinput; [print(line, end="") for line in fileinput.input()]', '@INPUT@' ]
trace_events_all = custom_target('trace-events-all', trace_events_all = custom_target('trace-events-all',
output: 'trace-events-all', output: 'trace-events-all',
input: trace_events_files, input: trace_events_files,
command: [ 'cat', '@INPUT@' ], command: cat,
capture: true, capture: true,
install: get_option('trace_backends') != [ 'nop' ], install: get_option('trace_backends') != [ 'nop' ],
install_dir: qemu_datadir) install_dir: qemu_datadir)