Skip to content

Commit

Permalink
dependencies: Use a DependencyFactory for LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Jan 29, 2020
1 parent 8a9d6b1 commit 29b6d3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
7 changes: 4 additions & 3 deletions mesonbuild/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from .base import ( # noqa: F401
Dependency, DependencyException, DependencyMethods, ExternalProgram, EmptyExternalProgram, NonExistingExternalProgram,
ExternalDependency, NotFoundDependency, ExternalLibrary, ExtraFrameworkDependency, InternalDependency,
PkgConfigDependency, CMakeDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language)
from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency
PkgConfigDependency, CMakeDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language,
DependencyFactory)
from .dev import GMockDependency, GTestDependency, ValgrindDependency, llvm_factory
from .coarrays import CoarrayDependency
from .mpi import MPIDependency
from .scalapack import ScalapackDependency
Expand All @@ -33,7 +34,7 @@
# From dev:
'gtest': GTestDependency,
'gmock': GMockDependency,
'llvm': LLVMDependency,
'llvm': llvm_factory,
'valgrind': ValgrindDependency,

'boost': BoostDependency,
Expand Down
6 changes: 5 additions & 1 deletion mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,7 @@ class DependencyFactory:
"""

def __init__(self, name: str, methods: T.List[DependencyMethods], *,
extra_kwargs: T.Optional[T.Dict[str, T.Any]] = None,
pkgconfig_name: T.Optional[str] = None,
pkgconfig_class: 'T.Type[PkgConfigDependency]' = PkgConfigDependency,
cmake_name: T.Optional[str] = None,
Expand All @@ -2224,6 +2225,7 @@ def __init__(self, name: str, methods: T.List[DependencyMethods], *,
if DependencyMethods.CONFIG_TOOL in methods and not configtool_class:
raise DependencyException('A configtool must have a custom class')

self.extra_kwargs = extra_kwargs or {}
self.methods = methods
self.classes = {
# Just attach the correct name right now, either the generic name
Expand Down Expand Up @@ -2256,8 +2258,10 @@ def __call__(self, env: Environment, for_machine: MachineChoice,
kwargs: T.Dict[str, T.Any]) -> T.List['DependencyType']:
"""Return a list of Dependencies with the arguments already attached."""
methods = process_method_kw(self.methods, kwargs)
nwargs = self.extra_kwargs.copy()
nwargs.update(kwargs)

return [functools.partial(self.classes[m], env, kwargs) for m in methods
return [functools.partial(self.classes[m], env, nwargs) for m in methods
if self._process_method(m, env, for_machine)]


Expand Down
42 changes: 15 additions & 27 deletions mesonbuild/dependencies/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import glob
import os
import re
import typing as T

from .. import mesonlib, mlog
from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice
from ..environment import get_llvm_tool_names
from .base import (
DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency,
strip_system_libdirs, ConfigToolDependency, CMakeDependency, process_method_kw
strip_system_libdirs, ConfigToolDependency, CMakeDependency, process_method_kw,
DependencyFactory,
)
from .misc import ThreadDependency

import typing as T


def get_shared_library_suffix(environment, for_machine: MachineChoice):
"""This is only guaranteed to work for languages that compile to machine
Expand Down Expand Up @@ -204,7 +204,7 @@ class LLVMDependencyConfigTool(ConfigToolDependency):
tool_name = 'llvm-config'
__cpp_blacklist = {'-DNDEBUG'}

def __init__(self, environment, kwargs):
def __init__(self, name: str, environment, kwargs):
self.tools = get_llvm_tool_names('llvm-config')

# Fedora starting with Fedora 30 adds a suffix of the number
Expand All @@ -218,7 +218,7 @@ def __init__(self, environment, kwargs):

# It's necessary for LLVM <= 3.8 to use the C++ linker. For 3.9 and 4.0
# the C linker works fine if only using the C API.
super().__init__('LLVM', environment, kwargs, language='cpp')
super().__init__(name, environment, kwargs, language='cpp')
self.provided_modules = []
self.required_modules = set()
self.module_details = []
Expand Down Expand Up @@ -391,10 +391,10 @@ def log_details(self):
return ''

class LLVMDependencyCMake(CMakeDependency):
def __init__(self, env, kwargs):
def __init__(self, name: str, env, kwargs):
self.llvm_modules = stringlistify(extract_as_list(kwargs, 'modules'))
self.llvm_opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules'))
super().__init__('LLVM', env, kwargs, language='cpp')
super().__init__(name, env, kwargs, language='cpp')

if self.traceparser is None:
return
Expand Down Expand Up @@ -433,26 +433,6 @@ def _original_module_name(self, module: str) -> str:
return orig_name[0]
return module

class LLVMDependency(ExternalDependency):
def __init__(self, env, kwargs):
super().__init__('LLVM', env, kwargs, language='cpp')

@classmethod
def _factory(cls, env, kwargs):
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []

if DependencyMethods.CONFIG_TOOL in methods:
candidates.append(functools.partial(LLVMDependencyConfigTool, env, kwargs))

if DependencyMethods.CMAKE in methods:
candidates.append(functools.partial(LLVMDependencyCMake, env, kwargs))

return candidates

@staticmethod
def get_methods():
return [DependencyMethods.CMAKE, DependencyMethods.CONFIG_TOOL]

class ValgrindDependency(PkgConfigDependency):
'''
Expand All @@ -464,3 +444,11 @@ def __init__(self, env, kwargs):

def get_link_args(self, **kwargs):
return []


llvm_factory = DependencyFactory(
'LLVM',
[DependencyMethods.CMAKE, DependencyMethods.CONFIG_TOOL],
cmake_class=LLVMDependencyCMake,
configtool_class=LLVMDependencyConfigTool,
)

0 comments on commit 29b6d3e

Please sign in to comment.