diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2021-01-26 13:51:23 -0500 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-01-30 09:51:06 +0000 |
commit | 0626465ea8aa65b10776d5c4064e881fe0d6fa25 (patch) | |
tree | be11f7029bd7bd418494d45cf7f3de52cbaf435f /mesonbuild/scripts | |
parent | c321339b24f896d02b0839d1b1e5008eae405858 (diff) | |
download | meson-0626465ea8aa65b10776d5c4064e881fe0d6fa25.zip meson-0626465ea8aa65b10776d5c4064e881fe0d6fa25.tar.gz meson-0626465ea8aa65b10776d5c4064e881fe0d6fa25.tar.bz2 |
Fix executable as script on Windows
On Windows this would fail because of missing DLL:
```
mylib = library(...)
exe = executable(..., link_with: mylib)
meson.add_install_script(exe)
```
The reason is on Windows we cannot rely on rpath to find libraries from
build directory, they are searched in $PATH. We already have all that
mechanism in place for custom_target() using ExecutableSerialisation
class, so reuse it for install/dist/postconf scripts too.
This has bonus side effect to also use exe_wrapper for those scripts.
Fixes: #8187
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r-- | mesonbuild/scripts/meson_exe.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py index 751d39b..620f579 100644 --- a/mesonbuild/scripts/meson_exe.py +++ b/mesonbuild/scripts/meson_exe.py @@ -30,7 +30,7 @@ def buildparser() -> argparse.ArgumentParser: parser.add_argument('--capture') return parser -def run_exe(exe: ExecutableSerialisation) -> int: +def run_exe(exe: ExecutableSerialisation, extra_env: T.Optional[dict] = None) -> int: if exe.exe_runner: if not exe.exe_runner.found(): raise AssertionError('BUG: Can\'t run cross-compiled exe {!r} with not-found ' @@ -39,6 +39,8 @@ def run_exe(exe: ExecutableSerialisation) -> int: else: cmd_args = exe.cmd_args child_env = os.environ.copy() + if extra_env: + child_env.update(extra_env) if exe.env: child_env = exe.env.get_env(child_env) if exe.extra_paths: @@ -56,14 +58,21 @@ def run_exe(exe: ExecutableSerialisation) -> int: stderr=subprocess.PIPE) stdout, stderr = p.communicate() - if exe.pickled and p.returncode != 0: - print('while executing {!r}'.format(cmd_args)) - if p.returncode == 0xc0000135: # STATUS_DLL_NOT_FOUND on Windows indicating a common problem that is otherwise hard to diagnose raise FileNotFoundError('due to missing DLLs') - if exe.capture and p.returncode == 0: + if p.returncode != 0: + if exe.pickled: + print('while executing {!r}'.format(cmd_args)) + if not exe.capture: + print('--- stdout ---') + print(stdout.decode()) + print('--- stderr ---') + print(stderr.decode()) + return p.returncode + + if exe.capture: skip_write = False try: with open(exe.capture, 'rb') as cur: @@ -73,11 +82,8 @@ def run_exe(exe: ExecutableSerialisation) -> int: if not skip_write: with open(exe.capture, 'wb') as output: output.write(stdout) - else: - sys.stdout.buffer.write(stdout) - if stderr: - sys.stderr.buffer.write(stderr) - return p.returncode + + return 0 def run(args: T.List[str]) -> int: global options |