aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-07-06 23:47:15 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-07-07 04:33:24 -0700
commit2093d45a4e1203d868d200628918472877c7ec31 (patch)
treea7253981585f71f5bd3a0053deff8ed90ad690ee
parent80392225a61a5baa28ef1f45bfc19b4623d2d188 (diff)
downloadmeson-2093d45a4e1203d868d200628918472877c7ec31.zip
meson-2093d45a4e1203d868d200628918472877c7ec31.tar.gz
meson-2093d45a4e1203d868d200628918472877c7ec31.tar.bz2
Print a more usable message when a subproject fails to configure
Instead of just printing the message in the exception, if it's a MesonException, also print the file and the line number. If it's an unknown exception, print the entire traceback so that we can pin-point what the Meson bug causing it is.
-rw-r--r--mesonbuild/interpreter.py12
-rw-r--r--mesonbuild/interpreterbase.py2
-rw-r--r--mesonbuild/mesonlib.py10
-rw-r--r--mesonbuild/mlog.py8
4 files changed, 24 insertions, 8 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 121fdb7..833e982 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -36,6 +36,7 @@ import re, shlex
import subprocess
from collections import namedtuple
from pathlib import PurePath
+import traceback
import importlib
@@ -2960,9 +2961,14 @@ root and issuing %s.
# If the subproject execution failed in a non-fatal way, don't raise an
# exception; let the caller handle things.
except Exception as e:
- mlog.log('Couldn\'t use fallback subproject in',
- mlog.bold(os.path.join(self.subproject_dir, dirname)),
- 'for the dependency', mlog.bold(display_name), '\nReason:', str(e))
+ msg = ['Couldn\'t use fallback subproject in',
+ mlog.bold(os.path.join(self.subproject_dir, dirname)),
+ 'for the dependency', mlog.bold(display_name), '\nReason:']
+ if isinstance(e, mesonlib.MesonException):
+ msg.append(e.get_msg_with_context())
+ else:
+ msg.append(traceback.format_exc())
+ mlog.log(*msg)
return None
dep = self.get_subproject_dep(name, dirname, varname, kwargs.get('required', True))
if not dep:
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index dfdccb1..64177ab 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -394,7 +394,7 @@ class InterpreterBase:
self.current_lineno = cur.lineno
self.evaluate_statement(cur)
except Exception as e:
- if not(hasattr(e, 'lineno')):
+ if not hasattr(e, 'lineno'):
e.lineno = cur.lineno
e.colno = cur.colno
e.file = os.path.join(self.subdir, 'meson.build')
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index f3682ce..efb8d11 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -83,6 +83,13 @@ an_unpicklable_object = threading.Lock()
class MesonException(Exception):
'''Exceptions thrown by Meson'''
+ def get_msg_with_context(self):
+ s = ''
+ if hasattr(self, 'lineno') and hasattr(self, 'file'):
+ s = get_error_location_string(self.file, self.lineno) + ' '
+ s += str(self)
+ return s
+
class EnvironmentException(MesonException):
'''Exceptions thrown while processing and creating the build environment'''
@@ -1047,6 +1054,9 @@ def detect_subprojects(spdir_name, current_dir='', result=None):
result[basename] = [trial]
return result
+def get_error_location_string(fname, lineno):
+ return '{}:{}:'.format(fname, lineno)
+
class OrderedSet(collections.MutableSet):
"""A set that preserves the order in which items are added, by first
insertion.
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index b75a267..1654824 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -140,7 +140,8 @@ def log(*args, **kwargs):
force_print(*arr, **kwargs)
def _log_error(severity, *args, **kwargs):
- from . import environment
+ from .mesonlib import get_error_location_string
+ from .environment import build_filename
if severity == 'warning':
args = (yellow('WARNING:'),) + args
elif severity == 'error':
@@ -152,9 +153,8 @@ def _log_error(severity, *args, **kwargs):
location = kwargs.pop('location', None)
if location is not None:
- location_str = '{}:{}:'.format(os.path.join(location.subdir,
- environment.build_filename),
- location.lineno)
+ location_file = os.path.join(location.subdir, build_filename)
+ location_str = get_error_location_string(location_file, location.lineno)
args = (location_str,) + args
log(*args, **kwargs)