aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mcompile.py
diff options
context:
space:
mode:
authorTheQwertiest <qwertiest@mail.ru>2020-05-23 16:06:33 +0300
committerXavier Claessens <xclaesse@gmail.com>2020-05-26 13:45:03 -0400
commitb9c9024e841450766fb68f2afc215229df6a3505 (patch)
treeee1b4b3e909cbb095c15dbabce4ba5473f38afc0 /mesonbuild/mcompile.py
parent1e7f1ad4c96945b5a849896bd368ceb40d0bfd1a (diff)
downloadmeson-b9c9024e841450766fb68f2afc215229df6a3505.zip
meson-b9c9024e841450766fb68f2afc215229df6a3505.tar.gz
meson-b9c9024e841450766fb68f2afc215229df6a3505.tar.bz2
mcompile: replaced backend divination code + cleanup
Diffstat (limited to 'mesonbuild/mcompile.py')
-rw-r--r--mesonbuild/mcompile.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py
index 7829ffc..a957c84 100644
--- a/mesonbuild/mcompile.py
+++ b/mesonbuild/mcompile.py
@@ -14,11 +14,12 @@
"""Entrypoint script for backend agnostic compile."""
+import json
import os
-import pathlib
import shutil
import sys
import typing as T
+from pathlib import Path
from . import mlog
from . import mesonlib
@@ -27,6 +28,20 @@ from .mesonlib import MesonException
if T.TYPE_CHECKING:
import argparse
+def get_backend_from_introspect(builddir: Path) -> str:
+ """
+ Gets `backend` option value from introspection data
+ """
+ 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))
def add_arguments(parser: 'argparse.ArgumentParser') -> None:
"""Add compile specific arguments."""
@@ -53,24 +68,23 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
'-C',
action='store',
dest='builddir',
- type=pathlib.Path,
+ type=Path,
default='.',
help='The directory containing build files to be built.'
)
def run(options: 'argparse.Namespace') -> int:
- bdir = options.builddir # type: pathlib.Path
+ 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.')
cmd = [] # type: T.List[str]
- runner = None # type T.Optional[str]
- slns = list(bdir.glob('*.sln'))
- if (bdir / 'build.ninja').exists():
+ backend = get_backend_from_introspect(bdir)
+ if backend == 'ninja':
runner = os.environ.get('NINJA')
if not runner:
if shutil.which('ninja'):
@@ -80,6 +94,7 @@ def run(options: 'argparse.Namespace') -> int:
if runner is None:
raise MesonException('Cannot find either ninja or samu.')
+ mlog.log('Found runner:', runner)
cmd = [runner, '-C', bdir.as_posix()]
@@ -92,8 +107,8 @@ def run(options: 'argparse.Namespace') -> int:
if options.clean:
cmd.append('clean')
- # TODO: with python 3.8 this could be `elif slns := bdir.glob('*.sln'):`
- elif slns:
+ elif backend.startswith('vs'):
+ slns = list(bdir.glob('*.sln'))
assert len(slns) == 1, 'More than one solution in a project?'
sln = slns[0]
@@ -113,9 +128,7 @@ def run(options: 'argparse.Namespace') -> int:
# TODO: xcode?
else:
raise MesonException(
- 'Could not find any runner or backend for directory {}'.format(bdir.resolve().as_posix()))
-
- mlog.log('Found runner:', runner)
+ 'Backend `{}` is not yet supported by `compile`. Use generated project files directly instead.'.format(backend))
p, *_ = mesonlib.Popen_safe(cmd, stdout=sys.stdout.buffer, stderr=sys.stderr.buffer)