File 0002-Pass-unique-and-sorted-native-paths-for-executable-o.patch of Package meson
From ac6415726e69ee65eeabc0ddfd2db0e72ece979d Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Wed, 11 Jan 2023 10:25:28 +0100
Subject: [PATCH 2/2] Pass unique and sorted native paths for executable or
test execution
The paths to the build directory must be placed before the system paths
to avoid using incorrect binaries.
To detect multiple path definitions, the paths are first normalized.
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de
---
mesonbuild/mtest.py | 6 +++++-
mesonbuild/scripts/meson_exe.py | 8 +++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 82a801ef0..813780673 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -1417,7 +1417,11 @@ class SingleTestRunner:
self.cmd = self._get_cmd()
if self.cmd and self.test.extra_paths:
- env['PATH'] = os.pathsep.join(self.test.extra_paths + ['']) + env['PATH']
+ build_dir = os.getcwd()
+ paths = list(set([os.path.normpath(p) for p in self.test.extra_paths]
+ + env.get('PATH', '').split(os.pathsep)))
+ paths.sort(key=lambda x: not build_dir in x)
+ env['PATH'] = os.pathsep.join(paths)
winecmd = []
for c in self.cmd:
winecmd.append(c)
diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py
index 7d02208d6..e981cad72 100644
--- a/mesonbuild/scripts/meson_exe.py
+++ b/mesonbuild/scripts/meson_exe.py
@@ -34,13 +34,15 @@ def run_exe(exe: ExecutableSerialisation, extra_env: T.Optional[T.Dict[str, str]
if exe.env:
child_env = exe.env.get_env(child_env)
if exe.extra_paths:
- child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) +
- child_env['PATH'])
+ build_dir = os.getcwd()
+ paths = list(set([os.path.normpath(p) for p in exe.extra_paths]
+ + child_env.get('PATH', '').split(os.pathsep)))
+ paths.sort(key=lambda x: not build_dir in x)
+ child_env['PATH'] = os.pathsep.join(paths)
if exe.exe_wrapper and any('wine' in i for i in exe.exe_wrapper.get_command()):
from .. import mesonlib
wine_paths = list(set(['Z:' + os.path.normpath(p) for p in exe.extra_paths]
+ child_env.get('WINEPATH', '').split(';')))
- build_dir = os.getcwd()
wine_paths.sort(key=lambda x: not build_dir in x)
child_env['WINEPATH'] = mesonlib.get_wine_shortpath(exe.exe_wrapper.get_command(), wine_paths, exe.workdir)
--
2.47.1