diff --git a/autospec/config.py b/autospec/config.py index bf62fc9..0e32d65 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -115,7 +115,9 @@ config_options = { "security_sensitive": "set flags for security-sensitive builds", "so_to_lib": "add .so files to the lib package instead of dev", "autoupdate": "this package is trusted enough to automatically update " - "(used by other tools)"} + "(used by other tools)", + "compat": "this package is a library compatability package and only " + "ships versioned library files"} # simple_pattern_pkgconfig patterns # contains patterns for parsing build.log for missing dependencies diff --git a/autospec/files.py b/autospec/files.py index b833f15..a956952 100644 --- a/autospec/files.py +++ b/autospec/files.py @@ -62,6 +62,29 @@ class FileManager(object): print(" New %files content found") self.newfiles_printed = True + def compat_exclude(self, filename): + """ + Exclude non-library files if the package is for compatability. + """ + if not config.config_opts.get("compat"): + return False + + patterns = [ + re.compile(r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.so\."), + re.compile(r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.so\."), + re.compile(r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.so\."), + re.compile(r"^/usr/lib64/lib(asm|dw|elf)-[0-9.]+\.so"), + re.compile(r"^/usr/lib32/lib(asm|dw|elf)-[0-9.]+\.so"), + re.compile(r"^/usr/lib64/haswell/[a-zA-Z0-9\.\_\-\+]*\.so\.")] + + exclude = True + for pat in patterns: + if pat.search(filename): + exclude = False + break + + return exclude + def file_pat_match(self, filename, pattern, package, replacement="", prefix=""): """ Search for pattern in filename, if pattern matches push package file. @@ -75,7 +98,7 @@ class FileManager(object): pat = re.compile(pattern) match = pat.search(filename) if match: - if filename in self.excludes: + if filename in self.excludes or self.compat_exclude(filename): self.push_package_file("%exclude " + filename, package) return True diff --git a/tests/test_files.py b/tests/test_files.py index 7a2071b..5f75fac 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -1,4 +1,5 @@ import unittest +import config import files import tempfile import os @@ -39,6 +40,28 @@ class TestFiles(unittest.TestCase): self.assertEqual(self.fm.packages['dev'], set(['test-fn'])) self.assertTrue(self.fm.newfiles_printed) + def test_compat_exclude_keep_file(self): + """ + Test compat_exclude with a file that shouldn't be excluded. + """ + config.config_opts['compat'] = True + self.assertFalse(self.fm.compat_exclude('/usr/lib64/libfoo.so.1')) + + def test_compat_exclude_exclude_file(self): + """ + Test compat_exclude with a file that should be excluded. + """ + config.config_opts['compat'] = True + self.assertTrue(self.fm.compat_exclude('/usr/lib64/libfoo.so')) + + def test_compat_exclude_not_compat_mode(self): + """ + Test compat_exclude with a file that should be excluded but isn't + because the package isn't being run in compat mode. + """ + config.config_opts['compat'] = False + self.assertFalse(self.fm.compat_exclude('/usr/lib64/libfoo.so')) + def test_file_pat_match(self): """ Test file_pat_match with good match and no replacement or prefix