Simplify run_script_command()

pull/4204/head
Xavier Claessens 7 years ago
parent f8913d1d28
commit 5af2717e76
  1. 88
      mesonbuild/mesonmain.py

@ -14,69 +14,35 @@
import sys import sys
import os.path import os.path
import importlib
from . import mesonlib from . import mesonlib
from . import mlog from . import mlog
from .mesonlib import MesonException from .mesonlib import MesonException
from .environment import detect_msys2_arch from .environment import detect_msys2_arch
def run_script_command(args): def run_script_command(script_name, script_args):
cmdname = args[0] # Map script name to module name for those that doesn't match
cmdargs = args[1:] script_map = {'exe': 'meson_exe',
if cmdname == 'exe': 'install': 'meson_install',
import mesonbuild.scripts.meson_exe as abc 'delsuffix': 'delwithsuffix',
cmdfunc = abc.run 'gtkdoc': 'gtkdochelper',
elif cmdname == 'cleantrees': 'hotdoc': 'hotdochelper',
import mesonbuild.scripts.cleantrees as abc 'regencheck': 'regen_checker'}
cmdfunc = abc.run module_name = script_map.get(script_name, script_name)
elif cmdname == 'commandrunner':
import mesonbuild.scripts.commandrunner as abc try:
cmdfunc = abc.run module = importlib.import_module('mesonbuild.scripts.' + module_name)
elif cmdname == 'delsuffix': except ModuleNotFoundError as e:
import mesonbuild.scripts.delwithsuffix as abc mlog.exception(e)
cmdfunc = abc.run return 1
elif cmdname == 'dirchanger':
import mesonbuild.scripts.dirchanger as abc try:
cmdfunc = abc.run return module.run(script_args)
elif cmdname == 'gtkdoc': except MesonException as e:
import mesonbuild.scripts.gtkdochelper as abc mlog.error('Error in {} helper script:'.format(script_name))
cmdfunc = abc.run mlog.exception(e)
elif cmdname == 'msgfmthelper': return 1
import mesonbuild.scripts.msgfmthelper as abc
cmdfunc = abc.run
elif cmdname == 'hotdoc':
import mesonbuild.scripts.hotdochelper as abc
cmdfunc = abc.run
elif cmdname == 'regencheck':
import mesonbuild.scripts.regen_checker as abc
cmdfunc = abc.run
elif cmdname == 'symbolextractor':
import mesonbuild.scripts.symbolextractor as abc
cmdfunc = abc.run
elif cmdname == 'scanbuild':
import mesonbuild.scripts.scanbuild as abc
cmdfunc = abc.run
elif cmdname == 'vcstagger':
import mesonbuild.scripts.vcstagger as abc
cmdfunc = abc.run
elif cmdname == 'gettext':
import mesonbuild.scripts.gettext as abc
cmdfunc = abc.run
elif cmdname == 'yelphelper':
import mesonbuild.scripts.yelphelper as abc
cmdfunc = abc.run
elif cmdname == 'uninstall':
import mesonbuild.scripts.uninstall as abc
cmdfunc = abc.run
elif cmdname == 'dist':
import mesonbuild.scripts.dist as abc
cmdfunc = abc.run
elif cmdname == 'coverage':
import mesonbuild.scripts.coverage as abc
cmdfunc = abc.run
else:
raise MesonException('Unknown internal command {}.'.format(cmdname))
return cmdfunc(cmdargs)
def run(original_args, mainfile): def run(original_args, mainfile):
if sys.version_info < (3, 5): if sys.version_info < (3, 5):
@ -107,13 +73,7 @@ def run(original_args, mainfile):
# "meson --reconfigure" # "meson --reconfigure"
args = ['--reconfigure'] + args[2:] args = ['--reconfigure'] + args[2:]
else: else:
script = args[1] return run_script_command(args[1], args[2:])
try:
sys.exit(run_script_command(args[1:]))
except MesonException as e:
mlog.error('\nError in {} helper script:'.format(script))
mlog.exception(e)
sys.exit(1)
if len(args) > 0: if len(args) > 0:
# First check if we want to run a subcommand. # First check if we want to run a subcommand.

Loading…
Cancel
Save