aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/utils/universal.py
diff options
context:
space:
mode:
authorMarvin Scholz <epirat07@gmail.com>2022-11-22 14:39:24 +0100
committerDylan Baker <dylan@pnwbakers.com>2022-11-28 12:09:30 -0800
commit7c48cb513ab6e80b47001449ef367aeb175a029f (patch)
tree2a8330f5c902b6ddac791f8c21b37dffaa710b88 /mesonbuild/utils/universal.py
parent5022fd30e1a922ad7f2dfc81648d3c73c5f2aa22 (diff)
downloadmeson-7c48cb513ab6e80b47001449ef367aeb175a029f.zip
meson-7c48cb513ab6e80b47001449ef367aeb175a029f.tar.gz
meson-7c48cb513ab6e80b47001449ef367aeb175a029f.tar.bz2
utils: Popen_safe: Handle ENOEXEC to fail with an error message
This is much cleaner than to show a stack trace, where it is hard to figure out what is going wrong.
Diffstat (limited to 'mesonbuild/utils/universal.py')
-rw-r--r--mesonbuild/utils/universal.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index b1a301a..9fa590b 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -32,6 +32,7 @@ import typing as T
import textwrap
import copy
import pickle
+import errno
from mesonbuild import mlog
from .core import MesonException, HoldableObject
@@ -1413,12 +1414,19 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
# If write is not None, set stdin to PIPE so data can be sent.
if write is not None:
stdin = subprocess.PIPE
- if not sys.stdout.encoding or encoding.upper() != 'UTF-8':
- p, o, e = Popen_safe_legacy(args, write=write, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
- else:
- p = subprocess.Popen(args, universal_newlines=True, encoding=encoding, close_fds=False,
- stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
- o, e = p.communicate(write)
+
+ try:
+ if not sys.stdout.encoding or encoding.upper() != 'UTF-8':
+ p, o, e = Popen_safe_legacy(args, write=write, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
+ else:
+ p = subprocess.Popen(args, universal_newlines=True, encoding=encoding, close_fds=False,
+ stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
+ o, e = p.communicate(write)
+ except OSError as oserr:
+ if oserr.errno == errno.ENOEXEC:
+ raise MesonException(f'Failed running {args[0]!r}, binary or interpreter not executable.\n'
+ 'Possibly wrong architecture or the executable bit is not set.')
+ raise
# Sometimes the command that we run will call another command which will be
# without the above stdin workaround, so set the console mode again just in
# case.