aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonmain.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-09-13 09:38:19 -0400
committerEli Schwartz <eschwartz93@gmail.com>2022-09-28 19:36:13 -0400
commit2dfd952eb99590878430510644ffe99dd4a6a41d (patch)
tree53001a096d997511a8d12a44cf5019a2ff8d5a2b /mesonbuild/mesonmain.py
parenta58ec322b3a9a07af83ea268341c16f972f52791 (diff)
downloadmeson-2dfd952eb99590878430510644ffe99dd4a6a41d.zip
meson-2dfd952eb99590878430510644ffe99dd4a6a41d.tar.gz
meson-2dfd952eb99590878430510644ffe99dd4a6a41d.tar.bz2
Move classes used by scripts to their own module
Those classes are used by wrapper scripts and we should not have to import the rest of mesonlib, build.py, and all their dependencies for that. This renames mesonlib/ directory to utils/ and add a mesonlib.py module that imports everything from utils/ to not have to change `import mesonlib` everywhere. It allows to import utils.core without importing the rest of mesonlib.
Diffstat (limited to 'mesonbuild/mesonmain.py')
-rw-r--r--mesonbuild/mesonmain.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 2a55c03..7eed11d 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -18,18 +18,18 @@ from . import _pathlib
import sys
sys.modules['pathlib'] = _pathlib
+# This file is an entry point for all commands, including scripts. Include the
+# strict minimum python modules for performance reasons.
import os.path
import platform
import importlib
-import traceback
import argparse
-import shutil
-from . import mesonlib
+from .utils.core import MesonException, MesonBugException
from . import mlog
-from .mesonlib import MesonException, MesonBugException
def errorhandler(e, command):
+ import traceback
if isinstance(e, MesonException):
mlog.exception(e)
logfile = mlog.shutdown()
@@ -72,6 +72,7 @@ class CommandLineParser:
from . import mconf, mdist, minit, minstall, mintro, msetup, mtest, rewriter, msubprojects, munstable_coredata, mcompile, mdevenv
from .scripts import env2mfile
from .wrap import wraptool
+ import shutil
self.term_width = shutil.get_terminal_size().columns
self.formatter = lambda prog: argparse.HelpFormatter(prog, max_help_position=int(self.term_width / 2), width=self.term_width)
@@ -176,6 +177,7 @@ class CommandLineParser:
parser = self.parser
command = None
+ from . import mesonlib
args = mesonlib.expand_arguments(args)
options = parser.parse_args(args)
@@ -228,6 +230,11 @@ def ensure_stdout_accepts_unicode():
if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
sys.stdout.reconfigure(errors='surrogateescape')
+def set_meson_command(mainfile):
+ # Set the meson command that will be used to run scripts and so on
+ from . import mesonlib
+ mesonlib.set_meson_command(mainfile)
+
def run(original_args, mainfile):
if sys.version_info >= (3, 10) and os.environ.get('MESON_RUNNING_IN_PROJECT_TESTS'):
# workaround for https://bugs.python.org/issue34624
@@ -245,15 +252,13 @@ def run(original_args, mainfile):
mlog.error('Please install and use mingw-w64-x86_64-python3 and/or mingw-w64-x86_64-meson with Pacman')
return 2
- # Set the meson command that will be used to run scripts and so on
- mesonlib.set_meson_command(mainfile)
-
args = original_args[:]
# Special handling of internal commands called from backends, they don't
# need to go through argparse.
if len(args) >= 2 and args[0] == '--internal':
if args[1] == 'regenerate':
+ set_meson_command(mainfile)
from . import msetup
try:
return msetup.run(['--reconfigure'] + args[2:])
@@ -262,6 +267,7 @@ def run(original_args, mainfile):
else:
return run_script_command(args[1], args[2:])
+ set_meson_command(mainfile)
return CommandLineParser().run(args)
def main():