From 279cc58872618067df6eb8ed66126c5001d4b805 Mon Sep 17 00:00:00 2001
From: Harrison Booth <harrisontbooth@gmail.com>
Date: Fri, 24 Jul 2026 09:55:16 -0500
Subject: [PATCH v1 1/2] meson: Honor executable wrappers for regression tests

Meson only sets MESON_EXE_WRAPPER for tests it recognizes as
cross-built.  Regression tests invoke their host runner through the
native Python testwrap script, but passing runner.full_path() as a
string hides the cross-built executable from Meson.

Pass the executable target to test(), resolve Meson's build-relative
argument before testwrap changes directories, and invoke the runner
through MESON_EXE_WRAPPER when it is set.
---
 meson.build        |  2 +-
 src/tools/testwrap | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index f4cde249242..afc57548a08 100644
--- a/meson.build
+++ b/meson.build
@@ -3985,7 +3985,7 @@ foreach test_dir : tests
         fallback_dbname.format(test_dir['name']))
 
       test_command_base = [
-        runner.full_path(),
+        runner,
         '--inputdir', t.get('inputdir', test_dir['sd']),
         '--expecteddir', t.get('expecteddir', test_dir['sd']),
         '--bindir', '',
diff --git a/src/tools/testwrap b/src/tools/testwrap
index e91296ecd15..6301cd4faed 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 import argparse
+import shlex
 import shutil
 import subprocess
 import os
@@ -20,6 +21,9 @@ parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
 
+if args.test_command and not os.path.isabs(args.test_command[0]):
+    args.test_command[0] = os.path.join(args.basedir, args.test_command[0])
+
 testdir = '{}/testrun/{}/{}'.format(
     args.basedir, args.testgroup, args.testname)
 
@@ -61,7 +65,16 @@ else:
     if args.tests:
         args.test_command.extend(args.tests)
 
-sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
+test_command = args.test_command
+exe_wrapper = env_dict.get('MESON_EXE_WRAPPER')
+if exe_wrapper:
+    if os.name == 'nt':
+        test_command = '{} {}'.format(
+            exe_wrapper, subprocess.list2cmdline(test_command))
+    else:
+        test_command = shlex.split(exe_wrapper) + test_command
+
+sp = subprocess.Popen(test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
 # directive, so Meson computes the file result like Perl does.  This could
-- 
2.53.0.windows.2

