environment: Add detection logic for cython

pull/8706/head
Dylan Baker 4 years ago
parent edf1a21722
commit cf17ef3867
  1. 28
      mesonbuild/environment.py

@ -87,6 +87,7 @@ from .compilers import (
ClangObjCPPCompiler, ClangObjCPPCompiler,
ClangClCCompiler, ClangClCCompiler,
ClangClCPPCompiler, ClangClCPPCompiler,
CythonCompiler,
FlangFortranCompiler, FlangFortranCompiler,
G95FortranCompiler, G95FortranCompiler,
GnuCCompiler, GnuCCompiler,
@ -732,6 +733,7 @@ class Environment:
self.default_rust = ['rustc'] self.default_rust = ['rustc']
self.default_swift = ['swiftc'] self.default_swift = ['swiftc']
self.default_vala = ['valac'] self.default_vala = ['valac']
self.default_cython = [['cython']]
self.default_static_linker = ['ar', 'gar'] self.default_static_linker = ['ar', 'gar']
self.default_strip = ['strip'] self.default_strip = ['strip']
self.vs_static_linker = ['lib'] self.vs_static_linker = ['lib']
@ -1757,6 +1759,30 @@ class Environment:
self._handle_exceptions(popen_exceptions, compilers) self._handle_exceptions(popen_exceptions, compilers)
def detect_cython_compiler(self, for_machine: MachineChoice) -> CythonCompiler:
"""Search for a cython compiler."""
compilers = self.lookup_binary_entry(for_machine, 'cython')
is_cross = self.is_cross_build(for_machine)
info = self.machines[for_machine]
if compilers is None:
# TODO support fallback
compilers = [self.default_cython[0]]
popen_exceptions: T.Dict[str, Exception] = {}
for comp in compilers:
try:
err = Popen_safe(comp + ['-V'])[2]
except OSError as e:
popen_exceptions[' '.join(comp + ['-V'])] = e
continue
version = search_version(err)
if 'Cython' in err:
comp_class = CythonCompiler
self.coredata.add_lang_args(comp_class.language, comp_class, for_machine, self)
return comp_class(comp, version, for_machine, info, is_cross=is_cross)
self._handle_exceptions(popen_exceptions, compilers)
def detect_vala_compiler(self, for_machine): def detect_vala_compiler(self, for_machine):
exelist = self.lookup_binary_entry(for_machine, 'vala') exelist = self.lookup_binary_entry(for_machine, 'vala')
is_cross = self.is_cross_build(for_machine) is_cross = self.is_cross_build(for_machine)
@ -2023,6 +2049,8 @@ class Environment:
comp = self.detect_fortran_compiler(for_machine) comp = self.detect_fortran_compiler(for_machine)
elif lang == 'swift': elif lang == 'swift':
comp = self.detect_swift_compiler(for_machine) comp = self.detect_swift_compiler(for_machine)
elif lang == 'cython':
comp = self.detect_cython_compiler(for_machine)
else: else:
comp = None comp = None
return comp return comp

Loading…
Cancel
Save