interpreter: use typed_kwargs for "sources" keyword argument of build targets

pull/12333/head
Dylan Baker 1 year ago committed by Eli Schwartz
parent c4458a9a69
commit 179355bf18
  1. 4
      mesonbuild/interpreter/interpreter.py
  2. 4
      mesonbuild/interpreter/kwargs.py
  3. 14
      mesonbuild/interpreter/type_checking.py

@ -3265,8 +3265,8 @@ class Interpreter(InterpreterBase, HoldableObject):
# Silently force to native because that's the only sensible value
# and rust_crate_type is deprecated any way.
for_machine = MachineChoice.BUILD
if 'sources' in kwargs:
sources += listify(kwargs['sources'])
# Avoid mutating, since there could be other references to sources
sources = sources + kwargs['sources']
if any(isinstance(s, build.BuildTarget) for s in sources):
FeatureBroken.single_use('passing references to built targets as a source file', '1.1.0', self.subproject,
'Consider using `link_with` or `link_whole` if you meant to link, or dropping them as otherwise they are ignored.',

@ -16,7 +16,7 @@ from ..dependencies.base import Dependency
from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey
from ..modules.cmake import CMakeSubprojectOptions
from ..programs import ExternalProgram
from .type_checking import PkgConfigDefineType
from .type_checking import PkgConfigDefineType, SourcesVarargsType
class FuncAddProjectArgs(TypedDict):
@ -332,6 +332,7 @@ class _BuildTarget(_BaseBuildTarget):
"""Arguments shared by non-JAR functions"""
rust_dependency_map: T.Dict[str, str]
sources: SourcesVarargsType
class _LibraryMixin(TypedDict):
@ -390,6 +391,7 @@ class Jar(_BaseBuildTarget):
main_class: str
java_resources: T.Optional[build.StructuredSources]
sources: T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList, build.ExtractedObjects, build.BuildTarget]
class FuncDeclareDependency(TypedDict):

@ -467,6 +467,13 @@ DEPENDENCY_SOURCES_KW: KwargInfo[T.List[T.Union[str, File, CustomTarget, CustomT
SOURCES_VARARGS = (str, File, CustomTarget, CustomTargetIndex, GeneratedList, StructuredSources, ExtractedObjects, BuildTarget)
BT_SOURCES_KW: KwargInfo[SourcesVarargsType] = KwargInfo(
'sources',
ContainerTypeInfo(list, SOURCES_VARARGS),
listify=True,
default=[],
)
VARIABLES_KW: KwargInfo[T.Dict[str, str]] = KwargInfo(
'variables',
# str is listified by validator/convertor, cannot use listify=True here because
@ -527,6 +534,7 @@ _ALL_TARGET_KWS: T.List[KwargInfo] = [
# Applies to all build_target classes except jar
_BUILD_TARGET_KWS: T.List[KwargInfo] = [
*_ALL_TARGET_KWS,
BT_SOURCES_KW,
RUST_CRATE_TYPE_KW,
KwargInfo(
'rust_dependency_map',
@ -665,6 +673,12 @@ _EXCLUSIVE_JAR_KWS: T.List[KwargInfo] = [
JAR_KWS = [
*_ALL_TARGET_KWS,
*_EXCLUSIVE_JAR_KWS,
KwargInfo(
'sources',
ContainerTypeInfo(list, (str, File, CustomTarget, CustomTargetIndex, GeneratedList, ExtractedObjects, BuildTarget)),
listify=True,
default=[],
)
]
# Arguments used by both_library and library

Loading…
Cancel
Save