diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-29 13:48:22 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-26 13:10:33 -0400 |
commit | b8b2d87567af8e7f556e290c3585e7ac462679b6 (patch) | |
tree | 8ee2b80546ceecccc5446ed8d89694778ae91c37 | |
parent | b1ddfabf8fbb0561a584bd7cfe2bb712b4105da2 (diff) | |
download | meson-b8b2d87567af8e7f556e290c3585e7ac462679b6.zip meson-b8b2d87567af8e7f556e290c3585e7ac462679b6.tar.gz meson-b8b2d87567af8e7f556e290c3585e7ac462679b6.tar.bz2 |
dependencies: switch the delayed-import mechanism for custom dependencies
Simply store the module it is expected to be found in. That module then
appends to the packages dict, which guarantees mypy can verify that
it's got the right type -- there is no casting needed.
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 86 | ||||
-rw-r--r-- | mesonbuild/dependencies/boost.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/coarrays.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/cuda.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/detect.py | 8 | ||||
-rw-r--r-- | mesonbuild/dependencies/dev.py | 15 | ||||
-rw-r--r-- | mesonbuild/dependencies/hdf5.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 33 | ||||
-rw-r--r-- | mesonbuild/dependencies/mpi.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/platform.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/python.py | 5 | ||||
-rw-r--r-- | mesonbuild/dependencies/qt.py | 7 | ||||
-rw-r--r-- | mesonbuild/dependencies/scalapack.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/ui.py | 10 |
14 files changed, 114 insertions, 69 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 7fa1b46..c6dabc5 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -192,62 +192,66 @@ this approach, and no new dependencies should do this. # - An ExternalDependency subclass # - A DependencyFactory object # - A callable with a signature of (Environment, MachineChoice, Dict[str, Any]) -> List[Callable[[], ExternalDependency]] +# +# The internal "defaults" attribute contains a separate dictionary mapping +# for lazy imports. The values must be: +# - a string naming the submodule that should be imported from `mesonbuild.dependencies` to populate the dependency packages.defaults.update({ # From dev: - 'gtest': 'dev:gtest_factory', - 'gmock': 'dev:gmock_factory', - 'llvm': 'dev:llvm_factory', - 'valgrind': 'dev:ValgrindDependency', - 'zlib': 'dev:zlib_factory', - 'jni': 'dev:JNISystemDependency', - 'jdk': 'dev:JDKSystemDependency', + 'gtest': 'dev', + 'gmock': 'dev', + 'llvm': 'dev', + 'valgrind': 'dev', + 'zlib': 'dev', + 'jni': 'dev', + 'jdk': 'dev', - 'boost': 'boost:BoostDependency', - 'cuda': 'cuda:CudaDependency', + 'boost': 'boost', + 'cuda': 'cuda', # per-file - 'coarray': 'coarrays:coarray_factory', - 'hdf5': 'hdf5:hdf5_factory', - 'mpi': 'mpi:mpi_factory', - 'scalapack': 'scalapack:scalapack_factory', + 'coarray': 'coarrays', + 'hdf5': 'hdf5', + 'mpi': 'mpi', + 'scalapack': 'scalapack', # From misc: - 'blocks': 'misc:BlocksDependency', - 'curses': 'misc:curses_factory', - 'netcdf': 'misc:netcdf_factory', - 'openmp': 'misc:OpenMPDependency', - 'threads': 'misc:threads_factory', - 'pcap': 'misc:pcap_factory', - 'cups': 'misc:cups_factory', - 'libwmf': 'misc:libwmf_factory', - 'libgcrypt': 'misc:libgcrypt_factory', - 'gpgme': 'misc:gpgme_factory', - 'shaderc': 'misc:shaderc_factory', - 'iconv': 'misc:iconv_factory', - 'intl': 'misc:intl_factory', - 'dl': 'misc:dl_factory', - 'openssl': 'misc:openssl_factory', - 'libcrypto': 'misc:libcrypto_factory', - 'libssl': 'misc:libssl_factory', + 'blocks': 'misc', + 'curses': 'misc', + 'netcdf': 'misc', + 'openmp': 'misc', + 'threads': 'misc', + 'pcap': 'misc', + 'cups': 'misc', + 'libwmf': 'misc', + 'libgcrypt': 'misc', + 'gpgme': 'misc', + 'shaderc': 'misc', + 'iconv': 'misc', + 'intl': 'misc', + 'dl': 'misc', + 'openssl': 'misc', + 'libcrypto': 'misc', + 'libssl': 'misc', # From platform: - 'appleframeworks': 'platform:AppleFrameworks', + 'appleframeworks': 'platform', # from python: - 'python3': 'python:python_factory', - 'pybind11': 'python:pybind11_factory', + 'python3': 'python', + 'pybind11': 'python', # From ui: - 'gl': 'ui:gl_factory', - 'gnustep': 'ui:GnuStepDependency', - 'sdl2': 'ui:sdl2_factory', - 'wxwidgets': 'ui:WxDependency', - 'vulkan': 'ui:vulkan_factory', + 'gl': 'ui', + 'gnustep': 'ui', + 'sdl2': 'ui', + 'wxwidgets': 'ui', + 'vulkan': 'ui', # from qt - 'qt4': 'qt:qt4_factory', - 'qt5': 'qt:qt5_factory', - 'qt6': 'qt:qt6_factory', + 'qt4': 'qt', + 'qt5': 'qt', + 'qt6': 'qt', }) _packages_accept_language.update({ 'hdf5', diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 44f1baf..0e4dab9 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -23,6 +23,7 @@ from .. import mlog from .. import mesonlib from .base import DependencyException, SystemDependency +from .detect import packages from .pkgconfig import PkgConfigDependency from .misc import threads_factory @@ -738,6 +739,7 @@ class BoostDependency(SystemDependency): # BOOST_ALL_DYN_LINK should not be required with the known defines below return ['-DBOOST_ALL_NO_LIB'] # Disable automatic linking +packages['boost'] = BoostDependency # See https://www.boost.org/doc/libs/1_72_0/more/getting_started/unix-variants.html#library-naming # See https://mesonbuild.com/Reference-tables.html#cpu-families diff --git a/mesonbuild/dependencies/coarrays.py b/mesonbuild/dependencies/coarrays.py index 70cf4f8..5cb8556 100644 --- a/mesonbuild/dependencies/coarrays.py +++ b/mesonbuild/dependencies/coarrays.py @@ -18,6 +18,7 @@ import typing as T from .base import DependencyMethods, detect_compiler, SystemDependency from .cmake import CMakeDependency +from .detect import packages from .pkgconfig import PkgConfigDependency from .factory import factory_methods @@ -51,6 +52,7 @@ def coarray_factory(env: 'Environment', candidates.append(functools.partial(CoarrayDependency, env, kwargs)) return candidates +packages['coarray'] = coarray_factory class CoarrayDependency(SystemDependency): diff --git a/mesonbuild/dependencies/cuda.py b/mesonbuild/dependencies/cuda.py index 89e562f..af0ae4b 100644 --- a/mesonbuild/dependencies/cuda.py +++ b/mesonbuild/dependencies/cuda.py @@ -23,6 +23,7 @@ from .. import mesonlib from .. import mlog from ..environment import detect_cpu_family from .base import DependencyException, SystemDependency +from .detect import packages if T.TYPE_CHECKING: @@ -290,3 +291,5 @@ class CudaDependency(SystemDependency): for lib in self.requested_modules: args += self.lib_modules[lib] return args + +packages['cuda'] = CudaDependency diff --git a/mesonbuild/dependencies/detect.py b/mesonbuild/dependencies/detect.py index a10131d..9428d54 100644 --- a/mesonbuild/dependencies/detect.py +++ b/mesonbuild/dependencies/detect.py @@ -35,12 +35,10 @@ class DependencyPackages(collections.UserDict): def __missing__(self, key: str) -> PackageTypes: if key in self.defaults: - modn, package = self.defaults[key].split(':', maxsplit=1) - mod = importlib.import_module(f'mesonbuild.dependencies.{modn}') - value = T.cast('PackageTypes', getattr(mod, package)) - self.data[key] = value + modn = self.defaults[key] + importlib.import_module(f'mesonbuild.dependencies.{modn}') - return value + return self.data[key] raise KeyError(key) def __contains__(self, key: object) -> bool: diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 9c03496..ec70151 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -34,6 +34,7 @@ from ..mesonlib import version_compare, version_compare_many, search_version, st from .base import DependencyException, DependencyMethods, detect_compiler, strip_system_includedirs, strip_system_libdirs, SystemDependency, ExternalDependency, DependencyTypeName from .cmake import CMakeDependency from .configtool import ConfigToolDependency +from .detect import packages from .factory import DependencyFactory from .misc import threads_factory from .pkgconfig import PkgConfigDependency @@ -507,6 +508,8 @@ class ValgrindDependency(PkgConfigDependency): def get_link_args(self, language: T.Optional[str] = None, raw: bool = False) -> T.List[str]: return [] +packages['valgrind'] = ValgrindDependency + class ZlibSystemDependency(SystemDependency): @@ -671,6 +674,8 @@ class JNISystemDependency(SystemDependency): return None +packages['jni'] = JNISystemDependency + class JDKSystemDependency(JNISystemDependency): def __init__(self, environment: 'Environment', kwargs: JNISystemDependencyKW): @@ -683,29 +688,31 @@ class JDKSystemDependency(JNISystemDependency): 'Use the jni system dependency instead' )) +packages['jdk'] = JDKSystemDependency + -llvm_factory = DependencyFactory( +packages['llvm'] = llvm_factory = DependencyFactory( 'LLVM', [DependencyMethods.CMAKE, DependencyMethods.CONFIG_TOOL], cmake_class=LLVMDependencyCMake, configtool_class=LLVMDependencyConfigTool, ) -gtest_factory = DependencyFactory( +packages['gtest'] = gtest_factory = DependencyFactory( 'gtest', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM], pkgconfig_class=GTestDependencyPC, system_class=GTestDependencySystem, ) -gmock_factory = DependencyFactory( +packages['gmock'] = gmock_factory = DependencyFactory( 'gmock', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM], pkgconfig_class=GMockDependencyPC, system_class=GMockDependencySystem, ) -zlib_factory = DependencyFactory( +packages['zlib'] = zlib_factory = DependencyFactory( 'zlib', [DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE, DependencyMethods.SYSTEM], cmake_name='ZLIB', diff --git a/mesonbuild/dependencies/hdf5.py b/mesonbuild/dependencies/hdf5.py index 4e5820a..392bb09 100644 --- a/mesonbuild/dependencies/hdf5.py +++ b/mesonbuild/dependencies/hdf5.py @@ -25,6 +25,7 @@ from ..mesonlib import Popen_safe, OrderedSet, join_args from ..programs import ExternalProgram from .base import DependencyException, DependencyMethods from .configtool import ConfigToolDependency +from .detect import packages from .pkgconfig import PkgConfigDependency from .factory import factory_methods import typing as T @@ -178,3 +179,5 @@ def hdf5_factory(env: 'Environment', for_machine: 'MachineChoice', candidates.append(functools.partial(HDF5ConfigToolDependency, 'hdf5', env, kwargs, language)) return candidates + +packages['hdf5'] = hdf5_factory diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 0c747c4..d775669 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -25,6 +25,7 @@ from .base import DependencyException, DependencyMethods from .base import BuiltinDependency, SystemDependency from .cmake import CMakeDependency from .configtool import ConfigToolDependency +from .detect import packages from .factory import DependencyFactory, factory_methods from .pkgconfig import PkgConfigDependency @@ -57,6 +58,8 @@ def netcdf_factory(env: 'Environment', return candidates +packages['netcdf'] = netcdf_factory + class DlBuiltinDependency(BuiltinDependency): def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): @@ -136,6 +139,8 @@ class OpenMPDependency(SystemDependency): if not self.is_found: mlog.log(mlog.yellow('WARNING:'), 'OpenMP found but omp.h missing.') +packages['openmp'] = OpenMPDependency + class ThreadDependency(SystemDependency): def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None: @@ -183,6 +188,8 @@ class BlocksDependency(SystemDependency): self.is_found = True +packages['blocks'] = BlocksDependency + class PcapDependencyConfigTool(ConfigToolDependency): @@ -489,6 +496,7 @@ def curses_factory(env: 'Environment', candidates.append(functools.partial(CursesSystemDependency, 'curses', env, kwargs)) return candidates +packages['curses'] = curses_factory @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM}) @@ -524,83 +532,84 @@ def shaderc_factory(env: 'Environment', candidates.append(functools.partial(ShadercDependency, env, kwargs)) return candidates +packages['shaderc'] = shaderc_factory -cups_factory = DependencyFactory( +packages['cups'] = cups_factory = DependencyFactory( 'cups', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE], configtool_class=CupsDependencyConfigTool, cmake_name='Cups', ) -dl_factory = DependencyFactory( +packages['dl'] = dl_factory = DependencyFactory( 'dl', [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], builtin_class=DlBuiltinDependency, system_class=DlSystemDependency, ) -gpgme_factory = DependencyFactory( +packages['gpgme'] = gpgme_factory = DependencyFactory( 'gpgme', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], configtool_class=GpgmeDependencyConfigTool, ) -libgcrypt_factory = DependencyFactory( +packages['libgcrypt'] = libgcrypt_factory = DependencyFactory( 'libgcrypt', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], configtool_class=LibGCryptDependencyConfigTool, ) -libwmf_factory = DependencyFactory( +packages['libwmf'] = libwmf_factory = DependencyFactory( 'libwmf', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], configtool_class=LibWmfDependencyConfigTool, ) -pcap_factory = DependencyFactory( +packages['pcap'] = pcap_factory = DependencyFactory( 'pcap', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], configtool_class=PcapDependencyConfigTool, pkgconfig_name='libpcap', ) -threads_factory = DependencyFactory( +packages['threads'] = threads_factory = DependencyFactory( 'threads', [DependencyMethods.SYSTEM, DependencyMethods.CMAKE], cmake_name='Threads', system_class=ThreadDependency, ) -iconv_factory = DependencyFactory( +packages['iconv'] = iconv_factory = DependencyFactory( 'iconv', [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], builtin_class=IconvBuiltinDependency, system_class=IconvSystemDependency, ) -intl_factory = DependencyFactory( +packages['intl'] = intl_factory = DependencyFactory( 'intl', [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], builtin_class=IntlBuiltinDependency, system_class=IntlSystemDependency, ) -openssl_factory = DependencyFactory( +packages['openssl'] = openssl_factory = DependencyFactory( 'openssl', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM, DependencyMethods.CMAKE], system_class=OpensslSystemDependency, cmake_class=lambda name, env, kwargs: CMakeDependency('OpenSSL', env, dict(kwargs, modules=['OpenSSL::Crypto', 'OpenSSL::SSL'])), ) -libcrypto_factory = DependencyFactory( +packages['libcrypto'] = libcrypto_factory = DependencyFactory( 'libcrypto', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM, DependencyMethods.CMAKE], system_class=OpensslSystemDependency, cmake_class=lambda name, env, kwargs: CMakeDependency('OpenSSL', env, dict(kwargs, modules=['OpenSSL::Crypto'])), ) -libssl_factory = DependencyFactory( +packages['libssl'] = libssl_factory = DependencyFactory( 'libssl', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM, DependencyMethods.CMAKE], system_class=OpensslSystemDependency, diff --git a/mesonbuild/dependencies/mpi.py b/mesonbuild/dependencies/mpi.py index 8f83ce4..9100681 100644 --- a/mesonbuild/dependencies/mpi.py +++ b/mesonbuild/dependencies/mpi.py @@ -21,6 +21,7 @@ import re from ..environment import detect_cpu_family from .base import DependencyMethods, detect_compiler, SystemDependency from .configtool import ConfigToolDependency +from .detect import packages from .factory import factory_methods from .pkgconfig import PkgConfigDependency @@ -100,6 +101,8 @@ def mpi_factory(env: 'Environment', return candidates +packages['mpi'] = mpi_factory + class _MPIConfigToolDependency(ConfigToolDependency): diff --git a/mesonbuild/dependencies/platform.py b/mesonbuild/dependencies/platform.py index 6d32555..87726b5 100644 --- a/mesonbuild/dependencies/platform.py +++ b/mesonbuild/dependencies/platform.py @@ -17,6 +17,7 @@ from __future__ import annotations from .base import DependencyTypeName, ExternalDependency, DependencyException +from .detect import packages from ..mesonlib import MesonException import typing as T @@ -58,3 +59,5 @@ class AppleFrameworks(ExternalDependency): @staticmethod def log_tried() -> str: return 'framework' + +packages['appleframeworks'] = AppleFrameworks diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py index 2410007..1607728 100644 --- a/mesonbuild/dependencies/python.py +++ b/mesonbuild/dependencies/python.py @@ -20,6 +20,7 @@ import typing as T from .. import mesonlib, mlog from .base import process_method_kw, DependencyMethods, DependencyTypeName, ExternalDependency, SystemDependency from .configtool import ConfigToolDependency +from .detect import packages from .factory import DependencyFactory from .framework import ExtraFrameworkDependency from .pkgconfig import PkgConfigDependency @@ -407,7 +408,9 @@ def python_factory(env: 'Environment', for_machine: 'MachineChoice', return candidates -pybind11_factory = DependencyFactory( +packages['python3'] = python_factory + +packages['pybind11'] = pybind11_factory = DependencyFactory( 'pybind11', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.CMAKE], configtool_class=Pybind11ConfigToolDependency, diff --git a/mesonbuild/dependencies/qt.py b/mesonbuild/dependencies/qt.py index 6d31859..1a86bd2 100644 --- a/mesonbuild/dependencies/qt.py +++ b/mesonbuild/dependencies/qt.py @@ -24,6 +24,7 @@ import typing as T from .base import DependencyException, DependencyMethods from .configtool import ConfigToolDependency +from .detect import packages from .framework import ExtraFrameworkDependency from .pkgconfig import PkgConfigDependency from .factory import DependencyFactory @@ -467,21 +468,21 @@ class Qt6PkgConfigDependency(Qt6WinMainMixin, QtPkgConfigDependency): return _qt_get_private_includes(mod_inc_dir, module, self.version) -qt4_factory = DependencyFactory( +packages['qt4'] = qt4_factory = DependencyFactory( 'qt4', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], pkgconfig_class=Qt4PkgConfigDependency, configtool_class=Qt4ConfigToolDependency, ) -qt5_factory = DependencyFactory( +packages['qt5'] = qt5_factory = DependencyFactory( 'qt5', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], pkgconfig_class=Qt5PkgConfigDependency, configtool_class=Qt5ConfigToolDependency, ) -qt6_factory = DependencyFactory( +packages['qt6'] = qt6_factory = DependencyFactory( 'qt6', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL], pkgconfig_class=Qt6PkgConfigDependency, diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py index be8ee70..257e4aa 100644 --- a/mesonbuild/dependencies/scalapack.py +++ b/mesonbuild/dependencies/scalapack.py @@ -22,6 +22,7 @@ from ..mesonlib import OptionKey from .base import DependencyMethods from .base import DependencyException from .cmake import CMakeDependency +from .detect import packages from .pkgconfig import PkgConfigDependency from .factory import factory_methods @@ -52,6 +53,8 @@ def scalapack_factory(env: 'Environment', for_machine: 'MachineChoice', return candidates +packages['scalapack'] = scalapack_factory + class MKLPkgConfigDependency(PkgConfigDependency): diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index f3879be..1dffa1f 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -29,6 +29,7 @@ from ..environment import detect_cpu_family from .base import DependencyException, DependencyMethods, DependencyTypeName, SystemDependency from .configtool import ConfigToolDependency +from .detect import packages from .factory import DependencyFactory if T.TYPE_CHECKING: @@ -136,6 +137,8 @@ class GnuStepDependency(ConfigToolDependency): version = '1' return version +packages['gnustep'] = GnuStepDependency + class SDL2DependencyConfigTool(ConfigToolDependency): @@ -187,6 +190,7 @@ class WxDependency(ConfigToolDependency): raise DependencyException('wxwidgets module argument is not a string') return candidates +packages['wxwidgets'] = WxDependency class VulkanDependencySystem(SystemDependency): @@ -244,20 +248,20 @@ class VulkanDependencySystem(SystemDependency): self.link_args.append(lib) return -gl_factory = DependencyFactory( +packages['gl'] = gl_factory = DependencyFactory( 'gl', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM], system_class=GLDependencySystem, ) -sdl2_factory = DependencyFactory( +packages['sdl2'] = sdl2_factory = DependencyFactory( 'sdl2', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE], configtool_class=SDL2DependencyConfigTool, cmake_name='SDL2', ) -vulkan_factory = DependencyFactory( +packages['vulkan'] = vulkan_factory = DependencyFactory( 'vulkan', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM], system_class=VulkanDependencySystem, |