|
|
|
@ -14,53 +14,41 @@ |
|
|
|
|
|
|
|
|
|
# This file contains the detection logic for miscellaneous external dependencies. |
|
|
|
|
|
|
|
|
|
import subprocess |
|
|
|
|
import functools |
|
|
|
|
import os |
|
|
|
|
import re |
|
|
|
|
import shutil |
|
|
|
|
import subprocess |
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
from .. import mlog |
|
|
|
|
from ..mesonlib import split_args, listify |
|
|
|
|
from .base import (DependencyException, DependencyMethods, ExternalDependency, ExternalProgram, |
|
|
|
|
PkgConfigDependency) |
|
|
|
|
from ..mesonlib import OrderedSet, join_args |
|
|
|
|
from .base import ( |
|
|
|
|
DependencyException, DependencyMethods, ConfigToolDependency, |
|
|
|
|
PkgConfigDependency, factory_methods |
|
|
|
|
) |
|
|
|
|
import typing as T |
|
|
|
|
|
|
|
|
|
if T.TYPE_CHECKING: |
|
|
|
|
from .base import Dependency |
|
|
|
|
from ..envconfig import MachineChoice |
|
|
|
|
from ..environment import Environment |
|
|
|
|
|
|
|
|
|
class HDF5Dependency(ExternalDependency): |
|
|
|
|
|
|
|
|
|
def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None: |
|
|
|
|
language = kwargs.get('language', 'c') |
|
|
|
|
super().__init__('hdf5', environment, kwargs, language=language) |
|
|
|
|
kwargs['required'] = False |
|
|
|
|
kwargs['silent'] = True |
|
|
|
|
self.is_found = False |
|
|
|
|
methods = listify(self.methods) |
|
|
|
|
class HDF5PkgConfigDependency(PkgConfigDependency): |
|
|
|
|
|
|
|
|
|
if language not in ('c', 'cpp', 'fortran'): |
|
|
|
|
raise DependencyException('Language {} is not supported with HDF5.'.format(language)) |
|
|
|
|
"""Handle brokenness in the HDF5 pkg-config files.""" |
|
|
|
|
|
|
|
|
|
if set([DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]).intersection(methods): |
|
|
|
|
pkgconfig_files = ['hdf5', 'hdf5-serial'] |
|
|
|
|
PCEXE = shutil.which('pkg-config') |
|
|
|
|
if PCEXE: |
|
|
|
|
# some distros put hdf5-1.2.3.pc with version number in .pc filename. |
|
|
|
|
ret = subprocess.run([PCEXE, '--list-all'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, |
|
|
|
|
universal_newlines=True) |
|
|
|
|
if ret.returncode == 0: |
|
|
|
|
for pkg in ret.stdout.split('\n'): |
|
|
|
|
if pkg.startswith(('hdf5')): |
|
|
|
|
pkgconfig_files.append(pkg.split(' ', 1)[0]) |
|
|
|
|
pkgconfig_files = list(set(pkgconfig_files)) # dedupe |
|
|
|
|
def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None) -> None: |
|
|
|
|
language = language or 'c' |
|
|
|
|
if language not in {'c', 'cpp', 'fortran'}: |
|
|
|
|
raise DependencyException('Language {} is not supported with HDF5.'.format(language)) |
|
|
|
|
|
|
|
|
|
for pkg in pkgconfig_files: |
|
|
|
|
pkgdep = PkgConfigDependency(pkg, environment, kwargs, language=self.language) |
|
|
|
|
if not pkgdep.found(): |
|
|
|
|
continue |
|
|
|
|
super().__init__(name, environment, kwargs, language) |
|
|
|
|
if not self.is_found: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
self.compile_args = pkgdep.get_compile_args() |
|
|
|
|
# some broken pkgconfig don't actually list the full path to the needed includes |
|
|
|
|
newinc = [] |
|
|
|
|
newinc = [] # type: T.List[str] |
|
|
|
|
for arg in self.compile_args: |
|
|
|
|
if arg.startswith('-I'): |
|
|
|
|
stem = 'static' if kwargs.get('static', False) else 'shared' |
|
|
|
@ -68,10 +56,8 @@ class HDF5Dependency(ExternalDependency): |
|
|
|
|
newinc.append('-I' + str(Path(arg[2:]) / stem)) |
|
|
|
|
self.compile_args += newinc |
|
|
|
|
|
|
|
|
|
# derive needed libraries by language |
|
|
|
|
pd_link_args = pkgdep.get_link_args() |
|
|
|
|
link_args = [] |
|
|
|
|
for larg in pd_link_args: |
|
|
|
|
link_args = [] # type: T.List[str] |
|
|
|
|
for larg in self.get_link_args(): |
|
|
|
|
lpath = Path(larg) |
|
|
|
|
# some pkg-config hdf5.pc (e.g. Ubuntu) don't include the commonly-used HL HDF5 libraries, |
|
|
|
|
# so let's add them if they exist |
|
|
|
@ -95,41 +81,96 @@ class HDF5Dependency(ExternalDependency): |
|
|
|
|
link_args.append(larg) |
|
|
|
|
|
|
|
|
|
self.link_args = link_args |
|
|
|
|
self.version = pkgdep.get_version() |
|
|
|
|
self.is_found = True |
|
|
|
|
self.pcdep = pkgdep |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if DependencyMethods.AUTO in methods: |
|
|
|
|
wrappers = {'c': 'h5cc', 'cpp': 'h5c++', 'fortran': 'h5fc'} |
|
|
|
|
comp_args = [] |
|
|
|
|
link_args = [] |
|
|
|
|
# have to always do C as well as desired language |
|
|
|
|
for lang in set([language, 'c']): |
|
|
|
|
prog = ExternalProgram(wrappers[lang], silent=True) |
|
|
|
|
if not prog.found(): |
|
|
|
|
return |
|
|
|
|
shlib_arg = '-noshlib' if kwargs.get('static', False) else '-shlib' |
|
|
|
|
cmd = prog.get_command() + [shlib_arg, '-show'] |
|
|
|
|
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, timeout=15) |
|
|
|
|
if p.returncode != 0: |
|
|
|
|
mlog.debug('Command', mlog.bold(str(cmd)), 'failed to run:') |
|
|
|
|
mlog.debug(mlog.bold('Standard output\n'), p.stdout) |
|
|
|
|
mlog.debug(mlog.bold('Standard error\n'), p.stderr) |
|
|
|
|
|
|
|
|
|
class HDF5ConfigToolDependency(ConfigToolDependency): |
|
|
|
|
|
|
|
|
|
"""Wrapper around hdf5 binary config tools.""" |
|
|
|
|
|
|
|
|
|
version_arg = '-showconfig' |
|
|
|
|
|
|
|
|
|
def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None) -> None: |
|
|
|
|
language = language or 'c' |
|
|
|
|
if language not in {'c', 'cpp', 'fortran'}: |
|
|
|
|
raise DependencyException('Language {} is not supported with HDF5.'.format(language)) |
|
|
|
|
|
|
|
|
|
if language == 'c': |
|
|
|
|
cenv = 'CC' |
|
|
|
|
tools = ['h5cc'] |
|
|
|
|
elif language == 'cpp': |
|
|
|
|
cenv = 'CXX' |
|
|
|
|
tools = ['h5c++'] |
|
|
|
|
elif language == 'fortran': |
|
|
|
|
cenv = 'FC' |
|
|
|
|
tools = ['h5fc'] |
|
|
|
|
else: |
|
|
|
|
raise DependencyException('How did you get here?') |
|
|
|
|
|
|
|
|
|
# We need this before we call super() |
|
|
|
|
for_machine = self.get_for_machine_from_kwargs(kwargs) |
|
|
|
|
|
|
|
|
|
nkwargs = kwargs.copy() |
|
|
|
|
nkwargs['tools'] = tools |
|
|
|
|
|
|
|
|
|
# Override the compiler that the config tools are going to use by |
|
|
|
|
# setting the environment variables that they use for the compiler and |
|
|
|
|
# linkers. |
|
|
|
|
compiler = environment.coredata.compilers[for_machine][language] |
|
|
|
|
try: |
|
|
|
|
os.environ['HDF5_{}'.format(cenv)] = join_args(compiler.get_exelist()) |
|
|
|
|
os.environ['HDF5_{}LINKER'.format(cenv)] = join_args(compiler.get_linker_exelist()) |
|
|
|
|
super().__init__(name, environment, nkwargs, language) |
|
|
|
|
finally: |
|
|
|
|
del os.environ['HDF5_{}'.format(cenv)] |
|
|
|
|
del os.environ['HDF5_{}LINKER'.format(cenv)] |
|
|
|
|
if not self.is_found: |
|
|
|
|
return |
|
|
|
|
args = split_args(p.stdout) |
|
|
|
|
|
|
|
|
|
args = self.get_config_value(['-show', '-noshlib' if kwargs.get('static', False) else '-shlib'], 'args') |
|
|
|
|
for arg in args[1:]: |
|
|
|
|
if arg.startswith(('-I', '-f', '-D')) or arg == '-pthread': |
|
|
|
|
comp_args.append(arg) |
|
|
|
|
self.compile_args.append(arg) |
|
|
|
|
elif arg.startswith(('-L', '-l', '-Wl')): |
|
|
|
|
link_args.append(arg) |
|
|
|
|
self.link_args.append(arg) |
|
|
|
|
elif Path(arg).is_file(): |
|
|
|
|
link_args.append(arg) |
|
|
|
|
self.compile_args = comp_args |
|
|
|
|
self.link_args = link_args |
|
|
|
|
self.is_found = True |
|
|
|
|
return |
|
|
|
|
self.link_args.append(arg) |
|
|
|
|
|
|
|
|
|
# If the language is not C we need to add C as a subdependency |
|
|
|
|
if language != 'c': |
|
|
|
|
nkwargs = kwargs.copy() |
|
|
|
|
nkwargs['language'] = 'c' |
|
|
|
|
# I'm being too clever for mypy and pylint |
|
|
|
|
self.is_found = self._add_sub_dependency(hdf5_factory(environment, for_machine, nkwargs)) # type: ignore # pylint: disable=no-value-for-parameter |
|
|
|
|
|
|
|
|
|
def _sanitize_version(self, ver: str) -> str: |
|
|
|
|
v = re.search(r'\s*HDF5 Version: (\d+\.\d+\.\d+)', ver) |
|
|
|
|
return v.group(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL}) |
|
|
|
|
def hdf5_factory(env: 'Environment', for_machine: 'MachineChoice', |
|
|
|
|
kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List[T.Callable[[], 'Dependency']]: |
|
|
|
|
language = kwargs.get('language') |
|
|
|
|
candidates = [] # type: T.List[T.Callable[[], Dependency]] |
|
|
|
|
|
|
|
|
|
if DependencyMethods.PKGCONFIG in methods: |
|
|
|
|
# Use an ordered set so that these remain the first tried pkg-config files |
|
|
|
|
pkgconfig_files = OrderedSet(['hdf5', 'hdf5-serial']) |
|
|
|
|
# FIXME: This won't honor pkg-config paths, and cross-native files |
|
|
|
|
PCEXE = shutil.which('pkg-config') |
|
|
|
|
if PCEXE: |
|
|
|
|
# some distros put hdf5-1.2.3.pc with version number in .pc filename. |
|
|
|
|
ret = subprocess.run([PCEXE, '--list-all'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, |
|
|
|
|
universal_newlines=True) |
|
|
|
|
if ret.returncode == 0: |
|
|
|
|
for pkg in ret.stdout.split('\n'): |
|
|
|
|
if pkg.startswith(('hdf5')): |
|
|
|
|
pkgconfig_files.add(pkg.split(' ', 1)[0]) |
|
|
|
|
|
|
|
|
|
for pkg in pkgconfig_files: |
|
|
|
|
candidates.append(functools.partial(HDF5PkgConfigDependency, pkg, env, kwargs, language)) |
|
|
|
|
|
|
|
|
|
if DependencyMethods.CONFIG_TOOL in methods: |
|
|
|
|
candidates.append(functools.partial(HDF5ConfigToolDependency, 'hdf5', env, kwargs, language)) |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def get_methods() -> T.List[DependencyMethods]: |
|
|
|
|
return [DependencyMethods.AUTO, DependencyMethods.PKGCONFIG] |
|
|
|
|
return candidates |
|
|
|
|