mcompile: replaced backend divination code + cleanup
This commit is contained in:
parent
1e7f1ad4c9
commit
b9c9024e84
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue