From 75871f612051f0b12ac54e82990aea928cec5b11 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 2 May 2021 18:51:07 -0700 Subject: [PATCH] Fix Issue #3933 debug output removed from SharedLibrary when SHLIBVERSION is specified. Also fixed shared library file naming, and symlink naming for applelink. Was libxyz.dylib.1.2.3 for example, is now libxyz.1.2.3.dylib --- CHANGES.txt | 5 +++++ SCons/Tool/applelink.py | 22 +++++++++++++++++++++- SCons/Tool/linkCommon/SharedLibrary.py | 6 +++++- test/LINK/SHLIBVERSIONFLAGS.py | 4 ++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d907867c13..782def8c15 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -24,6 +24,11 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER IMPLIBNOVERSIONSYMLINKS and LDMODULENOVERSIONSYMLINKS to True. - Added --experimental flag, to enable various experimental features/tools. You can specify 'all', 'none', or any combination of available experimental features. + - Fix Issue #3933 - Remove unguarded print of debug information in SharedLibrary logic when + SHLIBVERSION is specified. + - Fix versioned shared library naming for MacOS platform. (Previously was libxyz.dylib.1.2.3, + has been fixed to libxyz.1.2.3.dylib. Additionally the sonamed symlink had the same issue, + that is now resolved as well) From David H: - Fix Issue #3906 - `IMPLICIT_COMMAND_DEPENDENCIES` was not properly disabled when diff --git a/SCons/Tool/applelink.py b/SCons/Tool/applelink.py index 2cdbd50b24..b81d2b3cd3 100644 --- a/SCons/Tool/applelink.py +++ b/SCons/Tool/applelink.py @@ -36,7 +36,7 @@ # Even though the Mac is based on the GNU toolchain, it doesn't understand # the -rpath option, so we use the "link" tool instead of "gnulink". from SCons.Util import CLVar - +from SCons.Errors import UserError from . import link # User programmatically describes how SHLIBVERSION maps to values for compat/current. @@ -141,6 +141,24 @@ def _applelib_compatVersionFromSoVersion(source, target, env, for_signature): return "-Wl,-compatibility_version,%s" % version_string +def _applelib_soname(target, source, env, for_signature): + """ + Override default _soname() function from SCons.Tools.linkCommon.SharedLibrary. + Apple's file naming for versioned shared libraries puts the version string before + the shared library suffix (.dylib), instead of after. + """ + if "SONAME" in env: + # Now verify that SOVERSION is not also set as that is not allowed + if "SOVERSION" in env: + raise UserError( + "Ambiguous library .so naming, both SONAME: %s and SOVERSION: %s are defined. " + "Only one can be defined for a target library." + % (env["SONAME"], env["SOVERSION"]) + ) + return "$SONAME" + else: + return "$SHLIBPREFIX$_get_shlib_stem$_SHLIBSOVERSION${SHLIBSUFFIX}" + def generate(env): """Add Builders and construction variables for applelink to an @@ -178,6 +196,8 @@ def generate(env): env['__LDMODULEVERSIONFLAGS'] = '${__lib_either_version_flag(__env__,' \ '"LDMODULEVERSION","_APPLELINK_CURRENT_VERSION", "_LDMODULEVERSIONFLAGS")}' + env["_SHLIBSONAME"] = _applelib_soname + def exists(env): return env['PLATFORM'] == 'darwin' diff --git a/SCons/Tool/linkCommon/SharedLibrary.py b/SCons/Tool/linkCommon/SharedLibrary.py index 2a079bfdd1..6a12dd49ab 100644 --- a/SCons/Tool/linkCommon/SharedLibrary.py +++ b/SCons/Tool/linkCommon/SharedLibrary.py @@ -166,8 +166,12 @@ def _get_shlib_dir(target, source, env, for_signature: bool) -> str: Returns: the directory the library will be in (empty string if '.') """ + verbose = False + if target.dir and str(target.dir) != ".": - print("target.dir:%s" % target.dir) + if verbose: + print("_get_shlib_dir: target.dir:%s" % target.dir) + return "%s/" % str(target.dir) else: return "" diff --git a/test/LINK/SHLIBVERSIONFLAGS.py b/test/LINK/SHLIBVERSIONFLAGS.py index 783286260f..158e82a391 100644 --- a/test/LINK/SHLIBVERSIONFLAGS.py +++ b/test/LINK/SHLIBVERSIONFLAGS.py @@ -47,9 +47,9 @@ soname = 'libfoo.so.4' sonameVersionFlags = r".+ -h %s( .+)+" % soname elif 'applelink' in tool_list: - versionflags = r" 'libfoo.1.dylib'->'libfoo.1.2.3.dylib'" + versionflags = r".+ -Wl,-current_version,1.2.3( .+)+" soname = 'libfoo.4.dylib' - sonameVersionFlags = r" '%s'->'libfoo.1.2.3.dylib'(.+)+" % soname + sonameVersionFlags = r".+ -Wl,-compatibility_version,1.2.0(.+)+" else: test.skip_test('No testable linkers found, skipping the test\n')