interpreter: move some of CustomTarget's args to type_checking

As there are so many wrappers that need these as well
pull/9333/head
Dylan Baker 3 years ago
parent b923163109
commit 3bb962975e
  1. 44
      mesonbuild/interpreter/interpreter.py
  2. 49
      mesonbuild/interpreter/type_checking.py

@ -51,11 +51,17 @@ from .interpreterobjects import (
) )
from .type_checking import ( from .type_checking import (
COMMAND_KW, COMMAND_KW,
CT_BUILD_BY_DEFAULT,
CT_INPUT_KW,
CT_INSTALL_DIR_KW,
CT_OUTPUT_KW,
DEPENDS_KW, DEPENDS_KW,
DEPEND_FILES_KW, DEPEND_FILES_KW,
DEPFILE_KW, DEPFILE_KW,
ENV_KW, ENV_KW,
INSTALL_KW,
INSTALL_MODE_KW, INSTALL_MODE_KW,
CT_INSTALL_TAG_KW,
LANGUAGE_KW, LANGUAGE_KW,
NATIVE_KW, OVERRIDE_OPTIONS_KW, NATIVE_KW, OVERRIDE_OPTIONS_KW,
REQUIRED_KW, REQUIRED_KW,
@ -90,18 +96,6 @@ if T.TYPE_CHECKING:
build.GeneratedList] build.GeneratedList]
def _output_validator(outputs: T.List[str]) -> T.Optional[str]:
for i in outputs:
if i == '':
return 'Output must not be empty.'
elif i.strip() == '':
return 'Output must not consist only of whitespace.'
elif has_path_sep(i):
return f'Output {i!r} must not contain a path segment.'
return None
def stringifyUserArguments(args, quote=False): def stringifyUserArguments(args, quote=False):
if isinstance(args, list): if isinstance(args, list):
return '[%s]' % ', '.join([stringifyUserArguments(x, True) for x in args]) return '[%s]' % ', '.join([stringifyUserArguments(x, True) for x in args])
@ -1645,35 +1639,23 @@ external dependencies (including libraries) must go to "dependencies".''')
@typed_kwargs( @typed_kwargs(
'custom_target', 'custom_target',
COMMAND_KW, COMMAND_KW,
DEPEND_FILES_KW, CT_BUILD_BY_DEFAULT,
CT_INPUT_KW,
CT_INSTALL_DIR_KW,
CT_INSTALL_TAG_KW,
CT_OUTPUT_KW,
DEPENDS_KW, DEPENDS_KW,
DEPEND_FILES_KW,
DEPFILE_KW, DEPFILE_KW,
ENV_KW.evolve(since='0.57.0'), ENV_KW.evolve(since='0.57.0'),
INSTALL_KW,
INSTALL_MODE_KW.evolve(since='0.47.0'), INSTALL_MODE_KW.evolve(since='0.47.0'),
OVERRIDE_OPTIONS_KW, OVERRIDE_OPTIONS_KW,
KwargInfo('build_by_default', (bool, type(None)), since='0.40.0'),
KwargInfo('build_always', (bool, type(None)), deprecated='0.47.0'), KwargInfo('build_always', (bool, type(None)), deprecated='0.47.0'),
KwargInfo('build_always_stale', (bool, type(None)), since='0.47.0'), KwargInfo('build_always_stale', (bool, type(None)), since='0.47.0'),
KwargInfo('feed', bool, default=False, since='0.59.0'), KwargInfo('feed', bool, default=False, since='0.59.0'),
KwargInfo('capture', bool, default=False), KwargInfo('capture', bool, default=False),
KwargInfo('console', bool, default=False, since='0.48.0'), KwargInfo('console', bool, default=False, since='0.48.0'),
KwargInfo('install', bool, default=False),
KwargInfo('install_dir', ContainerTypeInfo(list, (str, bool)), listify=True, default=[]),
KwargInfo(
'output',
ContainerTypeInfo(list, str, allow_empty=False),
listify=True,
required=True,
default=[],
validator=_output_validator,
),
KwargInfo(
'input',
ContainerTypeInfo(list, (str, mesonlib.File, ExternalProgram, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, build.ExtractedObjects, build.GeneratedList)),
listify=True,
default=[],
),
KwargInfo('install_tag', ContainerTypeInfo(list, (str, bool)), listify=True, default=[], since='0.60.0'),
) )
def func_custom_target(self, node: mparser.FunctionNode, args: T.Tuple[str], def func_custom_target(self, node: mparser.FunctionNode, args: T.Tuple[str],
kwargs: 'kwargs.CustomTarget') -> build.CustomTarget: kwargs: 'kwargs.CustomTarget') -> build.CustomTarget:

@ -6,7 +6,7 @@
import typing as T import typing as T
from .. import compilers from .. import compilers
from ..build import EnvironmentVariables, CustomTarget, BuildTarget, CustomTargetIndex from ..build import EnvironmentVariables, CustomTarget, BuildTarget, CustomTargetIndex, ExtractedObjects, GeneratedList
from ..coredata import UserFeatureOption from ..coredata import UserFeatureOption
from ..interpreterbase import TYPE_var from ..interpreterbase import TYPE_var
from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo
@ -233,3 +233,50 @@ OVERRIDE_OPTIONS_KW: KwargInfo[T.List[str]] = KwargInfo(
validator=_env_validator, validator=_env_validator,
convertor=_override_options_convertor, convertor=_override_options_convertor,
) )
def _output_validator(outputs: T.List[str]) -> T.Optional[str]:
for i in outputs:
if i == '':
return 'Output must not be empty.'
elif i.strip() == '':
return 'Output must not consist only of whitespace.'
elif has_path_sep(i):
return f'Output {i!r} must not contain a path segment.'
return None
CT_OUTPUT_KW: KwargInfo[T.List[str]] = KwargInfo(
'output',
ContainerTypeInfo(list, str, allow_empty=False),
listify=True,
required=True,
default=[],
validator=_output_validator,
)
CT_INPUT_KW: KwargInfo[T.List[T.Union[str, File, ExternalProgram, BuildTarget, CustomTarget, CustomTargetIndex, ExtractedObjects, GeneratedList]]] = KwargInfo(
'input',
ContainerTypeInfo(list, (str, File, ExternalProgram, BuildTarget, CustomTarget, CustomTargetIndex, ExtractedObjects, GeneratedList)),
listify=True,
default=[],
)
CT_INSTALL_TAG_KW: KwargInfo[T.List[T.Union[str, bool]]] = KwargInfo(
'install_tag',
ContainerTypeInfo(list, (str, bool)),
listify=True,
default=[],
since='0.60.0',
)
INSTALL_KW = KwargInfo('install', bool, default=False)
CT_INSTALL_DIR_KW: KwargInfo[T.List[T.Union[str, bool]]] = KwargInfo(
'install_dir',
ContainerTypeInfo(list, (str, bool)),
listify=True,
default=[],
)
CT_BUILD_BY_DEFAULT: KwargInfo[T.Optional[bool]] = KwargInfo('build_by_default', (bool, type(None)), since='0.40.0')

Loading…
Cancel
Save