From 1c24ed9c389932b520ef7dac9469967e28638b74 Mon Sep 17 00:00:00 2001
From: Harrison Booth <harrisontbooth@gmail.com>
Date: Mon, 12 Oct 2026 15:54:34 -0500
Subject: [PATCH v2] meson: Support ECPG tests in runnable cross builds

Use can_run_host_binaries() to enable ECPG tests for runnable cross builds.
Make the regression test wrapper honor MESON_EXE_WRAPPER and resolve
relative runner paths, so execution through a wrapper also works.
---
 meson.build                          |  2 +-
 src/interfaces/ecpg/test/meson.build |  4 ++--
 src/tools/testwrap                   | 15 ++++++++++++++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/meson.build b/meson.build
index d05634fef0d..61f0348058a 100644
--- a/meson.build
+++ b/meson.build
@@ -3992,7 +3992,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/interfaces/ecpg/test/meson.build b/src/interfaces/ecpg/test/meson.build
index 7f5b950c186..9397dd4d6f7 100644
--- a/src/interfaces/ecpg/test/meson.build
+++ b/src/interfaces/ecpg/test/meson.build
@@ -1,7 +1,7 @@
 # Copyright (c) 2022-2026, PostgreSQL Global Development Group
 
-# can't run ecpg to build test dependencies, at least not without an emulator
-if meson.is_cross_build()
+# We need to run ecpg to build test dependencies.
+if not meson.can_run_host_binaries()
   subdir_done()
 endif
 
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
