diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-08-25 04:09:54 +0530 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-08-25 09:32:02 +0300 |
commit | 274c852e857b85c8a8c1b9a5ba22c6f9802e59cc (patch) | |
tree | d7cd228b4566c934a03192a38cf2500f96fbc981 | |
parent | 07a2ec39fb947e6946545ed280e85c2ac8255728 (diff) |
cerbero: Factor out shlib search code
We want to use this for libtool (.la) file generation
-rw-r--r-- | cerbero/build/filesprovider.py | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/cerbero/build/filesprovider.py b/cerbero/build/filesprovider.py index f8f87dea..e173b56b 100644 --- a/cerbero/build/filesprovider.py +++ b/cerbero/build/filesprovider.py @@ -25,6 +25,18 @@ from cerbero.config import Platform from cerbero.utils import shell from cerbero.utils import messages as m +def find_shlib_regex(libname, prefix, libdir, ext, regex): + # Use globbing to find all files that look like they might match + # this library to narrow down our exact search + fpath = os.path.join(libdir, '*{0}*{1}*'.format(libname, ext)) + found = glob.glob(os.path.join(prefix, fpath)) + # Find which of those actually match via an exact regex + # Ideally Python should provide a function for regex file 'globbing' + for each in found: + fname = os.path.basename(each) + if re.match(regex.format(re.escape(libname)), fname): + yield os.path.join(libdir, fname) + def flatten_files_list(all_files): """ Some files search functions return a list of lists instead of a flat list @@ -55,12 +67,14 @@ class FilesProvider(object): LANG_CAT = 'lang' TYPELIB_CAT = 'typelibs' # Usually DLLs have 0 or 1 version components (just the major version), but - # some packages like Nettle add 2, so we check for upto 2. - _DLL_REGEX = r'^(lib)?{}(-[0-9]+){{0,2}}\.dll$' - # UNIX shared libraries can have between 0 and 3 version components - # (major, minor, micro) - _SO_REGEX = r'^lib{}\.so(\.[0-9]+){{0,3}}$' - _DYLIB_REGEX = r'^lib{}(\.[0-9]+){{0,3}}\.dylib$' + # some packages like Nettle add 2, so we check for upto 2. We don't use + # {m,n} here because we want to capture all the matches. + _DLL_REGEX = r'^(lib)?{}(-[0-9]+)?(-[0-9]+)?\.dll$' + # UNIX shared libraries can have between 0 and 3 version components: + # major, minor, micro. We don't use {m,n} here because we want to capture + # all the matches. + _SO_REGEX = r'^lib{}\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$' + _DYLIB_REGEX = r'^lib{}(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?\.dylib$' # Extension Glob Legend: # bext = binary extension @@ -71,15 +85,15 @@ class FilesProvider(object): # smext = static module (plugin) extension # pext = python module extension (.pyd on Windows) EXTENSIONS = { - Platform.WINDOWS: {'bext': '.exe', 'sext': _DLL_REGEX, 'sdir': 'bin', + Platform.WINDOWS: {'bext': '.exe', 'sregex': _DLL_REGEX, 'sdir': 'bin', 'mext': '.dll', 'smext': '.a', 'pext': '.pyd', 'srext': '.dll'}, - Platform.LINUX: {'bext': '', 'sext': _SO_REGEX, 'sdir': 'lib', + Platform.LINUX: {'bext': '', 'sregex': _SO_REGEX, 'sdir': 'lib', 'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.so'}, - Platform.ANDROID: {'bext': '', 'sext': _SO_REGEX, 'sdir': 'lib', + Platform.ANDROID: {'bext': '', 'sregex': _SO_REGEX, 'sdir': 'lib', 'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.so'}, - Platform.DARWIN: {'bext': '', 'sext': _DYLIB_REGEX, 'sdir': 'lib', + Platform.DARWIN: {'bext': '', 'sregex': _DYLIB_REGEX, 'sdir': 'lib', 'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'}, - Platform.IOS: {'bext': '', 'sext': _DYLIB_REGEX, 'sdir': 'lib', + Platform.IOS: {'bext': '', 'sregex': _DYLIB_REGEX, 'sdir': 'lib', 'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'}} def __init__(self, config): @@ -233,23 +247,14 @@ class FilesProvider(object): guess (sometimes incorrectly) based on the dll filename. ''' libdir = self.extensions['sdir'] - libregex = self.extensions['sext'] libext = self.extensions['srext'] + libregex = self.extensions['sregex'] libsmatch = {} notfound = [] for f in files: - # Use globbing to find all files that look like they might match - # this library to narrow down our exact search - fpath = os.path.join(libdir, '*{0}*{1}*'.format(f[3:], libext)) - found = glob.glob(os.path.join(self.config.prefix, fpath)) - # Find which of those actually match via an exact regex - # Ideally Python should provide a function for regex file 'globbing' - libsmatch[f] = [] - for each in found: - fname = os.path.basename(each) - if re.match(libregex.format(re.escape(f[3:])), fname): - libsmatch[f].append(os.path.join(libdir, fname)) + libsmatch[f] = list(find_shlib_regex(f[3:], self.config.prefix, + libdir, libext, libregex)) if not libsmatch[f]: notfound.append(f) |