Skip to content

Commit 77eaf12

Browse files
mgornyeli-schwartz
authored andcommitted
scalapack: Fix exception when MKLROOT is unset
Fix `scalapack.MKLPkgConfigDependency` not to crash when `MKLROOT` is unset: ``` File "/meson/mesonbuild/dependencies/scalapack.py", line 65, in __init__ super().__init__(name, env, kwargs, language=language) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/meson/mesonbuild/dependencies/pkgconfig.py", line 322, in __init__ self._set_cargs() ~~~~~~~~~~~~~~~^^ File "/meson/mesonbuild/dependencies/scalapack.py", line 141, in _set_cargs cflags = self.pkgconfig.cflags(self.name, allow_system, define_variable=(('prefix', self.__mklroot.as_posix()),)) ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'as_posix' ``` The code is crashing because the `_set_cargs()` method assumes that `self.__mklroot` will always be set, presumably because it assumes it will only be called only when `MKLPkgConfigDependency.__init__()` finishes with `is_found = True`. However, both `_set_cargs()` and `_set_libs()` are called during `PkgConfigDependency.__init__()`, and therefore they will be called if pkg-config lookup succeeds even without `MKL_ROOT` set. To avoid the issue, check for `self.__mklroot is None` in both functions, and raise a `DependencyException` — effectively causing the pkg-config lookup to fail in a natural way. Fixes mesonbuild#11172 Signed-off-by: Michał Górny <[email protected]> (cherry picked from commit 27c5ac3)
1 parent 29fc4b0 commit 77eaf12

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mesonbuild/dependencies/scalapack.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import typing as T
1010

1111
from ..options import OptionKey
12-
from .base import DependencyMethods
12+
from .base import DependencyException, DependencyMethods
1313
from .cmake import CMakeDependency
1414
from .detect import packages
1515
from .pkgconfig import PkgConfigDependency
@@ -65,8 +65,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
6565
super().__init__(name, env, kwargs, language=language)
6666

6767
# Doesn't work with gcc on windows, but does on Linux
68-
if (not self.__mklroot or (env.machines[self.for_machine].is_windows()
69-
and self.clib_compiler.id == 'gcc')):
68+
if env.machines[self.for_machine].is_windows() and self.clib_compiler.id == 'gcc':
7069
self.is_found = False
7170

7271
# This can happen either because we're using GCC, we couldn't find the
@@ -96,6 +95,9 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
9695
self.version = v
9796

9897
def _set_libs(self) -> None:
98+
if self.__mklroot is None:
99+
raise DependencyException('MKLROOT not set')
100+
99101
super()._set_libs()
100102

101103
if self.env.machines[self.for_machine].is_windows():
@@ -133,6 +135,9 @@ def _set_libs(self) -> None:
133135
self.link_args.insert(i + 1, '-lmkl_blacs_intelmpi_lp64')
134136

135137
def _set_cargs(self) -> None:
138+
if self.__mklroot is None:
139+
raise DependencyException('MKLROOT not set')
140+
136141
allow_system = False
137142
if self.language == 'fortran':
138143
# gfortran doesn't appear to look in system paths for INCLUDE files,

0 commit comments

Comments
 (0)