aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mcompile.py
diff options
context:
space:
mode:
authorTheQwertiest <qwertiest@mail.ru>2020-05-26 15:00:46 +0300
committerXavier Claessens <xclaesse@gmail.com>2020-05-26 13:45:03 -0400
commit7c2f9e2b57daca67d98dde163100112f47512bfc (patch)
tree38b027cea7d43463d84ebc4e8c8483f46887d705 /mesonbuild/mcompile.py
parentb9c9024e841450766fb68f2afc215229df6a3505 (diff)
downloadmeson-7c2f9e2b57daca67d98dde163100112f47512bfc.zip
meson-7c2f9e2b57daca67d98dde163100112f47512bfc.tar.gz
meson-7c2f9e2b57daca67d98dde163100112f47512bfc.tar.bz2
mcompile: replaced intro with cdata + extracted code to funcs
Diffstat (limited to 'mesonbuild/mcompile.py')
-rw-r--r--mesonbuild/mcompile.py123
1 files changed, 63 insertions, 60 deletions
diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py
index a957c84..cc17871 100644
--- a/mesonbuild/mcompile.py
+++ b/mesonbuild/mcompile.py
@@ -14,7 +14,6 @@
"""Entrypoint script for backend agnostic compile."""
-import json
import os
import shutil
import sys
@@ -23,26 +22,70 @@ from pathlib import Path
from . import mlog
from . import mesonlib
+from . import coredata
from .mesonlib import MesonException
if T.TYPE_CHECKING:
import argparse
-
-def get_backend_from_introspect(builddir: Path) -> str:
+
+def validate_builddir(builddir: Path):
+ if not (builddir / 'meson-private' / 'coredata.dat' ).is_file():
+ raise MesonException('Current directory is not a meson build directory: `{}`.\n'
+ 'Please specify a valid build dir or change the working directory to it.\n'
+ 'It is also possible that the build directory was generated with an old\n'
+ 'meson version. Please regenerate it in this case.'.format(builddir))
+
+def get_backend_from_coredata(builddir: Path) -> str:
"""
- Gets `backend` option value from introspection data
+ Gets `backend` option value from coredata
"""
- path_to_intro = builddir / 'meson-info' / 'intro-buildoptions.json'
- if not path_to_intro.exists():
- raise MesonException('`{}` is missing! Directory is not configured yet?'.format(path_to_intro.name))
- with (path_to_intro).open() as f:
- schema = json.load(f)
-
- for option in schema:
- if option['name'] == 'backend':
- return option['value']
- raise MesonException('`{}` is missing `backend` option!'.format(path_to_intro.name))
-
+ return coredata.load(str(builddir)).get_builtin_option('backend')
+
+def get_parsed_args_ninja(options: 'argparse.Namespace', builddir: Path):
+ runner = os.environ.get('NINJA')
+ if not runner:
+ if shutil.which('ninja'):
+ runner = 'ninja'
+ elif shutil.which('samu'):
+ runner = 'samu'
+
+ if runner is None:
+ raise MesonException('Cannot find either ninja or samu.')
+ mlog.log('Found runner:', runner)
+
+ cmd = [runner, '-C', builddir.as_posix()]
+
+ # If the value is set to < 1 then don't set anything, which let's
+ # ninja/samu decide what to do.
+ if options.jobs > 0:
+ cmd.extend(['-j', str(options.jobs)])
+ if options.load_average > 0:
+ cmd.extend(['-l', str(options.load_average)])
+ if options.clean:
+ cmd.append('clean')
+
+ return cmd
+
+def get_parsed_args_vs(options: 'argparse.Namespace', builddir: Path):
+ slns = list(builddir.glob('*.sln'))
+ assert len(slns) == 1, 'More than one solution in a project?'
+
+ sln = slns[0]
+ cmd = ['msbuild', str(sln.resolve())]
+
+ # In msbuild `-m` with no number means "detect cpus", the default is `-m1`
+ if options.jobs > 0:
+ cmd.append('-m{}'.format(options.jobs))
+ else:
+ cmd.append('-m')
+
+ if options.load_average:
+ mlog.warning('Msbuild does not have a load-average switch, ignoring.')
+ if options.clean:
+ cmd.extend(['/t:Clean'])
+
+ return cmd
+
def add_arguments(parser: 'argparse.ArgumentParser') -> None:
"""Add compile specific arguments."""
parser.add_argument(
@@ -76,57 +119,17 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
def run(options: 'argparse.Namespace') -> int:
bdir = options.builddir # type: Path
- if not bdir.exists():
- raise MesonException('Path to builddir {} does not exist!'.format(str(bdir.resolve())))
- if not bdir.is_dir():
- raise MesonException('builddir path should be a directory.')
+ validate_builddir(bdir.resolve())
cmd = [] # type: T.List[str]
- backend = get_backend_from_introspect(bdir)
+ backend = get_backend_from_coredata(bdir)
if backend == 'ninja':
- runner = os.environ.get('NINJA')
- if not runner:
- if shutil.which('ninja'):
- runner = 'ninja'
- elif shutil.which('samu'):
- runner = 'samu'
-
- if runner is None:
- raise MesonException('Cannot find either ninja or samu.')
- mlog.log('Found runner:', runner)
-
- cmd = [runner, '-C', bdir.as_posix()]
-
- # If the value is set to < 1 then don't set anything, which let's
- # ninja/samu decide what to do.
- if options.jobs > 0:
- cmd.extend(['-j', str(options.jobs)])
- if options.load_average > 0:
- cmd.extend(['-l', str(options.load_average)])
- if options.clean:
- cmd.append('clean')
-
+ cmd = get_parsed_args_ninja(options, bdir)
elif backend.startswith('vs'):
- slns = list(bdir.glob('*.sln'))
- assert len(slns) == 1, 'More than one solution in a project?'
-
- sln = slns[0]
- cmd = ['msbuild', str(sln.resolve())]
-
- # In msbuild `-m` with no number means "detect cpus", the default is `-m1`
- if options.jobs > 0:
- cmd.append('-m{}'.format(options.jobs))
- else:
- cmd.append('-m')
-
- if options.load_average:
- mlog.warning('Msbuild does not have a load-average switch, ignoring.')
- if options.clean:
- cmd.extend(['/t:Clean'])
-
- # TODO: xcode?
+ cmd = get_parsed_args_vs(options, bdir)
else:
+ # TODO: xcode?
raise MesonException(
'Backend `{}` is not yet supported by `compile`. Use generated project files directly instead.'.format(backend))