diff options
| -rw-r--r-- | mesonbuild/dependencies/__init__.py | 2 | ||||
| -rw-r--r-- | mesonbuild/dependencies/base.py | 9 | ||||
| -rw-r--r-- | mesonbuild/dependencies/boost.py | 2 | ||||
| -rw-r--r-- | mesonbuild/dependencies/cuda.py | 7 | ||||
| -rw-r--r-- | mesonbuild/dependencies/misc.py | 9 | ||||
| -rw-r--r-- | mesonbuild/dependencies/scalapack.py | 2 | ||||
| -rw-r--r-- | mesonbuild/interpreter/kwargs.py | 1 | ||||
| -rw-r--r-- | mesonbuild/interpreter/mesonmain.py | 5 | ||||
| -rw-r--r-- | mesonbuild/interpreter/type_checking.py | 1 | ||||
| -rw-r--r-- | unittests/failuretests.py | 2 |
10 files changed, 24 insertions, 16 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 95e606975..00548e3ae 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -114,7 +114,7 @@ class FooSystemDependency(ExternalDependency): return get_option = environment.coredata.get_option - static_opt = kwargs.get('static', get_option(Mesonlib.OptionKey('prefer_static')) + static_opt = kwargs['static'] if kwargs.get('static') is not None else get_option(Mesonlib.OptionKey('prefer_static') static = Mesonlib.LibType.STATIC if static_opt else Mesonlib.LibType.SHARED lib = self.clib_compiler.find_library( 'foo', environment, [os.path.join(root, 'lib')], libtype=static) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index ddf6088bd..58a40bd38 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -55,6 +55,7 @@ if T.TYPE_CHECKING: optional_modules: T.List[str] private_headers: bool required: bool + static: T.Optional[bool] _MissingCompilerBase = Compiler else: @@ -412,10 +413,12 @@ class ExternalDependency(Dependency): self.version_reqs = T.cast('T.Optional[T.List[str]]', version_reqs) self.required = kwargs.get('required', True) self.silent = T.cast('bool', kwargs.get('silent', False)) - self.static = T.cast('bool', kwargs.get('static', self.env.coredata.optstore.get_value_for(OptionKey('prefer_static')))) + static = kwargs.get('static') + if static is None: + static = T.cast('bool', self.env.coredata.optstore.get_value_for(OptionKey('prefer_static'))) + self.static = static + self.libtype = LibType.STATIC if self.static else LibType.PREFER_SHARED self.libtype = LibType.STATIC if self.static else LibType.PREFER_SHARED - if not isinstance(self.static, bool): - raise DependencyException('Static keyword must be boolean') # Is this dependency to be run on the build platform? self.for_machine = kwargs.get('native', MachineChoice.HOST) self.clib_compiler = detect_compiler(self.name, environment, self.for_machine, self.language) diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 160eecb99..517d1e832 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -348,7 +348,7 @@ class BoostDependency(SystemDependency): self.multithreading = kwargs.get('threading', 'multi') == 'multi' self.boost_root: T.Optional[Path] = None - self.explicit_static = 'static' in kwargs + self.explicit_static = kwargs.get('static') is not None # Extract and validate modules self.modules = kwargs.get('modules', []) diff --git a/mesonbuild/dependencies/cuda.py b/mesonbuild/dependencies/cuda.py index ddfb2ea48..b09a4378f 100644 --- a/mesonbuild/dependencies/cuda.py +++ b/mesonbuild/dependencies/cuda.py @@ -44,7 +44,7 @@ class CudaDependency(SystemDependency): # By default, we prefer to link the static CUDA runtime, since this is what nvcc also does by default: # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#cudart-none-shared-static-cudart req_modules = ['cudart'] - if kwargs.get('static', True): + if kwargs.get('static') is not False: req_modules = ['cudart_static'] self.requested_modules = req_modules + self.requested_modules @@ -68,7 +68,10 @@ class CudaDependency(SystemDependency): self.libdir = os.path.join(self.cuda_path, self.target_path, arch_libdir) mlog.debug('CUDA library directory is', mlog.bold(self.libdir)) - if 'static' not in kwargs: + # For legacy reasons cuda ignores the `prefer_static` option, and treats + # anything short of `static : false` as `static : true`. This is the + # opposite behavior of all other languages. + if kwargs.get('static') is None: self.libtype = LibType.PREFER_STATIC self.is_found = self._find_requested_libraries() diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index f73dbdeff..672f58ae2 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -449,7 +449,7 @@ class IntlSystemDependency(SystemDependency): self.is_found = True if self.static: - if not self._add_sub_dependency(iconv_factory(env, self.for_machine, {'static': True})): # type: ignore[typeddict-unknown-key] + if not self._add_sub_dependency(iconv_factory(env, self.for_machine, {'static': True})): self.is_found = False @@ -460,7 +460,7 @@ class OpensslSystemDependency(SystemDependency): dependency_kwargs: DependencyObjectKWs = { 'method': DependencyMethods.SYSTEM, 'static': self.static, - } # type: ignore[typeddict-unknown-key] + } if not self.clib_compiler.has_header('openssl/ssl.h', '', env)[0]: return @@ -573,7 +573,10 @@ def shaderc_factory(env: 'Environment', shared_libs = ['shaderc'] static_libs = ['shaderc_combined', 'shaderc_static'] - if kwargs.get('static', env.coredata.optstore.get_value_for(OptionKey('prefer_static'))): + static = kwargs.get('static') + if static is None: + static = T.cast('bool', env.coredata.optstore.get_value_for(OptionKey('prefer_static'))) + if static: c = [functools.partial(PkgConfigDependency, name, env, kwargs) for name in static_libs + shared_libs] else: diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py index 1107aa8ac..26a6e3904 100644 --- a/mesonbuild/dependencies/scalapack.py +++ b/mesonbuild/dependencies/scalapack.py @@ -29,7 +29,7 @@ def scalapack_factory(env: 'Environment', for_machine: 'MachineChoice', candidates: T.List['DependencyGenerator'] = [] if DependencyMethods.PKGCONFIG in methods: - static_opt = kwargs.get('static', env.coredata.optstore.get_value_for(OptionKey('prefer_static'))) + static_opt = kwargs['static'] if kwargs.get('static') is not None else env.coredata.optstore.get_value_for(OptionKey('prefer_static')) mkl = 'mkl-static-lp64-iomp' if static_opt else 'mkl-dynamic-lp64-iomp' candidates.append(functools.partial( MKLPkgConfigDependency, mkl, env, kwargs)) diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 02097de0a..2a0d1f867 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -509,3 +509,4 @@ class FuncDependency(ExtractRequired): not_found_message: str optional_modules: T.List[str] private_headers: bool + static: T.Optional[bool] diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 6ae2d2148..74b655816 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -383,10 +383,7 @@ class MesonMain(MesonInterpreterObject): # We need the cast here as get_dep_identifier works on such a dict, # which FuncOverrideDependency is, but mypy can't figure that out nkwargs: DependencyObjectKWs = kwargs.copy() # type: ignore[assignment] - if static is None: - del nkwargs['static'] # type: ignore[typeddict-item] - else: - nkwargs['static'] = static # type: ignore[typeddict-unknown-key] + nkwargs['static'] = static identifier = dependencies.get_dep_identifier(name, nkwargs) for_machine = kwargs['native'] override = self.build.dependency_overrides[for_machine].get(identifier) diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index e2207176c..6a7cfb86f 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -951,4 +951,5 @@ DEPENDENCY_KWS: T.List[KwargInfo] = [ KwargInfo('not_found_message', str, default='', since='0.50.0'), KwargInfo('optional_modules', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('private_headers', bool, default=False), + KwargInfo('static', (bool, NoneType)), ] diff --git a/unittests/failuretests.py b/unittests/failuretests.py index fa860d0a0..bcc4aafdb 100644 --- a/unittests/failuretests.py +++ b/unittests/failuretests.py @@ -148,7 +148,7 @@ class FailureTests(BasePlatformTests): if subprocess.call(['pkg-config', '--exists', 'zlib']) != 0: raise unittest.SkipTest('zlib not found with pkg-config') a = (("dependency('zlib', method : 'fail')", 'dependency keyword argument "method" must be one of auto, builtin, cmake, config-tool, cups-config, dub, extraframework, libwmf-config, pcap-config, pkg-config, qmake, sdlconfig, sysconfig, system, not fail'), - ("dependency('zlib', static : '1')", "[Ss]tatic.*boolean"), + ("dependency('zlib', static : '1')", "dependency keyword argument 'static' was of type str but should have been one of: bool, NoneType"), ("dependency('zlib', version : 1)", "Item must be a list or one of <class 'str'>"), ("dependency('zlib', required : 1)", "dependency keyword argument 'required' was of type int but should have been one of: bool, UserFeatureOption"), ("dependency('zlib', method : 1)", "dependency keyword argument 'method' was of type int but should have been str"), |
