mcompile: replaced backend divination code + cleanup

pull/7207/head
TheQwertiest 5 years ago committed by Xavier Claessens
parent 1e7f1ad4c9
commit b9c9024e84
  1. 35
      mesonbuild/mcompile.py

@ -14,11 +14,12 @@
"""Entrypoint script for backend agnostic compile.""" """Entrypoint script for backend agnostic compile."""
import json
import os import os
import pathlib
import shutil import shutil
import sys import sys
import typing as T import typing as T
from pathlib import Path
from . import mlog from . import mlog
from . import mesonlib from . import mesonlib
@ -27,6 +28,20 @@ from .mesonlib import MesonException
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
import argparse 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: def add_arguments(parser: 'argparse.ArgumentParser') -> None:
"""Add compile specific arguments.""" """Add compile specific arguments."""
@ -53,24 +68,23 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
'-C', '-C',
action='store', action='store',
dest='builddir', dest='builddir',
type=pathlib.Path, type=Path,
default='.', default='.',
help='The directory containing build files to be built.' help='The directory containing build files to be built.'
) )
def run(options: 'argparse.Namespace') -> int: def run(options: 'argparse.Namespace') -> int:
bdir = options.builddir # type: pathlib.Path bdir = options.builddir # type: Path
if not bdir.exists(): if not bdir.exists():
raise MesonException('Path to builddir {} does not exist!'.format(str(bdir.resolve()))) raise MesonException('Path to builddir {} does not exist!'.format(str(bdir.resolve())))
if not bdir.is_dir(): if not bdir.is_dir():
raise MesonException('builddir path should be a directory.') raise MesonException('builddir path should be a directory.')
cmd = [] # type: T.List[str] 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') runner = os.environ.get('NINJA')
if not runner: if not runner:
if shutil.which('ninja'): if shutil.which('ninja'):
@ -80,6 +94,7 @@ def run(options: 'argparse.Namespace') -> int:
if runner is None: if runner is None:
raise MesonException('Cannot find either ninja or samu.') raise MesonException('Cannot find either ninja or samu.')
mlog.log('Found runner:', runner)
cmd = [runner, '-C', bdir.as_posix()] cmd = [runner, '-C', bdir.as_posix()]
@ -92,8 +107,8 @@ def run(options: 'argparse.Namespace') -> int:
if options.clean: if options.clean:
cmd.append('clean') cmd.append('clean')
# TODO: with python 3.8 this could be `elif slns := bdir.glob('*.sln'):` elif backend.startswith('vs'):
elif slns: slns = list(bdir.glob('*.sln'))
assert len(slns) == 1, 'More than one solution in a project?' assert len(slns) == 1, 'More than one solution in a project?'
sln = slns[0] sln = slns[0]
@ -113,9 +128,7 @@ def run(options: 'argparse.Namespace') -> int:
# TODO: xcode? # TODO: xcode?
else: else:
raise MesonException( raise MesonException(
'Could not find any runner or backend for directory {}'.format(bdir.resolve().as_posix())) 'Backend `{}` is not yet supported by `compile`. Use generated project files directly instead.'.format(backend))
mlog.log('Found runner:', runner)
p, *_ = mesonlib.Popen_safe(cmd, stdout=sys.stdout.buffer, stderr=sys.stderr.buffer) p, *_ = mesonlib.Popen_safe(cmd, stdout=sys.stdout.buffer, stderr=sys.stderr.buffer)

Loading…
Cancel
Save