On Thu, May 29, 2025 at 4:55 AM oltolm <[email protected]> wrote:
>
> 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.
>
> Signed-off-by: oltolm <[email protected]>
> ---
> 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(-)
>
> diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
> index fa8a426c8..1876bc784 100644
> --- a/contrib/plugins/meson.build
> +++ b/contrib/plugins/meson.build
> @@ -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
> diff --git a/scripts/tracetool/backend/ftrace.py
> b/scripts/tracetool/backend/ftrace.py
> index baed2ae61..81a5f93b3 100644
> --- a/scripts/tracetool/backend/ftrace.py
> +++ b/scripts/tracetool/backend/ftrace.py
> @@ -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()
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?
> +
> 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)
>
> diff --git a/scripts/tracetool/backend/log.py
> b/scripts/tracetool/backend/log.py
> index de27b7e62..241fbbbd0 100644
> --- a/scripts/tracetool/backend/log.py
> +++ b/scripts/tracetool/backend/log.py
> @@ -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)
> diff --git a/scripts/tracetool/backend/syslog.py
> b/scripts/tracetool/backend/syslog.py
> index 012970f6c..2e010e7c9 100644
> --- a/scripts/tracetool/backend/syslog.py
> +++ b/scripts/tracetool/backend/syslog.py
> @@ -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)
> diff --git a/tests/functional/meson.build b/tests/functional/meson.build
> index 52b4706cf..ee222888f 100644
> --- a/tests/functional/meson.build
> +++ b/tests/functional/meson.build
> @@ -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)
> diff --git a/tests/include/meson.build b/tests/include/meson.build
> index 9abba308f..8e8d1ec4e 100644
> --- a/tests/include/meson.build
> +++ b/tests/include/meson.build
> @@ -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', ''])
> diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build
> index 41f02f2c7..029342282 100644
> --- a/tests/tcg/plugins/meson.build
> +++ b/tests/tcg/plugins/meson.build
> @@ -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
> diff --git a/trace/meson.build b/trace/meson.build
> index 3df454935..ebce0154c 100644
> --- a/trace/meson.build
> +++ b/trace/meson.build
> @@ -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
>
>