aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-09-22 14:38:09 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-09-22 15:23:39 -0400
commitd364985365e2cf49a877bda104a5e20b15e42a53 (patch)
tree224b5f5c30d06a3bafed644840b3c1aa99174145 /mesonbuild
parent3fd2459a748cc9eed4be73132b002400da81cb0a (diff)
downloadmeson-d364985365e2cf49a877bda104a5e20b15e42a53.zip
meson-d364985365e2cf49a877bda104a5e20b15e42a53.tar.gz
meson-d364985365e2cf49a877bda104a5e20b15e42a53.tar.bz2
fix regression in handling errors during reconfigure
In commit 9ed5cfda155c585f7aea896fe2f40d3a92eac43a we refactored startup to be a bit faster and import less. But this had the side effect of moving out of our errorhandler. Refactor this so it can be easily used elsewhere.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/mesonmain.py83
1 files changed, 45 insertions, 38 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index d024deb..03ff687 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -29,6 +29,46 @@ from . import mesonlib
from . import mlog
from .mesonlib import MesonException, MesonBugException
+def errorhandler(e, command):
+ if isinstance(e, MesonException):
+ mlog.exception(e)
+ logfile = mlog.shutdown()
+ if logfile is not None:
+ mlog.log("\nA full log can be found at", mlog.bold(logfile))
+ if os.environ.get('MESON_FORCE_BACKTRACE'):
+ raise e
+ return 1
+ elif isinstance(e, OSError):
+ if os.environ.get('MESON_FORCE_BACKTRACE'):
+ raise e
+ traceback.print_exc()
+ error_msg = os.linesep.join([
+ "Unhandled python exception",
+ f"{e.strerror} - {e.args}",
+ "this is probably not a Meson bug."])
+
+ mlog.exception(error_msg)
+ return e.errno
+
+ else: # Exception
+ if os.environ.get('MESON_FORCE_BACKTRACE'):
+ raise e
+ traceback.print_exc()
+ # We assume many types of traceback are Meson logic bugs, but most
+ # particularly anything coming from the interpreter during `setup`.
+ # Some things definitely aren't:
+ # - PermissionError is always a problem in the user environment
+ # - runpython doesn't run Meson's own code, even though it is
+ # dispatched by our run()
+ if command != 'runpython':
+ msg = 'Unhandled python exception'
+ if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']):
+ e = MesonBugException(msg, e.file, e.lineno, e.colno) # type: ignore
+ else:
+ e = MesonBugException(msg)
+ mlog.exception(e)
+ return 2
+
# Note: when adding arguments, please also add them to the completion
# scripts in $MESONSRC/data/shell-completions/
class CommandLineParser:
@@ -155,44 +195,8 @@ class CommandLineParser:
try:
return options.run_func(options)
- except MesonException as e:
- mlog.exception(e)
- logfile = mlog.shutdown()
- if logfile is not None:
- mlog.log("\nA full log can be found at", mlog.bold(logfile))
- if os.environ.get('MESON_FORCE_BACKTRACE'):
- raise
- return 1
- except OSError as e:
- if os.environ.get('MESON_FORCE_BACKTRACE'):
- raise
- traceback.print_exc()
- error_msg = os.linesep.join([
- "Unhandled python exception",
- f"{e.strerror} - {e.args}",
- "this is probably not a Meson bug."])
-
- mlog.exception(error_msg)
- return e.errno
-
except Exception as e:
- if os.environ.get('MESON_FORCE_BACKTRACE'):
- raise
- traceback.print_exc()
- # We assume many types of traceback are Meson logic bugs, but most
- # particularly anything coming from the interpreter during `setup`.
- # Some things definitely aren't:
- # - PermissionError is always a problem in the user environment
- # - runpython doesn't run Meson's own code, even though it is
- # dispatched by our run()
- if command != 'runpython':
- msg = 'Unhandled python exception'
- if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']):
- e = MesonBugException(msg, e.file, e.lineno, e.colno) # type: ignore
- else:
- e = MesonBugException(msg)
- mlog.exception(e)
- return 2
+ return errorhandler(e, command)
finally:
if implicit_setup_command_notice:
mlog.warning('Running the setup command as `meson [options]` instead of '
@@ -256,7 +260,10 @@ def run(original_args, mainfile):
if len(args) >= 2 and args[0] == '--internal':
if args[1] == 'regenerate':
from . import msetup
- return msetup.run(['--reconfigure'] + args[2:])
+ try:
+ return msetup.run(['--reconfigure'] + args[2:])
+ except Exception as e:
+ return errorhandler(e, 'setup')
else:
return run_script_command(args[1], args[2:])