qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] meson: fix Windows build
@ 2025-05-29  8:54 oltolm
  2025-06-02  8:16 ` Philippe Mathieu-Daudé
  2025-06-02 18:44 ` Stefan Hajnoczi
  0 siblings, 2 replies; 6+ messages in thread
From: oltolm @ 2025-05-29  8:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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.

Signed-off-by: oltolm <oleg.tolmatcev@gmail.com>
---
 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()
+
     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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] meson: fix Windows build
  2025-05-29  8:54 [PATCH v2] meson: fix Windows build oltolm
@ 2025-06-02  8:16 ` Philippe Mathieu-Daudé
  2025-06-02 18:44 ` Stefan Hajnoczi
  1 sibling, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-02  8:16 UTC (permalink / raw)
  To: oltolm, qemu-devel; +Cc: Stefan Hajnoczi, Mads Ynddal, Pierrick Bouvier

(Cc'ing maintainers)

On 29/5/25 10:54, oltolm 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 <oleg.tolmatcev@gmail.com>
> ---
>   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()
> +
>       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)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] meson: fix Windows build
  2025-05-29  8:54 [PATCH v2] meson: fix Windows build oltolm
  2025-06-02  8:16 ` Philippe Mathieu-Daudé
@ 2025-06-02 18:44 ` Stefan Hajnoczi
  2025-06-03 16:59   ` Oleg Tolmatcev
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2025-06-02 18:44 UTC (permalink / raw)
  To: oltolm; +Cc: qemu-devel

On Thu, May 29, 2025 at 4:55 AM oltolm <oleg.tolmatcev@gmail.com> 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 <oleg.tolmatcev@gmail.com>
> ---
>  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
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] meson: fix Windows build
  2025-06-02 18:44 ` Stefan Hajnoczi
@ 2025-06-03 16:59   ` Oleg Tolmatcev
  2025-06-03 17:56     ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Tolmatcev @ 2025-06-03 16:59 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <stefanha@gmail.com>:
>
> > +    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".

> 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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] meson: fix Windows build
  2025-06-03 16:59   ` Oleg Tolmatcev
@ 2025-06-03 17:56     ` Stefan Hajnoczi
  2025-06-03 20:46       ` Oleg Tolmatcev
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2025-06-03 17:56 UTC (permalink / raw)
  To: Oleg Tolmatcev; +Cc: qemu-devel

On Tue, Jun 3, 2025 at 1:00 PM Oleg Tolmatcev <oleg.tolmatcev@gmail.com> wrote:
>
> Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <stefanha@gmail.com>:
> >
> > > +    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".
>
> > 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.

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] meson: fix Windows build
  2025-06-03 17:56     ` Stefan Hajnoczi
@ 2025-06-03 20:46       ` Oleg Tolmatcev
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Tolmatcev @ 2025-06-03 20:46 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

Am Di., 3. Juni 2025 um 19:56 Uhr schrieb Stefan Hajnoczi <stefanha@gmail.com>:
>
> On Tue, Jun 3, 2025 at 1:00 PM Oleg Tolmatcev <oleg.tolmatcev@gmail.com> wrote:
> >
> > Am Mo., 2. Juni 2025 um 20:45 Uhr schrieb Stefan Hajnoczi <stefanha@gmail.com>:
> > >
> > > > +    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".
> >
> > > 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.
>
> 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?

Sounds good.
Oleg


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-03 20:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29  8:54 [PATCH v2] meson: fix Windows build oltolm
2025-06-02  8:16 ` Philippe Mathieu-Daudé
2025-06-02 18:44 ` Stefan Hajnoczi
2025-06-03 16:59   ` Oleg Tolmatcev
2025-06-03 17:56     ` Stefan Hajnoczi
2025-06-03 20:46       ` Oleg Tolmatcev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).