diff options
author | SmallWood-D <shay.gozan@gmail.com> | 2022-09-25 21:30:03 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2022-11-29 01:48:27 +0200 |
commit | d32ee583ada8304fb31d11382bc6055f6239a99b (patch) | |
tree | 02b30d6a37cfc2e2c9b0aa9f0db0e3e7bf4a3f1a /mesonbuild/dependencies | |
parent | 23fcea16e56cd154f995208a0443e3d8c18bd8bf (diff) | |
download | meson-d32ee583ada8304fb31d11382bc6055f6239a99b.zip meson-d32ee583ada8304fb31d11382bc6055f6239a99b.tar.gz meson-d32ee583ada8304fb31d11382bc6055f6239a99b.tar.bz2 |
Fix crash when toolchain is missing
Add a MissingCompiler class returned by compiler detecting methods
intead of None - accessing such an object raises a DependencyException
Fixes #10586
Co-authored-by: duckflyer <duckflyer@gmail.com>
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 19 | ||||
-rw-r--r-- | mesonbuild/dependencies/cuda.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/dev.py | 5 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/mpi.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/qt.py | 3 |
7 files changed, 23 insertions, 13 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index bbf31ad..b6fdb18 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -15,7 +15,7 @@ from .boost import BoostDependency from .cuda import CudaDependency from .hdf5 import hdf5_factory -from .base import Dependency, InternalDependency, ExternalDependency, NotFoundDependency +from .base import Dependency, InternalDependency, ExternalDependency, NotFoundDependency, MissingCompiler from .base import ( ExternalLibrary, DependencyException, DependencyMethods, BuiltinDependency, SystemDependency, get_leaf_external_dependencies) @@ -52,6 +52,7 @@ __all__ = [ 'ExternalLibrary', 'DependencyException', 'DependencyMethods', + 'MissingCompiler', 'CMakeDependency', 'ConfigToolDependency', diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index d901ef9..e78a420 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -46,6 +46,19 @@ class DependencyException(MesonException): '''Exceptions raised while trying to find dependencies''' +class MissingCompiler: + """Represent a None Compiler - when no tool chain is found. + replacing AttributeError with DependencyException""" + + def __getattr__(self, item: str) -> T.Any: + if item.startswith('__'): + raise AttributeError() + raise DependencyException('no toolchain found') + + def __bool__(self) -> bool: + return False + + class DependencyMethods(Enum): # Auto means to use whatever dependency checking mechanisms in whatever order meson thinks is best. AUTO = 'auto' @@ -361,7 +374,7 @@ class ExternalDependency(Dependency, HasNativeKwarg): HasNativeKwarg.__init__(self, kwargs) self.clib_compiler = detect_compiler(self.name, environment, self.for_machine, self.language) - def get_compiler(self) -> 'Compiler': + def get_compiler(self) -> T.Union['MissingCompiler', 'Compiler']: return self.clib_compiler def get_partial_dependency(self, *, compile_args: bool = False, @@ -573,7 +586,7 @@ def process_method_kw(possible: T.Iterable[DependencyMethods], kwargs: T.Dict[st return methods def detect_compiler(name: str, env: 'Environment', for_machine: MachineChoice, - language: T.Optional[str]) -> T.Optional['Compiler']: + language: T.Optional[str]) -> T.Union['MissingCompiler', 'Compiler']: """Given a language and environment find the compiler used.""" compilers = env.coredata.compilers[for_machine] @@ -591,7 +604,7 @@ def detect_compiler(name: str, env: 'Environment', for_machine: MachineChoice, return compilers[lang] except KeyError: continue - return None + return MissingCompiler() class SystemDependency(ExternalDependency): diff --git a/mesonbuild/dependencies/cuda.py b/mesonbuild/dependencies/cuda.py index d9b69c5..608d4f7 100644 --- a/mesonbuild/dependencies/cuda.py +++ b/mesonbuild/dependencies/cuda.py @@ -283,7 +283,7 @@ class CudaDependency(SystemDependency): return candidates def get_link_args(self, language: T.Optional[str] = None, raw: bool = False) -> T.List[str]: - args = [] + args: T.List[str] = [] if self.libdir: args += self.clib_compiler.get_linker_search_args(self.libdir) for lib in self.requested_modules: diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 606bb4f..b345387 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -499,11 +499,6 @@ class ZlibSystemDependency(SystemDependency): self.is_found = True self.link_args = ['-lz'] else: - # Without a clib_compiler we can't find zlib, so just give up. - if self.clib_compiler is None: - self.is_found = False - return - if self.clib_compiler.get_argument_syntax() == 'msvc': libs = ['zlib1' 'zlib'] else: diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index a5b1f41..e5f92b3 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -145,7 +145,7 @@ class ThreadDependency(SystemDependency): self.is_found = True # Happens if you are using a language with threads # concept without C, such as plain Cuda. - if self.clib_compiler is None: + if not self.clib_compiler: self.compile_args = [] self.link_args = [] else: diff --git a/mesonbuild/dependencies/mpi.py b/mesonbuild/dependencies/mpi.py index 2354767..a99a4cc 100644 --- a/mesonbuild/dependencies/mpi.py +++ b/mesonbuild/dependencies/mpi.py @@ -40,7 +40,7 @@ def mpi_factory(env: 'Environment', candidates: T.List['DependencyGenerator'] = [] compiler = detect_compiler('mpi', env, for_machine, language) - if compiler is None: + if not compiler: return [] compiler_is_intel = compiler.get_id() in {'intel', 'intel-cl'} diff --git a/mesonbuild/dependencies/qt.py b/mesonbuild/dependencies/qt.py index e1e9e07..c6162ed 100644 --- a/mesonbuild/dependencies/qt.py +++ b/mesonbuild/dependencies/qt.py @@ -33,6 +33,7 @@ if T.TYPE_CHECKING: from ..compilers import Compiler from ..envconfig import MachineInfo from ..environment import Environment + from ..dependencies import MissingCompiler def _qt_get_private_includes(mod_inc_dir: str, module: str, mod_version: str) -> T.List[str]: @@ -122,7 +123,7 @@ class _QtBase: """Mixin class for shared components between PkgConfig and Qmake.""" link_args: T.List[str] - clib_compiler: 'Compiler' + clib_compiler: T.Union['MissingCompiler', 'Compiler'] env: 'Environment' libexecdir: T.Optional[str] = None |