Rob Managan avatar Rob Managan committed dc92e42

Treat the sym links as side effects instead of extra targets. This prevents Install from copying the links as full files. Still need to get Install to create the links, if possible. Still a test failure or two to clean up as well. Needs a new test as well.

Comments (0)

Files changed (2)

src/engine/SCons/Tool/__init__.py

 import sys
 import re
 import os
+import shutil
 
 import SCons.Builder
 import SCons.Errors
         version = env.subst('$SHLIBVERSION')
     except KeyError:
         version = None
-    libname = str(target[0])
-    if Verbose:
-        print "VersionShLib: libname = ",libname
+    libname = target[0].name
     platform = env.subst('$PLATFORM')
     shlib_suffix = env.subst('$SHLIBSUFFIX')
     shlink_flags = SCons.Util.CLVar(env.subst('$SHLINKFLAGS'))
+    if Verbose:
+        print "VersionShLib: libname      = ",libname
+        print "VersionShLib: platform     = ",platform
+        print "VersionShLib: shlib_suffix = ",shlib_suffix
 
     if version:
+        # set the shared lib link flags
         if platform == 'posix':
-            ilib_suffix = '.' + version
-            ilib_len = len(ilib_suffix)
+            suffix_re = re.escape(shlib_suffix + '.' + version)
             (major, age, revision) = version.split(".")
-            index = libname.find('.'+major,-ilib_len,-1)
-            soname = libname[0:index] + "." + major
+            soname = re.sub(suffix_re, shlib_suffix, libname) + '.' + major
             shlink_flags += [ '-Wl,-Bsymbolic', '-Wl,-soname=%s' % soname ]
             if Verbose:
-                print "ilib_suffix ",ilib_suffix,", soname ",soname,", shlink_flags ",shlink_flags
+                print " soname ",soname,", shlink_flags ",shlink_flags
         elif platform == 'cygwin':
             shlink_flags += [ '-Wl,-Bsymbolic',
                               '-Wl,--out-implib,${TARGET.base}.a' ]
             shlink_flags += [ '-current_version', '%s' % version,
                               '-compatibility_version', '%s' % version,
                               '-undefined', 'dynamic_lookup' ]
+        if Verbose:
+            print "VersionShLib: shlink_flags = ",shlink_flags
         envlink = env.Clone()
         envlink['SHLINKFLAGS'] = shlink_flags
     else:
     result = SCons.Defaults.ShLinkAction(target, source, envlink)
 
     if version:
+        # keep name with version in it
+        lib_ver = libname
         if platform == 'darwin':
             if version.count(".") != 2:
                 # We need a library name in libfoo.x.y.z.dylib form to proceed
                 raise ValueError
-            # regex to find version+.dylib in the target name
-            suffix_re = '[\\.0-9]*%s$' % re.escape(shlib_suffix)
-            # remove the version string from libname so we can make a symlink
-            lib_no_ver = re.sub(suffix_re, shlib_suffix, libname)
-            os.symlink(libname,lib_no_ver)
+            # create sym link of linkname -> lib_ver, linkname has no version number
+            suffix_re = re.escape('.' + version + shlib_suffix)
+            linkname = re.sub(suffix_re, shlib_suffix, libname)
+            if Verbose:
+                print "VersionShLib: linkname = ",linkname
+            os.symlink(lib_ver,linkname)
         elif platform == 'posix':
             if version.count(".") != 2:
                 # We need a library name in libfoo.so.x.y.z form to proceed
                 raise ValueError
-            suffix_re = '%s\\.[0-9\\.]*$' % re.escape(shlib_suffix)
+            suffix_re = re.escape(shlib_suffix + '.' + version)
+            # remove version number for linkname
+            linkname = re.sub(suffix_re, shlib_suffix, libname)
+            if Verbose:
+                print "VersionShLib: linkname = ",linkname
+            os.symlink(lib_ver, linkname)
             # For libfoo.so.x.y.z, links libfoo.so libfoo.so.x.y libfoo.so.x
-            major_name = shlib_suffix + "." + libname.split(".")[2]
-            minor_name = major_name + "." + libname.split(".")[3]
-            for linksuffix in [shlib_suffix, major_name, minor_name]:
-                linkname = re.sub(suffix_re, linksuffix, libname)
+            versionparts = version.split('.')
+            major_name = linkname + "." + versionparts[0]
+            minor_name = major_name + "." + versionparts[1]
+            for linkname in [major_name, minor_name]:
                 if Verbose:
-                    print "linksuffix ",linksuffix, ", linkname ",linkname, ", target ",str(target[0])
-                os.symlink(str(target[0]),linkname)
+                    print " linkname ",linkname, ", target ",libname
+                os.symlink(lib_ver,linkname)
     return False
 
 ShLibAction = SCons.Action.Action(VersionedSharedLibrary, "$SHLINKCOMSTR")

src/engine/SCons/Tool/link.py

     return '$CC'
 
 def shlib_emitter(target, source, env):
+    Verbose = False
     platform = env.subst('$PLATFORM')
     for tgt in target:
         tgt.attributes.shared = 1
         if version:
             if platform == 'posix':
                 versionparts = version.split('.')
-                name = str(target[0])
-                for ver in versionparts:
+                name = target[0].name
+                # generate library name with the version number
+                version_name = target[0].name + '.' + version
+                # change the name of the target to version_name
+                target[0].name = version_name
+                if Verbose:
+                    print "shlib_emitter: target is ", version_name
+                    print "shlib_emitter: side effect: ", name
+                # make name w/o version number a side effect (will be a sym link)
+                env.SideEffect(version_name, target[0])
+                env.Clean(target[0], version_name)
+                if Verbose:
+                    print "shlib_emitter: versionparts ",versionparts
+                for ver in versionparts[0:-1]:
                     name = name + '.' + ver
-                    target.insert(0, env.fs.File(name))
+                    if Verbose:
+                        print "shlib_emitter: side effect: ", name
+                    # make side effects of sym links with partial version number
+                    env.SideEffect(name, target[0])
+                    env.Clean(target[0], name)
             elif platform == 'darwin':
                 shlib_suffix = env.subst('$SHLIBSUFFIX')
-                name = str(target[0])
-                name = re.sub(shlib_suffix+"$",'.'+version+shlib_suffix,name)
-                target.insert(0, env.fs.File(name))
+                name = target[0].name
+                # generate library name with the version number
+                suffix_re = re.escape(shlib_suffix)
+                version_name = re.sub(suffix_re, '.' + version + shlib_suffix, name)
+                # change the name of the target to version_name
+                target[0].name = version_name
+                if Verbose:
+                    print "shlib_emitter: target is ", version_name
+                    print "shlib_emitter: side effect: ", name
+                # make name w/o version number a side effect (will be a sym link)
+                env.SideEffect(version_name, target[0])
+                env.Clean(target[0], version_name)
     except KeyError:
         version = None
     return (target, source)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.