[csw-devel] SF.net SVN: gar:[11209] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Sun Oct 10 22:31:00 CEST 2010
Revision: 11209
http://gar.svn.sourceforge.net/gar/?rev=11209&view=rev
Author: wahwah
Date: 2010-10-10 20:31:00 +0000 (Sun, 10 Oct 2010)
Log Message:
-----------
mGAR v2: Added a check for packages with shared libraries. The message still needs some work. Here's the original discussion: http://lists.opencsw.org/pipermail/maintainers/2010-September/012752.html
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/package_checks.py
csw/mgar/gar/v2/lib/python/package_checks_test.py
Added Paths:
-----------
csw/mgar/gar/v2/lib/python/sharedlib_utils.py
csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py
Modified: csw/mgar/gar/v2/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks.py 2010-10-10 00:51:08 UTC (rev 11208)
+++ csw/mgar/gar/v2/lib/python/package_checks.py 2010-10-10 20:31:00 UTC (rev 11209)
@@ -21,6 +21,7 @@
import textwrap
import dependency_checks as depchecks
import configuration as c
+import sharedlib_utils as su
from Cheetah import Template
PATHS_ALLOWED_ONLY_IN = {
@@ -737,7 +738,7 @@
"or is not allowed for other reasons." % pkgname)
-def CheckLinkingAgainstSunX11(pkg_data, error_mgr, logger, messenger):
+def GetSharedLibs(pkg_data):
# Finding all shared libraries
shared_libs = []
for metadata in pkg_data["files_metadata"]:
@@ -745,7 +746,11 @@
# TODO: Find out where mime_type is missing and why
if "sharedlib" in metadata["mime_type"]:
shared_libs.append(metadata["path"])
- shared_libs = set(shared_libs)
+ return shared_libs
+
+
+def CheckLinkingAgainstSunX11(pkg_data, error_mgr, logger, messenger):
+ shared_libs = set(GetSharedLibs(pkg_data))
for binary_info in pkg_data["binaries_dump_info"]:
for soname in binary_info["needed sonames"]:
if (binary_info["path"] in shared_libs
@@ -996,3 +1001,30 @@
file_metadata["path"],
pkginfo_arch,
machine["type"]))
+
+
+def CheckSharedLibraryNamingPolicy(pkg_data, error_mgr, logger, messenger):
+ placement_re = re.compile("/opt/csw/lib")
+ pkgname = pkg_data["basic_stats"]["pkgname"]
+ shared_libs = set(GetSharedLibs(pkg_data))
+ for binary_info in pkg_data["binaries_dump_info"]:
+ if binary_info["path"] in shared_libs:
+ if su.IsLibraryLinkable(binary_info["path"]):
+ # It is a shared library and other projects might link to it.
+ if "soname" in binary_info and binary_info["soname"]:
+ soname = binary_info["soname"]
+ else:
+ soname = os.path.split(binary_info["path"])[1]
+ tmp = su.MakePackageNameBySoname(soname)
+ policy_pkgname_list, policy_catalogname_list = tmp
+ if pkgname not in policy_pkgname_list:
+ error_mgr.ReportError(
+ "shared-lib-wrong-pkgname",
+ "file=%s pkgname=%s expected=%s"
+ % (binary_info["path"], pkgname, policy_pkgname_list))
+ messenger.OneTimeMessage(
+ soname,
+ "Shared libraries that other software might link "
+ "to, need to be separated out into own packages. "
+ "In this case, the suggested package names are %s."
+ % policy_pkgname_list)
Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py 2010-10-10 00:51:08 UTC (rev 11208)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py 2010-10-10 20:31:00 UTC (rev 11209)
@@ -1314,5 +1314,27 @@
'file=opt/csw/lib/sparcv9/libneon.so.26.0.4 pkginfo-says=i386 actual-binary=sparc')
+class TestCheckSharedLibraryNamingPolicy(CheckpkgUnitTestHelper, unittest.TestCase):
+ FUNCTION_NAME = 'CheckSharedLibraryNamingPolicy'
+ def CheckpkgTest(self):
+ self.pkg_data = neon_stats[0]
+ self.error_mgr_mock.ReportError(
+ 'shared-lib-wrong-pkgname',
+ "file=opt/csw/lib/libneon.so.26.0.4 pkgname=CSWneon "
+ "expected=['CSWlibneon26', 'CSWlibneon-26']")
+ self.error_mgr_mock.ReportError(
+ 'shared-lib-wrong-pkgname',
+ "file=opt/csw/lib/libneon.so.27.2.0 pkgname=CSWneon "
+ "expected=['CSWlibneon27', 'CSWlibneon-27']")
+ self.error_mgr_mock.ReportError(
+ 'shared-lib-wrong-pkgname',
+ "file=opt/csw/lib/sparcv9/libneon.so.26.0.4 pkgname=CSWneon "
+ "expected=['CSWlibneon26', 'CSWlibneon-26']")
+ self.error_mgr_mock.ReportError(
+ 'shared-lib-wrong-pkgname',
+ "file=opt/csw/lib/sparcv9/libneon.so.27.2.0 pkgname=CSWneon "
+ "expected=['CSWlibneon27', 'CSWlibneon-27']")
+
+
if __name__ == '__main__':
unittest.main()
Added: csw/mgar/gar/v2/lib/python/sharedlib_utils.py
===================================================================
--- csw/mgar/gar/v2/lib/python/sharedlib_utils.py (rev 0)
+++ csw/mgar/gar/v2/lib/python/sharedlib_utils.py 2010-10-10 20:31:00 UTC (rev 11209)
@@ -0,0 +1,25 @@
+import re
+import os.path
+
+def IsLibraryLinkable(file_path):
+ linkable_re = re.compile(r"^opt/csw(/[\w\.]+)*/lib(/[\w\+]+)?$")
+ file_dir, file_basename = os.path.split(file_path)
+ return bool(linkable_re.match(file_dir))
+
+def MakePackageNameBySoname(soname):
+ """Find the package name based on the soname.
+
+ Returns a pair of pkgname, catalogname.
+ """
+ soname_re = re.compile(r"(?P<basename>[\w-]+)\.so\.(?P<version>\d+)(\..*)?$")
+ m = soname_re.match(soname)
+ keywords = m.groupdict()
+ pkgname_list = [
+ "CSW%(basename)s%(version)s" % keywords,
+ "CSW%(basename)s-%(version)s" % keywords,
+ ]
+ catalogname_list = [
+ "%(basename)s%(version)s" % keywords,
+ "%(basename)s-%(version)s" % keywords,
+ ]
+ return pkgname_list, catalogname_list
Added: csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py (rev 0)
+++ csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py 2010-10-10 20:31:00 UTC (rev 11209)
@@ -0,0 +1,62 @@
+#!opt/csw/bin/python2.6
+# $Id$
+
+import re
+import unittest
+import mox
+import sharedlib_utils as su
+
+class UtilitiesUnitTest(unittest.TestCase):
+
+ def testIsLibraryLinkableTrue(self):
+ p = "opt/csw/lib/libfoo.so.0.2"
+ self.assertTrue(su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableNeonTrue(self):
+ p = "opt/csw/lib/libneon.so.26.0.4"
+ self.assertTrue(su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableSparc(self):
+ p = "opt/csw/lib/sparcv9/libfoo.so.0.2"
+ self.assertEqual(True, su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableSparcPlusVis(self):
+ p = "opt/csw/lib/sparcv9+vis/libfoo.so.0.2"
+ self.assertEqual(True, su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableAmd64(self):
+ p = "opt/csw/lib/amd64/libfoo.so.0.2"
+ self.assertTrue(su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkablePrefix(self):
+ p = "opt/csw/customprefix/lib/libfoo.so.0.2"
+ self.assertTrue(su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableLibexecFalse(self):
+ p = "opt/csw/libexec/bar"
+ self.assertEqual(False, su.IsLibraryLinkable(p))
+
+ def testIsLibraryLinkableFalse(self):
+ p = "opt/csw/share/bar"
+ self.assertEqual(False, su.IsLibraryLinkable(p))
+
+ def testMakePackageNameBySonameSimple(self):
+ soname = "libfoo.so.0"
+ expected = (
+ ["CSWlibfoo0", "CSWlibfoo-0"],
+ ["libfoo0", "libfoo-0"],
+ )
+ self.assertEqual(expected, su.MakePackageNameBySoname(soname))
+
+ def testMakePackageNameBySonameApr(self):
+ soname = "libapr-1.so.0"
+ expected = (
+ ['CSWlibapr-10', 'CSWlibapr-1-0'],
+ ['libapr-10', 'libapr-1-0']
+ )
+ self.assertEqual(expected,
+ su.MakePackageNameBySoname(soname))
+
+
+if __name__ == '__main__':
+ unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list