diff options
-rw-r--r-- | mesonbuild/ast/introspection.py | 19 | ||||
-rw-r--r-- | mesonbuild/dependencies/cmake.py | 16 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 8 | ||||
-rwxr-xr-x | mesonbuild/msubprojects.py | 8 | ||||
-rw-r--r-- | test cases/unit/117 openssl cmake bug/meson.build | 5 | ||||
-rw-r--r-- | test cases/unit/117 openssl cmake bug/nativefile.ini | 7 | ||||
-rw-r--r-- | unittests/platformagnostictests.py | 7 |
7 files changed, 61 insertions, 9 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index fa4b8d3..1525a2d 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -362,3 +362,22 @@ class IntrospectionInterpreter(AstInterpreter): self.sanity_check_ast() self.parse_project() self.run() + + def extract_subproject_dir(self) -> T.Optional[str]: + '''Fast path to extract subproject_dir kwarg. + This is faster than self.parse_project() which also initialize options + and also calls parse_project() on every subproject. + ''' + if not self.ast.lines: + return + project = self.ast.lines[0] + # first line is always project() + if not isinstance(project, FunctionNode): + return + for kw, val in project.args.kwargs.items(): + assert isinstance(kw, IdNode), 'for mypy' + if kw.value == 'subproject_dir': + # mypy does not understand "and isinstance" + if isinstance(val, StringNode): + return val.value + return None diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py index 11d3564..2bb1f6b 100644 --- a/mesonbuild/dependencies/cmake.py +++ b/mesonbuild/dependencies/cmake.py @@ -652,3 +652,19 @@ class CMakeDependency(ExternalDependency): if default_value is not None: return default_value raise DependencyException(f'Could not get cmake variable and no default provided for {self!r}') + + +class CMakeDependencyFactory: + + def __init__(self, name: T.Optional[str] = None, modules: T.Optional[T.List[str]] = None): + self.name = name + self.modules = modules + + def __call__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None, force_use_global_compilers: bool = False) -> CMakeDependency: + if self.modules: + kwargs['modules'] = self.modules + return CMakeDependency(self.name or name, env, kwargs, language, force_use_global_compilers) + + @staticmethod + def log_tried() -> str: + return CMakeDependency.log_tried() diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 1a5502f..b186b5d 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -23,7 +23,7 @@ from .. import mesonlib from .. import mlog from .base import DependencyException, DependencyMethods from .base import BuiltinDependency, SystemDependency -from .cmake import CMakeDependency +from .cmake import CMakeDependency, CMakeDependencyFactory from .configtool import ConfigToolDependency from .detect import packages from .factory import DependencyFactory, factory_methods @@ -599,19 +599,19 @@ 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'])), + cmake_class=CMakeDependencyFactory('OpenSSL', modules=['OpenSSL::Crypto', 'OpenSSL::SSL']), ) 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'])), + cmake_class=CMakeDependencyFactory('OpenSSL', modules=['OpenSSL::Crypto']), ) packages['libssl'] = libssl_factory = DependencyFactory( 'libssl', [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM, DependencyMethods.CMAKE], system_class=OpensslSystemDependency, - cmake_class=lambda name, env, kwargs: CMakeDependency('OpenSSL', env, dict(kwargs, modules=['OpenSSL::SSL'])), + cmake_class=CMakeDependencyFactory('OpenSSL', modules=['OpenSSL::SSL']), ) diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py index d1b51f0..64a09b0 100755 --- a/mesonbuild/msubprojects.py +++ b/mesonbuild/msubprojects.py @@ -14,7 +14,7 @@ import tarfile import zipfile from . import mlog -from .ast import IntrospectionInterpreter, AstIDGenerator +from .ast import IntrospectionInterpreter from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree from .wrap.wrap import (Resolver, WrapException, ALL_TYPES, parse_patch_url, update_wrap_file, get_releases) @@ -693,11 +693,9 @@ def run(options: 'Arguments') -> int: mlog.error('Directory', mlog.bold(source_dir), 'does not seem to be a Meson source directory.') return 1 with mlog.no_logging(): - intr = IntrospectionInterpreter(source_dir, '', 'none', visitors = [AstIDGenerator()]) + intr = IntrospectionInterpreter(source_dir, '', 'none') intr.load_root_meson_file() - intr.sanity_check_ast() - intr.parse_project() - subproject_dir = intr.subproject_dir + subproject_dir = intr.extract_subproject_dir() or 'subprojects' if not os.path.isdir(os.path.join(source_dir, subproject_dir)): mlog.log('Directory', mlog.bold(source_dir), 'does not seem to have subprojects.') return 0 diff --git a/test cases/unit/117 openssl cmake bug/meson.build b/test cases/unit/117 openssl cmake bug/meson.build new file mode 100644 index 0000000..d08a8ef --- /dev/null +++ b/test cases/unit/117 openssl cmake bug/meson.build @@ -0,0 +1,5 @@ +project('bug', 'cpp') + +# When cmake is not available, +# this triggers the bug described in #12098 +openssl_dep = dependency('openssl') diff --git a/test cases/unit/117 openssl cmake bug/nativefile.ini b/test cases/unit/117 openssl cmake bug/nativefile.ini new file mode 100644 index 0000000..dd6b0ff --- /dev/null +++ b/test cases/unit/117 openssl cmake bug/nativefile.ini @@ -0,0 +1,7 @@ +[binaries] + +cmake = '/path/to/nothing' + +[built-in options] + +pkg_config_path = ''
\ No newline at end of file diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index 92c613d..204a22b 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -271,3 +271,10 @@ class PlatformAgnosticTests(BasePlatformTests): builddir = os.path.join(srcdir, '_build') self.change_builddir(builddir) self.init(srcdir, override_envvars={'MESON_PACKAGE_CACHE_DIR': os.path.join(srcdir, 'cache_dir')}) + + def test_cmake_openssl_not_found_bug(self): + """Issue #12098""" + testdir = os.path.join(self.unit_test_dir, '117 openssl cmake bug') + self.meson_native_files.append(os.path.join(testdir, 'nativefile.ini')) + out = self.init(testdir, allow_fail=True) + self.assertNotIn('Unhandled python exception', out) |