deps: demote LLVM config to instance variable

Which fixes trying to use multiple versions of LLVM, and allows
simplifying the class somewhat.
pull/2378/head
Dylan Baker 7 years ago
parent 95ba1fcab2
commit 035bee5c54
  1. 39
      mesonbuild/dependencies/dev.py
  2. 5
      test cases/frameworks/15 llvm/meson.build

@ -129,9 +129,6 @@ class LLVMDependency(ExternalDependency):
'llvm-config-3.5', 'llvm-config35',
'llvm-config-5.0', 'llvm-config-devel', # development snapshot
]
llvmconfig = None
_llvmconfig_found = False
__best_found = None
__cpp_blacklist = {'-DNDEBUG'}
def __init__(self, environment, kwargs):
@ -139,11 +136,12 @@ class LLVMDependency(ExternalDependency):
# the C linker works fine if only using the C API.
super().__init__('llvm-config', environment, 'cpp', kwargs)
self.modules = []
self.llvmconfig = None
self.__best_found = None
# FIXME: Support multiple version requirements ala PkgConfigDependency
req_version = kwargs.get('version', None)
if self.llvmconfig is None:
self.check_llvmconfig(req_version)
if not self._llvmconfig_found:
if self.llvmconfig is None:
if self.__best_found is not None:
mlog.log('found {!r} but need:'.format(self.__best_found),
req_version)
@ -159,12 +157,14 @@ class LLVMDependency(ExternalDependency):
mlog.debug('stdout: {}\nstderr: {}'.format(out, err))
if self.required:
raise DependencyException('Dependency LLVM not found')
mlog.log('Dependency LLVM found:', mlog.red('NO'))
return
else:
self.version = out.strip()
mlog.log('Dependency LLVM found:', mlog.green('YES'))
self.is_found = True
self.version = out.strip()
p, out = Popen_safe(
[self.llvmconfig, '--libs', '--ldflags', '--system-libs'])[:2]
if p.returncode != 0:
@ -193,38 +193,33 @@ class LLVMDependency(ExternalDependency):
else:
mlog.log('LLVM module', mod, 'found:', mlog.green('YES'))
@classmethod
def check_llvmconfig(cls, version_req):
def check_llvmconfig(self, version_req):
"""Try to find the highest version of llvm-config."""
for llvmconfig in cls.llvm_config_bins:
for llvmconfig in self.llvm_config_bins:
try:
p, out = Popen_safe([llvmconfig, '--version'])[0:2]
out = out.strip()
if p.returncode != 0:
continue
# FIXME: As soon as some llvm-config is found, version checks
# in further dependnecy() calls will be ignored
if version_req:
if version_compare(out, version_req, strict=True):
if cls.__best_found and version_compare(out, '<={}'.format(cls.__best_found), strict=True):
if self.__best_found and version_compare(
out, '<={}'.format(self.__best_found), strict=True):
continue
cls.__best_found = out
cls.llvmconfig = llvmconfig
self.__best_found = out
self.llvmconfig = llvmconfig
else:
# If no specific version is requested use the first version
# found, since that should be the best.
cls.__best_found = out
cls.llvmconfig = llvmconfig
self.__best_found = out
self.llvmconfig = llvmconfig
break
except (FileNotFoundError, PermissionError):
pass
if cls.__best_found:
if self.__best_found:
mlog.log('Found llvm-config:',
mlog.bold(shutil.which(cls.llvmconfig)),
mlog.bold(shutil.which(self.llvmconfig)),
'({})'.format(out.strip()))
cls._llvmconfig_found = True
else:
cls.llvmconfig = False
def need_threads(self):
return True

@ -10,8 +10,7 @@ llvm_dep = dependency(
d = dependency('llvm', modules : 'not-found', required : false)
assert(d.found() == false, 'not-found llvm module found')
# XXX: Version checks are broken, see FIXME in LLVMDependency
#d = dependency('llvm', version : '<0.1', required : false)
#assert(d.found() == false, 'ancient llvm module found')
d = dependency('llvm', version : '<0.1', required : false)
assert(d.found() == false, 'ancient llvm module found')
executable('sum', 'sum.c', dependencies : llvm_dep)

Loading…
Cancel
Save