aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/linkers.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-14 14:37:30 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-09-16 20:28:56 -0700
commit3526b36a772b1ae38c7c0be30cf8cdb766e8914f (patch)
tree64349c89c568a9b9004d12b175bef16fedf32d7c /mesonbuild/linkers.py
parent4401668c9ac8c42d2e8633e32d168a2c5e1b0ee8 (diff)
downloadmeson-3526b36a772b1ae38c7c0be30cf8cdb766e8914f.zip
meson-3526b36a772b1ae38c7c0be30cf8cdb766e8914f.tar.gz
meson-3526b36a772b1ae38c7c0be30cf8cdb766e8914f.tar.bz2
linkers: fully type annotate and fix mypy issues
This makes GnuDynamicLinker not suitable for instantiation, so the tests need to be changed to use the BFD class.
Diffstat (limited to 'mesonbuild/linkers.py')
-rw-r--r--mesonbuild/linkers.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py
index fa8b326..02b30e9 100644
--- a/mesonbuild/linkers.py
+++ b/mesonbuild/linkers.py
@@ -22,6 +22,7 @@ from .envconfig import get_env_var
if T.TYPE_CHECKING:
from .coredata import OptionDictType
+ from .envconfig import MachineChoice
from .environment import Environment
@@ -516,6 +517,10 @@ class GnuLikeDynamicLinkerMixin:
other linkers like GNU-ld.
"""
+ if T.TYPE_CHECKING:
+ for_machine = MachineChoice.HOST
+ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]: ...
+
_BUILDTYPE_ARGS = {
'plain': [],
'debug': [],
@@ -761,8 +766,10 @@ class LLVMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, Dyna
id = 'ld.lld'
- def __init__(self, *args, **kwargs) -> None:
- super().__init__(*args, **kwargs)
+ def __init__(self, exelist: T.List[str],
+ for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]],
+ always_args: T.List[str], *, version: str = 'unknown version'):
+ super().__init__(exelist, for_machine, prefix_arg, always_args, version=version)
# Some targets don't seem to support this argument (windows, wasm, ...)
_, _, e = mesonlib.Popen_safe(self.exelist + self._apply_prefix('--allow-shlib-undefined'))
@@ -1052,6 +1059,12 @@ NvidiaHPC_StaticLinker = PGIStaticLinker
class VisualStudioLikeLinkerMixin:
+ """Mixin class for for dynamic linkers that act like Microsoft's link.exe."""
+
+ if T.TYPE_CHECKING:
+ for_machine = MachineChoice.HOST
+ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]: ...
+
_BUILDTYPE_ARGS = {
'plain': [],
'debug': [],
@@ -1063,9 +1076,13 @@ class VisualStudioLikeLinkerMixin:
'custom': [],
} # type: T.Dict[str, T.List[str]]
- def __init__(self, *args, direct: bool = True, machine: str = 'x86', **kwargs):
- super().__init__(*args, **kwargs)
+ def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice,
+ prefix_arg: T.Union[str, T.List[str]], always_args: T.List[str], *,
+ version: str = 'unknown version', direct: bool = True, machine: str = 'x86'):
+ # There's no way I can find to make mypy understand what's going on here
+ super().__init__(exelist, for_machine, prefix_arg, always_args, version=version) # type: ignore
self.machine = machine
+ self.direct = direct
def get_buildtype_args(self, buildtype: str) -> T.List[str]:
return mesonlib.listify([self._apply_prefix(a) for a in self._BUILDTYPE_ARGS[buildtype]])
@@ -1077,7 +1094,8 @@ class VisualStudioLikeLinkerMixin:
return self._apply_prefix(['/MACHINE:' + self.machine, '/OUT:' + outputname])
def get_always_args(self) -> T.List[str]:
- return self._apply_prefix('/nologo') + super().get_always_args()
+ parent = super().get_always_args() # type: ignore
+ return self._apply_prefix('/nologo') + T.cast(T.List[str], parent)
def get_search_args(self, dirname: str) -> T.List[str]:
return self._apply_prefix('/LIBPATH:' + dirname)
@@ -1278,7 +1296,7 @@ class CudaLinker(PosixDynamicLinkerMixin, DynamicLinker):
id = 'nvlink'
@staticmethod
- def parse_version():
+ def parse_version() -> str:
version_cmd = ['nvlink', '--version']
try:
_, out, _ = mesonlib.Popen_safe(version_cmd)