From efa9b75d5d21018b27f593ee65ea562d10d6dc2c Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 24 May 2018 03:26:36 +0530 Subject: [PATCH] Set WINEPATH when running serialized executables When the exe runner is `wine` or `wine32` or `wine64`, etc. This allows people to run tests with wine. Note that you also have to set WINEPATH to point to your custom prefix(es) if your tests use external dependencies. Closes https://github.com/mesonbuild/meson/issues/3620 --- mesonbuild/backend/backends.py | 8 ++++++-- mesonbuild/backend/ninjabackend.py | 6 +++++- mesonbuild/mtest.py | 16 ++++++++++++++++ mesonbuild/scripts/meson_exe.py | 9 +++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 44c3caeca..e56d18d8d 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -617,8 +617,12 @@ class Backend: exe_wrapper = self.environment.cross_info.config['binaries'].get('exe_wrapper', None) else: exe_wrapper = None - if mesonlib.is_windows() or mesonlib.is_cygwin(): - extra_paths = self.determine_windows_extra_paths(exe, []) + if mesonlib.for_windows(is_cross, self.environment) or \ + mesonlib.for_cygwin(is_cross, self.environment): + extra_bdeps = [] + if isinstance(exe, build.CustomTarget): + extra_bdeps = exe.get_transitive_build_target_deps() + extra_paths = self.determine_windows_extra_paths(exe, extra_bdeps) else: extra_paths = [] cmd_args = [] diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b32733885..6082c8502 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -530,7 +530,11 @@ int dummy; # the project, we need to set PATH so the DLLs are found. We use # a serialized executable wrapper for that and check if the # CustomTarget command needs extra paths first. - if mesonlib.is_windows() or mesonlib.is_cygwin(): + is_cross = self.environment.is_cross_build() and \ + self.environment.cross_info.need_cross_compiler() and \ + self.environment.cross_info.need_exe_wrapper() + if mesonlib.for_windows(is_cross, self.environment) or \ + mesonlib.for_cygwin(is_cross, self.environment): extra_bdeps = target.get_transitive_build_target_deps() extra_paths = self.determine_windows_extra_paths(target.command[0], extra_bdeps) if extra_paths: diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 9dd4cbddb..2a052d6a8 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -231,11 +231,27 @@ class SingleTestRunner: self.test.timeout = None return self._run_cmd(wrap + cmd + self.test.cmd_args + self.options.test_args) + @staticmethod + def _substring_in_list(substr, strlist): + for s in strlist: + if substr in s: + return True + return False + def _run_cmd(self, cmd): starttime = time.time() if len(self.test.extra_paths) > 0: self.env['PATH'] = os.pathsep.join(self.test.extra_paths + ['']) + self.env['PATH'] + if self._substring_in_list('wine', cmd): + wine_paths = ['Z:' + p for p in self.test.extra_paths] + wine_path = ';'.join(wine_paths) + # Don't accidentally end with an `;` because that will add the + # current directory and might cause unexpected behaviour + if 'WINEPATH' in self.env: + self.env['WINEPATH'] = wine_path + ';' + self.env['WINEPATH'] + else: + self.env['WINEPATH'] = wine_path # If MALLOC_PERTURB_ is not set, or if it is set to an empty value, # (i.e., the test or the environment don't explicitly set it), set diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py index 46d501faa..a70accac6 100644 --- a/mesonbuild/scripts/meson_exe.py +++ b/mesonbuild/scripts/meson_exe.py @@ -57,6 +57,15 @@ def run_exe(exe): if len(exe.extra_paths) > 0: child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) + child_env['PATH']) + if exe.exe_runner and 'wine' in exe.exe_runner: + wine_paths = ['Z:' + p for p in exe.extra_paths] + wine_path = ';'.join(wine_paths) + # Don't accidentally end with an `;` because that will add the + # current directory and might cause unexpected behaviour + if 'WINEPATH' in child_env: + child_env['WINEPATH'] = wine_path + ';' + child_env['WINEPATH'] + else: + child_env['WINEPATH'] = wine_path p = subprocess.Popen(cmd + exe.cmd_args, env=child_env, cwd=exe.workdir, close_fds=False,