deps: demote LLVM config to instance variable
Which fixes trying to use multiple versions of LLVM, and allows simplifying the class somewhat.
This commit is contained in:
parent
95ba1fcab2
commit
035bee5c54
|
@ -129,9 +129,6 @@ class LLVMDependency(ExternalDependency):
|
||||||
'llvm-config-3.5', 'llvm-config35',
|
'llvm-config-3.5', 'llvm-config35',
|
||||||
'llvm-config-5.0', 'llvm-config-devel', # development snapshot
|
'llvm-config-5.0', 'llvm-config-devel', # development snapshot
|
||||||
]
|
]
|
||||||
llvmconfig = None
|
|
||||||
_llvmconfig_found = False
|
|
||||||
__best_found = None
|
|
||||||
__cpp_blacklist = {'-DNDEBUG'}
|
__cpp_blacklist = {'-DNDEBUG'}
|
||||||
|
|
||||||
def __init__(self, environment, kwargs):
|
def __init__(self, environment, kwargs):
|
||||||
|
@ -139,11 +136,12 @@ class LLVMDependency(ExternalDependency):
|
||||||
# the C linker works fine if only using the C API.
|
# the C linker works fine if only using the C API.
|
||||||
super().__init__('llvm-config', environment, 'cpp', kwargs)
|
super().__init__('llvm-config', environment, 'cpp', kwargs)
|
||||||
self.modules = []
|
self.modules = []
|
||||||
|
self.llvmconfig = None
|
||||||
|
self.__best_found = None
|
||||||
# FIXME: Support multiple version requirements ala PkgConfigDependency
|
# FIXME: Support multiple version requirements ala PkgConfigDependency
|
||||||
req_version = kwargs.get('version', None)
|
req_version = kwargs.get('version', None)
|
||||||
|
self.check_llvmconfig(req_version)
|
||||||
if self.llvmconfig is None:
|
if self.llvmconfig is None:
|
||||||
self.check_llvmconfig(req_version)
|
|
||||||
if not self._llvmconfig_found:
|
|
||||||
if self.__best_found is not None:
|
if self.__best_found is not None:
|
||||||
mlog.log('found {!r} but need:'.format(self.__best_found),
|
mlog.log('found {!r} but need:'.format(self.__best_found),
|
||||||
req_version)
|
req_version)
|
||||||
|
@ -159,28 +157,30 @@ class LLVMDependency(ExternalDependency):
|
||||||
mlog.debug('stdout: {}\nstderr: {}'.format(out, err))
|
mlog.debug('stdout: {}\nstderr: {}'.format(out, err))
|
||||||
if self.required:
|
if self.required:
|
||||||
raise DependencyException('Dependency LLVM not found')
|
raise DependencyException('Dependency LLVM not found')
|
||||||
|
mlog.log('Dependency LLVM found:', mlog.red('NO'))
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
self.version = out.strip()
|
|
||||||
mlog.log('Dependency LLVM found:', mlog.green('YES'))
|
|
||||||
self.is_found = True
|
|
||||||
|
|
||||||
p, out = Popen_safe(
|
mlog.log('Dependency LLVM found:', mlog.green('YES'))
|
||||||
[self.llvmconfig, '--libs', '--ldflags', '--system-libs'])[:2]
|
self.is_found = True
|
||||||
if p.returncode != 0:
|
|
||||||
raise DependencyException('Could not generate libs for LLVM.')
|
|
||||||
self.link_args = shlex.split(out)
|
|
||||||
|
|
||||||
p, out = Popen_safe([self.llvmconfig, '--cppflags'])[:2]
|
self.version = out.strip()
|
||||||
if p.returncode != 0:
|
|
||||||
raise DependencyException('Could not generate includedir for LLVM.')
|
|
||||||
cargs = mesonlib.OrderedSet(shlex.split(out))
|
|
||||||
self.compile_args = list(cargs.difference(self.__cpp_blacklist))
|
|
||||||
|
|
||||||
p, out = Popen_safe([self.llvmconfig, '--components'])[:2]
|
p, out = Popen_safe(
|
||||||
if p.returncode != 0:
|
[self.llvmconfig, '--libs', '--ldflags', '--system-libs'])[:2]
|
||||||
raise DependencyException('Could not generate modules for LLVM.')
|
if p.returncode != 0:
|
||||||
self.modules = shlex.split(out)
|
raise DependencyException('Could not generate libs for LLVM.')
|
||||||
|
self.link_args = shlex.split(out)
|
||||||
|
|
||||||
|
p, out = Popen_safe([self.llvmconfig, '--cppflags'])[:2]
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise DependencyException('Could not generate includedir for LLVM.')
|
||||||
|
cargs = mesonlib.OrderedSet(shlex.split(out))
|
||||||
|
self.compile_args = list(cargs.difference(self.__cpp_blacklist))
|
||||||
|
|
||||||
|
p, out = Popen_safe([self.llvmconfig, '--components'])[:2]
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise DependencyException('Could not generate modules for LLVM.')
|
||||||
|
self.modules = shlex.split(out)
|
||||||
|
|
||||||
modules = mesonlib.stringlistify(mesonlib.flatten(kwargs.get('modules', [])))
|
modules = mesonlib.stringlistify(mesonlib.flatten(kwargs.get('modules', [])))
|
||||||
for mod in sorted(set(modules)):
|
for mod in sorted(set(modules)):
|
||||||
|
@ -193,38 +193,33 @@ class LLVMDependency(ExternalDependency):
|
||||||
else:
|
else:
|
||||||
mlog.log('LLVM module', mod, 'found:', mlog.green('YES'))
|
mlog.log('LLVM module', mod, 'found:', mlog.green('YES'))
|
||||||
|
|
||||||
@classmethod
|
def check_llvmconfig(self, version_req):
|
||||||
def check_llvmconfig(cls, version_req):
|
|
||||||
"""Try to find the highest version of llvm-config."""
|
"""Try to find the highest version of llvm-config."""
|
||||||
for llvmconfig in cls.llvm_config_bins:
|
for llvmconfig in self.llvm_config_bins:
|
||||||
try:
|
try:
|
||||||
p, out = Popen_safe([llvmconfig, '--version'])[0:2]
|
p, out = Popen_safe([llvmconfig, '--version'])[0:2]
|
||||||
out = out.strip()
|
out = out.strip()
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
continue
|
continue
|
||||||
# FIXME: As soon as some llvm-config is found, version checks
|
|
||||||
# in further dependnecy() calls will be ignored
|
|
||||||
if version_req:
|
if version_req:
|
||||||
if version_compare(out, version_req, strict=True):
|
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
|
continue
|
||||||
cls.__best_found = out
|
self.__best_found = out
|
||||||
cls.llvmconfig = llvmconfig
|
self.llvmconfig = llvmconfig
|
||||||
else:
|
else:
|
||||||
# If no specific version is requested use the first version
|
# If no specific version is requested use the first version
|
||||||
# found, since that should be the best.
|
# found, since that should be the best.
|
||||||
cls.__best_found = out
|
self.__best_found = out
|
||||||
cls.llvmconfig = llvmconfig
|
self.llvmconfig = llvmconfig
|
||||||
break
|
break
|
||||||
except (FileNotFoundError, PermissionError):
|
except (FileNotFoundError, PermissionError):
|
||||||
pass
|
pass
|
||||||
if cls.__best_found:
|
if self.__best_found:
|
||||||
mlog.log('Found llvm-config:',
|
mlog.log('Found llvm-config:',
|
||||||
mlog.bold(shutil.which(cls.llvmconfig)),
|
mlog.bold(shutil.which(self.llvmconfig)),
|
||||||
'({})'.format(out.strip()))
|
'({})'.format(out.strip()))
|
||||||
cls._llvmconfig_found = True
|
|
||||||
else:
|
|
||||||
cls.llvmconfig = False
|
|
||||||
|
|
||||||
def need_threads(self):
|
def need_threads(self):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -10,8 +10,7 @@ llvm_dep = dependency(
|
||||||
d = dependency('llvm', modules : 'not-found', required : false)
|
d = dependency('llvm', modules : 'not-found', required : false)
|
||||||
assert(d.found() == false, 'not-found llvm module found')
|
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)
|
||||||
#d = dependency('llvm', version : '<0.1', required : false)
|
assert(d.found() == false, 'ancient llvm module found')
|
||||||
#assert(d.found() == false, 'ancient llvm module found')
|
|
||||||
|
|
||||||
executable('sum', 'sum.c', dependencies : llvm_dep)
|
executable('sum', 'sum.c', dependencies : llvm_dep)
|
||||||
|
|
Loading…
Reference in New Issue