mirror of
https://github.com/mesonbuild/meson.git
synced 2026-11-06 05:16:42 +00:00
build: express that BothLibraries can appear in link_whole and link_with arguments
These are resolved in _extract_link_with and _extract_link_whole. They are still there in BuildTargetKeywordArguments and BaseBuildTarget. This was caught by mypy --warn-unreachable, so it can now be enabled for mesonbuild/build.py. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
1 parent
66c0d66f90
commit
b42fe92b77
5 files changed
+16
-18
No files matched your search
@@ -53,7 +53,6 @@ strict_optional = False
|
||||
|
||||
[mypy-mesonbuild.build]
|
||||
strict_optional = False
|
||||
warn_unreachable = False
|
||||
|
||||
[mypy-mesonbuild.cargo.interpreter]
|
||||
strict_optional = False
|
||||
|
||||
+8
-6
@@ -59,6 +59,8 @@ if T.TYPE_CHECKING:
|
||||
CommandTypes: TypeAlias = T.Union['programs.Program', 'BuildTargetTypes', File, str]
|
||||
GeneratedTypes: TypeAlias = T.Union['CustomTarget', 'CustomTargetIndex', 'GeneratedList']
|
||||
BuildTargetTypes: TypeAlias = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex']
|
||||
LinkableTypes: TypeAlias = T.Union['LinkableTargetProto', 'BothLibraries']
|
||||
StaticTypes: TypeAlias = T.Union['StaticTargetProto', 'BothLibraries']
|
||||
ObjectTypes: TypeAlias = T.Union['File', 'ExtractedObjects']
|
||||
RustCrateType: TypeAlias = Literal['bin', 'lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro']
|
||||
_LibraryType: TypeAlias = Literal['auto', 'shared', 'static']
|
||||
@@ -163,8 +165,8 @@ if T.TYPE_CHECKING:
|
||||
link_early_args: T.List[str]
|
||||
link_depends: T.Sequence[T.Union[File, BuildTargetProto]]
|
||||
link_language: Language
|
||||
link_whole: T.List[StaticTargetProto]
|
||||
link_with: T.List[LinkableTargetProto]
|
||||
link_whole: T.List[StaticTypes]
|
||||
link_with: T.List[LinkableTypes]
|
||||
name_prefix: T.Optional[str]
|
||||
name_suffix: T.Optional[str]
|
||||
native: MachineChoice
|
||||
@@ -1884,7 +1886,7 @@ class BuildTarget(Target, BuildTargetProto):
|
||||
assert isinstance(bl_type, str), 'for mypy'
|
||||
return T.cast('_LibraryType', bl_type)
|
||||
|
||||
def _extract_link_with(self, link_with: list[LinkableTargetProto]) -> list[LinkableTargetProto]:
|
||||
def _extract_link_with(self, link_with: T.Sequence[LinkableTypes]) -> list[LinkableTargetProto]:
|
||||
bl_type = self._default_library_type()
|
||||
|
||||
lib_list: list[LinkableTargetProto] = []
|
||||
@@ -1898,7 +1900,7 @@ class BuildTarget(Target, BuildTargetProto):
|
||||
lib_list.append(lib.get(bl_type))
|
||||
return lib_list
|
||||
|
||||
def _extract_link_whole(self, link_whole: list[StaticTargetProto]) -> list[StaticTargetProto]:
|
||||
def _extract_link_whole(self, link_whole: T.Sequence[StaticTypes]) -> list[StaticTargetProto]:
|
||||
lib_list: list[StaticTargetProto] = []
|
||||
for lib in itertools.chain(link_whole, self.link_whole_targets):
|
||||
if isinstance(lib, BothLibraries):
|
||||
@@ -3416,8 +3418,8 @@ class Jar(BuildTarget):
|
||||
self.main_class = kwargs.get('main_class', '')
|
||||
self.java_resources: T.Optional[StructuredSources] = kwargs.get('java_resources', None)
|
||||
|
||||
def _extract_link_with(self, link_with: list[LinkableTargetProto]) -> list[LinkableTargetProto]:
|
||||
return link_with
|
||||
def _extract_link_with(self, link_with: T.Sequence[LinkableTypes]) -> list[LinkableTargetProto]:
|
||||
return T.cast('list[LinkableTargetProto]', list(link_with))
|
||||
|
||||
def get_main_class(self) -> str:
|
||||
return self.main_class
|
||||
|
||||
@@ -381,8 +381,8 @@ class BaseBuildTarget(TypedDict):
|
||||
implicit_include_directories: bool
|
||||
link_depends: T.List[T.Union[str, File, build.BuildTargetProto]]
|
||||
link_language: T.Optional[Language]
|
||||
link_whole: T.List[build.StaticTargetProto]
|
||||
link_with: T.List[build.LinkableTargetProto]
|
||||
link_whole: T.List[build.StaticTypes]
|
||||
link_with: T.List[build.LinkableTypes]
|
||||
name_prefix: T.Optional[str]
|
||||
name_suffix: T.Optional[str]
|
||||
native: MachineChoice
|
||||
|
||||
@@ -29,7 +29,7 @@ if T.TYPE_CHECKING:
|
||||
from typing_extensions import Literal
|
||||
|
||||
from .kwargs import CustomTargetInputs
|
||||
from ..build import ObjectTypes, GeneratedTypes, CommandTypes, TargetSources
|
||||
from ..build import ObjectTypes, GeneratedTypes, CommandTypes, TargetSources, LinkableTypes, StaticTypes
|
||||
from ..interpreterbase import TYPE_var
|
||||
from ..options import ElementaryOptionValues
|
||||
from ..mesonlib import EnvInitValueType
|
||||
@@ -458,10 +458,7 @@ D_MODULE_VERSIONS_KW: KwargInfo[T.List[T.Union[str, int]]] = KwargInfo(
|
||||
|
||||
_LINK_WITH_ERROR = 'Dependency and external_library objects must go in the "dependencies" keyword argument'
|
||||
|
||||
def _link_with_validator(values: T.List[T.Union[BothLibraries, SharedLibrary, StaticLibrary,
|
||||
CustomTarget, CustomTargetIndex, Jar, Executable,
|
||||
]]
|
||||
) -> T.Optional[str]:
|
||||
def _link_with_validator(values: T.List[LinkableTypes]) -> T.Optional[str]:
|
||||
for value in values:
|
||||
if not value.is_linkable_target():
|
||||
return f'Link target "{value!s}" is not linkable'
|
||||
@@ -477,7 +474,7 @@ LINK_WITH_KW: KwargInfo[T.List[T.Union[BothLibraries, SharedLibrary, StaticLibra
|
||||
validator=_link_with_validator,
|
||||
)
|
||||
|
||||
def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, CustomTargetIndex]]) -> T.Optional[str]:
|
||||
def link_whole_validator(values: T.List[StaticTypes]) -> T.Optional[str]:
|
||||
for l in values:
|
||||
if isinstance(l, (CustomTarget, CustomTargetIndex)) and l.links_dynamically():
|
||||
return f'{type(l).__name__} returning a shared library is not allowed'
|
||||
|
||||
@@ -36,7 +36,7 @@ from ..programs import ExternalProgram, NonExistingExternalProgram
|
||||
if T.TYPE_CHECKING:
|
||||
from . import ModuleState
|
||||
from .. import cargo
|
||||
from ..build import ExecutableKeywordArguments, GeneratedTypes, IncludeDirs, LinkableTargetProto, CommandTypes, StaticTargetProto
|
||||
from ..build import ExecutableKeywordArguments, GeneratedTypes, IncludeDirs, LinkableTypes, CommandTypes, StaticTypes
|
||||
from ..cargo.interpreter import RUST_ABI, PackageConfiguration
|
||||
from ..compilers.compilers import Language
|
||||
from ..compilers.rust import RustCompiler
|
||||
@@ -59,8 +59,8 @@ if T.TYPE_CHECKING:
|
||||
args: T.List[ArgsType]
|
||||
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
|
||||
is_parallel: bool
|
||||
link_with: T.List[LinkableTargetProto]
|
||||
link_whole: T.List[StaticTargetProto]
|
||||
link_with: T.List[LinkableTypes]
|
||||
link_whole: T.List[StaticTypes]
|
||||
rust_args: T.List[str]
|
||||
|
||||
FuncTest = FuncRustTest[CommandTypes]
|
||||
|
||||
Reference in new issue
Block a user