Skip to content

Commit

Permalink
interpreter: use typed_kwargs for "sources" keyword argument of build…
Browse files Browse the repository at this point in the history
… targets
  • Loading branch information
dcbaker authored and eli-schwartz committed Oct 4, 2023
1 parent c4458a9 commit 179355b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions mesonbuild/interpreter/interpreter.py
Expand Up @@ -3265,8 +3265,8 @@ def build_target_decorator_caller(self, node, args, kwargs):
# 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.',
Expand Down
4 changes: 3 additions & 1 deletion mesonbuild/interpreter/kwargs.py
Expand Up @@ -16,7 +16,7 @@
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):

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions mesonbuild/interpreter/type_checking.py
Expand Up @@ -467,6 +467,13 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus

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
Expand Down Expand Up @@ -527,6 +534,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
# 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',
Expand Down Expand Up @@ -665,6 +673,12 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
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
Expand Down

0 comments on commit 179355b

Please sign in to comment.