[csw-devel] SF.net SVN: gar:[17348] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Fri Mar 9 23:30:12 CET 2012


Revision: 17348
          http://gar.svn.sourceforge.net/gar/?rev=17348&view=rev
Author:   wahwah
Date:     2012-03-09 22:30:12 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
checkpkg: Support libraries in subdirs

This is effectively an amendment to the shared libraries naming
policy[1].  It does not affect packages which put libraries into
/opt/csw/lib.  Packages which put libraries into directories with
additional prefixes, e.g. /opt/csw/bdb48/lib, are affected. The main
issue is that there can be libraries with the same sonames put into two
different directories.  Each library should be put into a separate
package, but since both libraries have identical sonames, the suggested
package names would also be identical, which is an error. Therefore, the
package names have to vary according to the prefix under which libraries
are put.

After this change, checkpkg will suggest adding the prefix at the end of
the package name. For example, a library under
/opt/csw/foo/lib/libbar.so.1 should be in a package named
CSWlibbar1-foo. The immediate use of this change will be for the C++
libraries from Boost. There will be two sets of these libraries, one
built with Sun Studio, put into /opt/csw/lib and one built with GCC, put
into /opt/csw/gxx/lib.

[1] http://wiki.opencsw.org/shared-libraries

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/package_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py
    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	2012-03-09 21:36:35 UTC (rev 17347)
+++ csw/mgar/gar/v2/lib/python/package_checks.py	2012-03-09 22:30:12 UTC (rev 17348)
@@ -1033,11 +1033,14 @@
         else:
           soname = os.path.split(binary_info["path"])[1]
         linkable_shared_libs.append((soname, binary_info))
+      else:
+        logging.debug("%r is not linkable", binary_info["path"])
   logging.debug("CheckSharedLibraryNamingPolicy(): "
                 "linkable shared libs of %s: %s"
                 % (pkgname, linkable_shared_libs))
   for soname, binary_info in linkable_shared_libs:
