aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek.chauhan@gmail.com>2016-04-15 00:17:57 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2016-04-14 21:47:57 +0300
commit563b978bf268ef9f6bf717929b472bc078fe95de (patch)
tree3e5234daa86bd3fe9124eb3ef07fb973dca96dd8
parentb56f008f805803f917c62462af9776149e2b7e13 (diff)
downloadmeson-563b978bf268ef9f6bf717929b472bc078fe95de.zip
meson-563b978bf268ef9f6bf717929b472bc078fe95de.tar.gz
meson-563b978bf268ef9f6bf717929b472bc078fe95de.tar.bz2
On failure, print exceptions encountered while searching for compilers (#515)
-rw-r--r--mesonbuild/environment.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 6ff93cb..c4591b4 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -192,6 +192,7 @@ class Environment():
ccache = self.detect_ccache()
is_cross = False
exe_wrap = None
+ popen_exceptions = {}
for compiler in compilers:
try:
basename = os.path.basename(compiler).lower()
@@ -199,9 +200,10 @@ class Environment():
arg = '/?'
else:
arg = '--version'
- p = subprocess.Popen([compiler] + [arg], stdout=subprocess.PIPE,
+ p = subprocess.Popen([compiler, arg], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- except OSError:
+ except OSError as e:
+ popen_exceptions[' '.join([compiler, arg])] = e
continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
@@ -232,7 +234,12 @@ class Environment():
# everything else to stdout. Why? Lord only knows.
version = re.search(Environment.version_regex, err).group()
return VisualStudioCCompiler([compiler], version, is_cross, exe_wrap)
- raise EnvironmentException('Unknown compiler(s): "' + ', '.join(compilers) + '"')
+ errmsg = 'Unknown compiler(s): "' + ', '.join(compilers) + '"'
+ if popen_exceptions:
+ errmsg += '\nThe follow exceptions were encountered:'
+ for (c, e) in popen_exceptions.items():
+ errmsg += '\nRunning "{0}" gave "{1}"'.format(c, e)
+ raise EnvironmentException(errmsg)
def detect_fortran_compiler(self, want_cross):
evar = 'FC'
@@ -248,13 +255,15 @@ class Environment():
compilers = self.default_fortran
is_cross = False
exe_wrap = None
+ popen_exceptions = {}
for compiler in compilers:
for arg in ['--version', '-V']:
try:
- p = subprocess.Popen([compiler] + [arg],
+ p = subprocess.Popen([compiler, arg],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- except OSError:
+ except OSError as e:
+ popen_exceptions[' '.join([compiler, arg])] = e
continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
@@ -292,8 +301,12 @@ class Environment():
if 'NAG Fortran' in err:
return NAGFortranCompiler([compiler], version, is_cross, exe_wrap)
-
- raise EnvironmentException('Unknown compiler(s): "' + ', '.join(compilers) + '"')
+ errmsg = 'Unknown compiler(s): "' + ', '.join(compilers) + '"'
+ if popen_exceptions:
+ errmsg += '\nThe follow exceptions were encountered:'
+ for (c, e) in popen_exceptions.items():
+ errmsg += '\nRunning "{0}" gave "{1}"'.format(c, e)
+ raise EnvironmentException(errmsg)
def get_scratch_dir(self):
return self.scratch_dir
@@ -319,6 +332,7 @@ class Environment():
ccache = self.detect_ccache()
is_cross = False
exe_wrap = None
+ popen_exceptions = {}
for compiler in compilers:
basename = os.path.basename(compiler).lower()
if basename == 'cl' or basename == 'cl.exe':
@@ -329,7 +343,8 @@ class Environment():
p = subprocess.Popen([compiler, arg],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- except OSError:
+ except OSError as e:
+ popen_exceptions[' '.join([compiler, arg])] = e
continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
@@ -358,7 +373,12 @@ class Environment():
if 'Microsoft' in out or 'Microsoft' in err:
version = re.search(Environment.version_regex, err).group()
return VisualStudioCPPCompiler([compiler], version, is_cross, exe_wrap)
- raise EnvironmentException('Unknown compiler(s) "' + ', '.join(compilers) + '"')
+ errmsg = 'Unknown compiler(s): "' + ', '.join(compilers) + '"'
+ if popen_exceptions:
+ errmsg += '\nThe follow exceptions were encountered:'
+ for (c, e) in popen_exceptions.items():
+ errmsg += '\nRunning "{0}" gave "{1}"'.format(c, e)
+ raise EnvironmentException(errmsg)
def detect_objc_compiler(self, want_cross):
if self.is_cross_build() and want_cross: