diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-17 18:05:12 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-26 13:10:32 -0400 |
commit | c82305db0c5216f821e43bfc7ea3c8e314d0dccd (patch) | |
tree | 2b294904907ee546b34f2180d49cce32dd5a2e58 | |
parent | c780d240e2f0a557eab0459a63e6936ff37615d1 (diff) | |
download | meson-c82305db0c5216f821e43bfc7ea3c8e314d0dccd.zip meson-c82305db0c5216f821e43bfc7ea3c8e314d0dccd.tar.gz meson-c82305db0c5216f821e43bfc7ea3c8e314d0dccd.tar.bz2 |
dependencies: delay often-unused imports
We expose detect.py as the mesonbuild.dependencies entrypoint and import
it upfront everywhere. But unless the `dependency()` function is
actually invoked, we don't need *any* of the private implementations for
this.
Avoid doing so until, as part of actual dependency lookup, we attempt
that specific dependency method. This avoids importing big modules if
`method:` is specified, and in most cases hopefully pkg-config works and
we can avoid importing the cmake implementation particularly.
Actually avoiding most of these imports requires more refactoring. But
even so, the garden path no longer needs to import the dub dependency
impl.
-rw-r--r-- | mesonbuild/dependencies/detect.py | 8 | ||||
-rw-r--r-- | test cases/unit/113 empty project/expected_mods.json | 3 | ||||
-rw-r--r-- | unittests/platformagnostictests.py | 2 |
3 files changed, 6 insertions, 7 deletions
diff --git a/mesonbuild/dependencies/detect.py b/mesonbuild/dependencies/detect.py index dea70a2..cdfdd13 100644 --- a/mesonbuild/dependencies/detect.py +++ b/mesonbuild/dependencies/detect.py @@ -14,10 +14,6 @@ from __future__ import annotations from .base import ExternalDependency, DependencyException, DependencyMethods, NotFoundDependency -from .cmake import CMakeDependency -from .dub import DubDependency -from .framework import ExtraFrameworkDependency -from .pkgconfig import PkgConfigDependency from ..mesonlib import listify, MachineChoice, PerMachine from .. import mlog @@ -201,21 +197,25 @@ def _build_external_dependency_list(name: str, env: 'Environment', for_machine: # Exclusive to when it is explicitly requested if 'dub' in methods: + from .dub import DubDependency candidates.append(functools.partial(DubDependency, name, env, kwargs)) # Preferred first candidate for auto. if 'pkg-config' in methods: + from .pkgconfig import PkgConfigDependency candidates.append(functools.partial(PkgConfigDependency, name, env, kwargs)) # On OSX only, try framework dependency detector. if 'extraframework' in methods: if env.machines[for_machine].is_darwin(): + from .framework import ExtraFrameworkDependency candidates.append(functools.partial(ExtraFrameworkDependency, name, env, kwargs)) # Only use CMake: # - if it's explicitly requested # - as a last resort, since it might not work 100% (see #6113) if 'cmake' in methods: + from .cmake import CMakeDependency candidates.append(functools.partial(CMakeDependency, name, env, kwargs)) return candidates diff --git a/test cases/unit/113 empty project/expected_mods.json b/test cases/unit/113 empty project/expected_mods.json index 2e7c289..9ad84d4 100644 --- a/test cases/unit/113 empty project/expected_mods.json +++ b/test cases/unit/113 empty project/expected_mods.json @@ -208,7 +208,6 @@ "mesonbuild.dependencies.cuda", "mesonbuild.dependencies.detect", "mesonbuild.dependencies.dev", - "mesonbuild.dependencies.dub", "mesonbuild.dependencies.factory", "mesonbuild.dependencies.framework", "mesonbuild.dependencies.hdf5", @@ -272,6 +271,6 @@ "mesonbuild.wrap", "mesonbuild.wrap.wrap" ], - "count": 98 + "count": 97 } } diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index bbc34c9..be90ee6 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -253,4 +253,4 @@ class PlatformAgnosticTests(BasePlatformTests): expected = json.load(f)['meson']['modules'] self.assertEqual(data['modules'], expected) - self.assertEqual(data['count'], 98) + self.assertEqual(data['count'], 97) |