-    tmp = su.MakePackageNameBySoname(soname)
+    path = os.path.split(binary_info["path"])[0]
+    tmp = su.MakePackageNameBySoname(soname, path)
     policy_pkgname_list, policy_catalogname_list = tmp
     if pkgname not in policy_pkgname_list:
       error_mgr.ReportError(

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2012-03-09 21:36:35 UTC (rev 17347)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2012-03-09 22:30:12 UTC (rev 17348)
@@ -635,7 +635,14 @@
         'depends': (('CSWlibfoo', None),),
         'isalist': (),
         'pkgmap': [],
-        }
+        'files_metadata': [
+                    {'endian': 'Little endian',
+                     'machine_id': 3,
+                     'mime_type': 'application/x-sharedlib; charset=binary',
+                     'mime_type_by_hachoir': u'application/x-executable',
+                     'path': 'opt/csw/bin/bar/libfoo.so.1'},
+        ],
+  }
   CSWlibfoo_DATA = {
         'basic_stats': {'catalogname': 'libfoo',
                         'pkgname': 'CSWlibfoo',
@@ -1341,10 +1348,40 @@
 
 class TestCheckSharedLibraryNamingPolicy(CheckTestHelper, unittest.TestCase):
   FUNCTION_NAME = 'CheckSharedLibraryNamingPolicy'
-  def testGood(self):
+  def testBad(self):
     self.pkg_data = bdb48_stats[0]
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/libdb-4.8.so soname=libdb-4.8.so '
+        'pkgname=CSWbdb48 expected=CSWlibdb4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/libdb_cxx-4.8.so soname=libdb_cxx-4.8.so '
+        'pkgname=CSWbdb48 expected=CSWlibdb-cxx4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/libdb_java-4.8.so '
+        'soname=libdb_java-4.8.so pkgname=CSWbdb48 '
+        'expected=CSWlibdb-java4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/libdb_tcl-4.8.so soname=libdb_tcl-4.8.so '
+        'pkgname=CSWbdb48 expected=CSWlibdb-tcl4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/sparcv9/libdb-4.8.so soname=libdb-4.8.so '
+        'pkgname=CSWbdb48 expected=CSWlibdb4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+        'shared-lib-pkgname-mismatch',
+        'file=opt/csw/bdb48/lib/sparcv9/libdb_cxx-4.8.so '
+        'soname=libdb_cxx-4.8.so pkgname=CSWbdb48 '
+        'expected=CSWlibdb-cxx4-8-bdb48')
+    self.error_mgr_mock.ReportError(
+          'shared-lib-pkgname-mismatch',
+          'file=opt/csw/bdb48/lib/sparcv9/libdb_java-4.8.so '
+          'soname=libdb_java-4.8.so pkgname=CSWbdb48 '
+          'expected=CSWlibdb-java4-8-bdb48')
 
-
 class TestCheckSharedLibraryPkgDoesNotHaveTheSoFile(CheckTestHelper,
                                                     unittest.TestCase):
   FUNCTION_NAME = 'CheckSharedLibraryPkgDoesNotHaveTheSoFile'

Modified: csw/mgar/gar/v2/lib/python/sharedlib_utils.py
===================================================================
--- csw/mgar/gar/v2/lib/python/sharedlib_utils.py	2012-03-09 21:36:35 UTC (rev 17347)
+++ csw/mgar/gar/v2/lib/python/sharedlib_utils.py	2012-03-09 22:30:12 UTC (rev 17348)
@@ -1,4 +1,5 @@
 # $Id$
+# coding=utf-8
 
 import copy
 import re
@@ -46,20 +47,26 @@
   pass
 
 
-def IsLibraryLinkable(file_path):
+def ParseLibPath(directory):
   arch_subdirs = (SPARCV8_PATHS + SPARCV8PLUS_PATHS + SPARCV9_PATHS
                   + INTEL_386_PATHS + AMD64_PATHS)
   # Need to escape the plus signs because of the regex usage below.
   arch_subdirs = [x.replace(r"+", r"\+") for x in arch_subdirs]
-  linkable_re = re.compile(r"^opt/csw(/[a-z-_]+)?/lib(/(%s))?$"
+  linkable_re = re.compile(r"^/?opt/csw"
+                           r"(/(?P<prefix>[a-z0-9-_]+))?"
+                           r"/lib(/(%s))?$"
                            % "|".join(arch_subdirs))
+  m = linkable_re.match(directory)
+  return m.groupdict() if m else False
+
+def IsLibraryLinkable(file_path):
   blacklist = [
       # If it has two lib components, it's a private lib.
       re.compile(r"^opt/csw/.*lib.*lib.*"),
       re.compile(r"^opt/csw/share.*lib.*"),
   ]
   file_dir, file_basename = os.path.split(file_path)
-  if linkable_re.match(file_dir):
+  if ParseLibPath(file_dir):
     for regex in blacklist:
       if regex.match(file_dir):
         return False
@@ -106,7 +113,15 @@
   return c.join(parts).lower()
 
 
-def MakePackageNameBySoname(soname):
+def ExtractPrefix(path):
+  parsed = ParseLibPath(path)
+  if parsed:
+    return parsed["prefix"]
+  else:
+    return parsed
+
+
+def MakePackageNameBySoname(soname, path=None):
   """Find the package name based on the soname.
 
   Returns a pair of pkgname, catalogname.
@@ -149,14 +164,20 @@
     else:
       keywords_pkgname[key] = ""
       keywords_catalogname[key] = ""
-  pkgname_list = []
+  if path:
+    prefix = ExtractPrefix(path)
+  else:
+    prefix = None
   keywords_pkgname = AddSeparator(keywords_pkgname, "-")
-  pkgname_list.append(
-      "CSW%(basename)s%(sep)s%(version)s" % keywords_pkgname)
+  pkgname = "CSW%(basename)s%(sep)s%(version)s" % keywords_pkgname
+  if prefix:
+    pkgname += "-%s" % prefix
+  pkgname_list = [pkgname]
   keywords_catalogname = AddSeparator(keywords_catalogname, "_")
-  catalogname_list = [
-      "%(basename)s%(sep)s%(version)s" % keywords_catalogname,
-  ]
+  catalogname = "%(basename)s%(sep)s%(version)s" % keywords_catalogname
+  if prefix:
+    catalogname += "_%s" % prefix
+  catalogname_list = [catalogname]
   return pkgname_list, catalogname_list
 
 

Modified: csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py	2012-03-09 21:36:35 UTC (rev 17347)
+++ csw/mgar/gar/v2/lib/python/sharedlib_utils_test.py	2012-03-09 22:30:12 UTC (rev 17348)
@@ -64,7 +64,11 @@
       "opt/csw/boost-gcc/lib"
       "/libboost_wserialization.so.1.44.0"))
 
+  def testIsLibraryLinkableWithPrefix(self):
+    self.assertTrue(
+        su.IsLibraryLinkable("opt/csw/bdb48/lib/libdb-4.8.so"))
 
+
 class MakePackageNameBySonameUnitTest(unittest.TestCase):
 
   def testMakePackageNameBySonameSimple(self):
@@ -173,7 +177,37 @@
     self.assertEqual(expected,
                      su.MakePackageNameBySoname(soname))
 
+  def testMakePackageNameBySonameWithPath(self):
+    soname = "libfoo.so.0"
+    path = "/opt/csw/gxx/lib"
+    expected = (
+        ["CSWlibfoo0-gxx"],
+        ["libfoo0-gxx"],
+    )
+    self.assertEqual(expected, su.MakePackageNameBySoname(soname, path))
 
+  def testMakePackageNameBySonameWithPathSparcv9(self):
+    soname = "libfoo.so.0"
+    path = "/opt/csw/gxx/lib/sparcv9"
+    expected = (
+        ["CSWlibfoo0-gxx"],
+        ["libfoo0-gxx"],
+    )
+    self.assertEqual(expected, su.MakePackageNameBySoname(soname, path))
+
+
+class ParseLibPathTest(unittest.TestCase):
+
+  def testSimple(self):
+    self.assertEquals({"prefix": None}, su.ParseLibPath("/opt/csw/lib"))
+
+  def testPrefix(self):
+    self.assertEquals({"prefix": "gxx"}, su.ParseLibPath("/opt/csw/gxx/lib"))
+
+  def testWithArch(self):
+    self.assertEquals({"prefix": "gxx"}, su.ParseLibPath("/opt/csw/gxx/lib/amd64"))
+
+
 class SanitizationUnitTest(unittest.TestCase):
 
   def testSanitizeWithChar(self):
@@ -201,5 +235,17 @@
     self.assertTrue("sparcv8plus+vis" in su.GetIsalist("sparc"))
 
 
+class ExtractPrefixTest(unittest.TestCase):
+
+  def testNoPrefix(self):
+    self.assertEquals(None, su.ExtractPrefix("/opt/csw/lib"))
+
+  def testSimple(self):
+    self.assertEquals("gxx", su.ExtractPrefix("/opt/csw/gxx/lib"))
+
+  def testWithArch(self):
+    self.assertEquals("gxx", su.ExtractPrefix("/opt/csw/gxx/lib/sparcv9"))
+
+
 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