When a CustomTarget is run with a command that is an executable built by the project which also has a DLL built in the same project as a dependency, the EXE can't run on Windows because the DLL can't be found. On UNIX-like systems, we set the RPATH using the linker so these dependencies can be found, but on Windows the only way is to set the PATH environment variable. The same problem exists for tests, so we reuse that infrastructure by creating a new meson_exe.py script that can be used as a wrapper to run CustomTarget commands on Windows. This can later also be extended to add support for setting an environment while calling the command needed to generate a CustomTarget: https://github.com/mesonbuild/meson/issues/266pull/494/head
parent
563b978bf2
commit
e3bc2e5c68
4 changed files with 135 additions and 2 deletions
@ -0,0 +1,74 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# Copyright 2013-2016 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import os |
||||
import sys |
||||
import argparse |
||||
import pickle |
||||
import platform |
||||
import subprocess |
||||
|
||||
import mesonbuild |
||||
|
||||
options = None |
||||
|
||||
parser = argparse.ArgumentParser() |
||||
parser.add_argument('args', nargs='+') |
||||
|
||||
def is_windows(): |
||||
platname = platform.system().lower() |
||||
return platname == 'windows' or 'mingw' in platname |
||||
|
||||
def run_with_mono(fname): |
||||
if fname.endswith('.exe') and not is_windows(): |
||||
return True |
||||
return False |
||||
|
||||
def run_exe(exe): |
||||
if exe.fname[0].endswith('.jar'): |
||||
cmd = ['java', '-jar'] + exe.fname |
||||
elif not exe.is_cross and run_with_mono(exe.fname[0]): |
||||
cmd = ['mono'] + exe.fname |
||||
else: |
||||
if exe.is_cross: |
||||
if exe.exe_runner is None: |
||||
raise Exception('BUG: Trying to run cross-compiled exes with no wrapper') |
||||
else: |
||||
cmd = [exe.exe_runner] + exe.fname |
||||
else: |
||||
cmd = exe.fname |
||||
child_env = os.environ.copy() |
||||
child_env.update(exe.env) |
||||
if len(exe.extra_paths) > 0: |
||||
child_env['PATH'] = child_env['PATH'] + ';'.join([''] + exe.extra_paths) |
||||
p = subprocess.Popen(cmd + exe.cmd_args, |
||||
stdout=subprocess.PIPE, |
||||
stderr=subprocess.PIPE, |
||||
env=child_env, |
||||
cwd=exe.workdir) |
||||
|
||||
def run(args): |
||||
global options |
||||
options = parser.parse_args(args) |
||||
if len(options.args) != 1: |
||||
print('Test runner for Meson. Do not run on your own, mmm\'kay?') |
||||
print(sys.argv[0] + ' [data file]') |
||||
exe_data_file = options.args[0] |
||||
exe = pickle.load(open(exe_data_file, 'rb')) |
||||
run_exe(exe) |
||||
|
||||
if __name__ == '__main__': |
||||
sys.exit(run(sys.argv[1:])) |
Loading…
Reference in new issue