dependencies: Use a custom factory for shaderc

This commit is contained in:
Dylan Baker 2020-01-08 16:13:26 -08:00
parent b0f0d30cf3
commit 89c67383cc
2 changed files with 42 additions and 29 deletions

View File

@ -24,7 +24,7 @@ from .dev import ValgrindDependency, gmock_factory, gtest_factory, llvm_factory
from .coarrays import CoarrayDependency from .coarrays import CoarrayDependency
from .mpi import MPIDependency from .mpi import MPIDependency
from .scalapack import ScalapackDependency from .scalapack import ScalapackDependency
from .misc import (BlocksDependency, CursesDependency, NetCDFDependency, OpenMPDependency, ThreadDependency, ShadercDependency, cups_factory, gpgme_factory, libgcrypt_factory, libwmf_factory, pcap_factory, python3_factory) from .misc import (BlocksDependency, CursesDependency, NetCDFDependency, OpenMPDependency, ThreadDependency, cups_factory, gpgme_factory, libgcrypt_factory, libwmf_factory, pcap_factory, python3_factory, shaderc_factory)
from .platform import AppleFrameworks from .platform import AppleFrameworks
from .ui import GnuStepDependency, Qt4Dependency, Qt5Dependency, WxDependency, gl_factory, sdl2_factory, vulkan_factory from .ui import GnuStepDependency, Qt4Dependency, Qt5Dependency, WxDependency, gl_factory, sdl2_factory, vulkan_factory
@ -57,7 +57,7 @@ packages.update({
'libwmf': libwmf_factory, 'libwmf': libwmf_factory,
'libgcrypt': libgcrypt_factory, 'libgcrypt': libgcrypt_factory,
'gpgme': gpgme_factory, 'gpgme': gpgme_factory,
'shaderc': ShadercDependency, 'shaderc': shaderc_factory,
# From platform: # From platform:
'appleframeworks': AppleFrameworks, 'appleframeworks': AppleFrameworks,

View File

@ -18,6 +18,7 @@ from pathlib import Path
import functools import functools
import re import re
import sysconfig import sysconfig
import typing as T
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
@ -27,9 +28,14 @@ from ..mesonlib import listify
from .base import ( from .base import (
DependencyException, DependencyMethods, ExternalDependency, DependencyException, DependencyMethods, ExternalDependency,
PkgConfigDependency, CMakeDependency, ConfigToolDependency, PkgConfigDependency, CMakeDependency, ConfigToolDependency,
process_method_kw, DependencyFactory, process_method_kw, factory_methods, DependencyFactory,
) )
if T.TYPE_CHECKING:
from ..environment import Environment, MachineChoice
from .base import DependencyType # noqa: F401
class NetCDFDependency(ExternalDependency): class NetCDFDependency(ExternalDependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
@ -422,32 +428,6 @@ class ShadercDependency(ExternalDependency):
def log_tried(self): def log_tried(self):
return 'system' return 'system'
@classmethod
def _factory(cls, environment, kwargs):
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
# ShaderC packages their shared and static libs together
# and provides different pkg-config files for each one. We
# smooth over this difference by handling the static
# keyword before handing off to the pkg-config handler.
shared_libs = ['shaderc']
static_libs = ['shaderc_combined', 'shaderc_static']
if kwargs.get('static', False):
c = [functools.partial(PkgConfigDependency, name, environment, kwargs)
for name in static_libs + shared_libs]
else:
c = [functools.partial(PkgConfigDependency, name, environment, kwargs)
for name in shared_libs + static_libs]
candidates.extend(c)
if DependencyMethods.SYSTEM in methods:
candidates.append(functools.partial(ShadercDependency, environment, kwargs))
return candidates
@staticmethod @staticmethod
def get_methods(): def get_methods():
return [DependencyMethods.SYSTEM, DependencyMethods.PKGCONFIG] return [DependencyMethods.SYSTEM, DependencyMethods.PKGCONFIG]
@ -477,6 +457,39 @@ class CursesDependency(ExternalDependency):
return [DependencyMethods.AUTO, DependencyMethods.PKGCONFIG] return [DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM})
def shaderc_factory(env: 'Environment', for_machine: 'MachineChoice',
kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyType']:
"""Custom DependencyFactory for ShaderC.
ShaderC's odd you get three different libraries from the same build
thing are just easier to represent as a separate function than
twisting DependencyFactory even more.
"""
candidates = [] # type: T.List['DependencyType']
if DependencyMethods.PKGCONFIG in methods:
# ShaderC packages their shared and static libs together
# and provides different pkg-config files for each one. We
# smooth over this difference by handling the static
# keyword before handing off to the pkg-config handler.
shared_libs = ['shaderc']
static_libs = ['shaderc_combined', 'shaderc_static']
if kwargs.get('static', False):
c = [functools.partial(PkgConfigDependency, name, env, kwargs)
for name in static_libs + shared_libs]
else:
c = [functools.partial(PkgConfigDependency, name, env, kwargs)
for name in shared_libs + static_libs]
candidates.extend(c)
if DependencyMethods.SYSTEM in methods:
candidates.append(functools.partial(ShadercDependency, environment, kwargs))
return candidates
cups_factory = DependencyFactory( cups_factory = DependencyFactory(
'cups', 'cups',
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE], [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE],