Skip to content

Commit

Permalink
boost: Better python module detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda authored and jpakkane committed Mar 27, 2020
1 parent 1bfd5e9 commit 4e52a0f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
34 changes: 33 additions & 1 deletion mesonbuild/dependencies/boost.py
Expand Up @@ -101,6 +101,11 @@ def __lt__(self, other: T.Any) -> bool:

@functools.total_ordering
class BoostLibraryFile():
# Python libraries are special because of the included
# minor version in the module name.
boost_python_libs = ['boost_python', 'boost_numpy']
reg_python_mod_split = re.compile(r'(boost_[a-zA-Z]+)([0-9]*)')

reg_abi_tag = re.compile(r'^s?g?y?d?p?n?$')
reg_ver_tag = re.compile(r'^[0-9_]+$')

Expand Down Expand Up @@ -218,6 +223,33 @@ def abitag(self) -> str:
def is_boost(self) -> bool:
return any([self.name.startswith(x) for x in ['libboost_', 'boost_']])

def is_python_lib(self) -> bool:
return any([self.mod_name.startswith(x) for x in BoostLibraryFile.boost_python_libs])

def mod_name_matches(self, mod_name: str) -> bool:
if self.mod_name == mod_name:
return True
if not self.is_python_lib():
return False

m_cur = BoostLibraryFile.reg_python_mod_split.match(self.mod_name)
m_arg = BoostLibraryFile.reg_python_mod_split.match(mod_name)

if not m_cur or not m_arg:
return False

if m_cur.group(1) != m_arg.group(1):
return False

cur_vers = m_cur.group(2)
arg_vers = m_arg.group(2)

# Always assume python 2 if nothing is specified
if not arg_vers:
arg_vers = '2'

return cur_vers.startswith(arg_vers)

def version_matches(self, version_lib: str) -> bool:
# If no version tag is present, assume that it fits
if not self.version_lib or not version_lib:
Expand Down Expand Up @@ -361,7 +393,7 @@ def run_check(self, inc_dirs: T.List[BoostIncludeDir], lib_dirs: T.List[Path]) -
for mod in modules:
found = False
for l in f_libs:
if l.mod_name == mod:
if l.mod_name_matches(mod):
selected_modules += [l]
found = True
break
Expand Down
18 changes: 2 additions & 16 deletions test cases/frameworks/1 boost/meson.build
Expand Up @@ -29,28 +29,14 @@ python3dep = python3.dependency(required: host_machine.system() == 'linux', embe

# compile python 2/3 modules only if we found a corresponding python version
if(python2dep.found() and host_machine.system() == 'linux' and not s)
if(dep.version().version_compare('>=1.67'))
# if we have a new version of boost, we need to construct the module name based
# on the installed version of python (and hope that they match the version boost
# was compiled against)
py2version_string = ''.join(python2dep.version().split('.'))
bpython2dep = dependency('boost', static: s, modules : ['python' + py2version_string], required: false, disabler: true)
else
# if we have an older version of boost, we need to use the old module names
bpython2dep = dependency('boost', static: s, modules : ['python'], required: false, disabler: true)
endif
bpython2dep = dependency('boost', static: s, modules : ['python'], required: false, disabler: true)
else
python2dep = disabler()
bpython2dep = disabler()
endif

if(python3dep.found() and host_machine.system() == 'linux' and not s)
if(dep.version().version_compare('>=1.67'))
py3version_string = ''.join(python3dep.version().split('.'))
bpython3dep = dependency('boost', static: s, modules : ['python' + py3version_string], required: false, disabler: true)
else
bpython3dep = dependency('boost', static: s, modules : ['python3'], required: false, disabler: true)
endif
bpython3dep = dependency('boost', static: s, modules : ['python3'], required: false, disabler: true)
else
python3dep = disabler()
bpython3dep = disabler()
Expand Down

0 comments on commit 4e52a0f

Please sign in to comment.