From f4a055902da6d647d31f49ad40a1a422e2c335ac Mon Sep 17 00:00:00 2001 From: William Deegan Date: Wed, 5 Dec 2018 15:32:10 -0500 Subject: initial pass at versioned library logic. WIP --- src/engine/SCons/Tool/applelink.py | 48 +++++- src/engine/SCons/Tool/applelink.xml | 315 ++++++++++++++++++++---------------- 2 files changed, 218 insertions(+), 145 deletions(-) diff --git a/src/engine/SCons/Tool/applelink.py b/src/engine/SCons/Tool/applelink.py index afe766e..c332fc2 100644 --- a/src/engine/SCons/Tool/applelink.py +++ b/src/engine/SCons/Tool/applelink.py @@ -40,6 +40,12 @@ import SCons.Util from . import link +class AppleLinkInvalidCurrentVersionException(Exception): + pass + +class AppleLinkInvalidCompatibityVersionException(Exception): + pass + def _applelib_versioned_lib_suffix(env, suffix, version): """For suffix='.dylib' and version='0.1.2' it returns '.0.1.2.dylib'""" @@ -74,6 +80,33 @@ def _applelib_versioned_shlib_soname(env, libnode, version, prefix, suffix): # User programmatically describes how SHLIBVERSION maps to values for compat/current. +_applelib_max_version_values = (65535, 255, 255) +def _applelib_check_valid_version(version_string): + """ + Check that the version # is valid. + X[.Y[.Z]] + where X 0-65535 + where Y either not specified or 0-255 + where Z either not specified or 0-255 + :param version_string: + :return: + """ + parts = version_string.split('.') + if len(parts) > 3: + return False, "Version string has too many periods" + if len(parts) <= 0: + return False, "Version string unspecified" + + for (i, p) in enumerate(parts): + try: + p_i = int(p) + except ValueError as e: + return False, "Version component %s (from %s) is not a number"%(p, version_string) + if p_i < 0 or p_i > _applelib_max_version_values[i]: + return False, "Version component %s (from %s) is not valid value should be between 0 and %d"%(p, version_string, _applelib_max_version_values[i]) + + return True, "" + def _applelib_currentVersionFromSoVersion(source, target, env, for_signature): """ @@ -87,9 +120,13 @@ def _applelib_currentVersionFromSoVersion(source, target, env, for_signature): else: return "" - print("Versino_String:%s"%version_string) + print("Version_String:%s"%version_string) version_string = ".".join(version_string.split('.')[:3]) + valid, reason = _applelib_check_valid_version(version_string) + if not valid: + raise AppleLinkInvalidCurrentVersionException(reason) + return "-Wl,-current_version,%s" % version_string @@ -105,6 +142,10 @@ def _applelib_compatVersionFromSoVersion(source, target, env, for_signature): else: return "" + valid, reason = _applelib_check_valid_version(version_string) + if not valid: + raise AppleLinkInvalidCompatibityVersionException(reason) + return "-Wl,-compatibility_version,%s" % version_string @@ -122,17 +163,12 @@ def generate(env): env['SHLINKCOM'] = env['SHLINKCOM'] + ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS' - # TODO: Work needed to generate versioned shared libraries - # Leaving this commented out, and also going to disable versioned library checking for now # see: http://docstore.mik.ua/orelly/unix3/mac/ch05_04.htm for proper naming link._setup_versioned_lib_variables(env, tool = 'applelink')#, use_soname = use_soname) env['LINKCALLBACKS'] = link._versioned_lib_callbacks() - - # 'VersionedShLibSuffix': _versioned_lib_suffix, env['LINKCALLBACKS']['VersionedShLibSuffix'] = _applelib_versioned_lib_suffix env['LINKCALLBACKS']['VersionedShLibSoname'] = _applelib_versioned_shlib_soname - env['_APPLELINK_CURRENT_VERSION'] = _applelib_currentVersionFromSoVersion env['_APPLELINK_COMPATIBILITY_VERSION'] = _applelib_compatVersionFromSoVersion env['_SHLIBVERSIONFLAGS'] = '$_APPLELINK_CURRENT_VERSION $_APPLELINK_COMPATIBILITY_VERSION ' diff --git a/src/engine/SCons/Tool/applelink.xml b/src/engine/SCons/Tool/applelink.xml index 5e5571f..c7c6d5b 100644 --- a/src/engine/SCons/Tool/applelink.xml +++ b/src/engine/SCons/Tool/applelink.xml @@ -7,149 +7,186 @@ See its __doc__ string for a discussion of the format. --> -%scons; - -%builders-mod; - -%functions-mod; - -%tools-mod; - -%variables-mod; -]> + + %scons; + + %builders-mod; + + %functions-mod; + + %tools-mod; + + %variables-mod; + ]> - - - -Sets construction variables for the Apple linker -(similar to the GNU linker). - - - -FRAMEWORKPATHPREFIX -_FRAMEWORKPATH -_FRAMEWORKS -LINKCOM -SHLINKFLAGS -SHLINKCOM -LDMODULEPREFIX -LDMODULESUFFIX -LDMODULEFLAGS -LDMODULECOM - - -FRAMEWORKSFLAGS - - - -"> - - -On Mac OS X with gcc, -general user-supplied frameworks options to be added at -the end of a command -line building a loadable module. -(This has been largely superseded by -the &cv-link-FRAMEWORKPATH;, &cv-link-FRAMEWORKPATHPREFIX;, -&cv-link-FRAMEWORKPREFIX; and &cv-link-FRAMEWORKS; variables -described above.) - - - - - - - -On Mac OS X with gcc, a list of the framework names to be linked into a -program or shared library or bundle. -The default value is the empty list. -For example: - - - - env.AppendUnique(FRAMEWORKS=Split('System Cocoa SystemConfiguration')) - - - - - - - - -On Mac OS X with gcc, -the prefix to be used for linking in frameworks -(see &cv-link-FRAMEWORKS;). -The default value is -. - - - - - - - -On Mac OS X with gcc, -an automatically-generated construction variable -containing the linker command-line options -for linking with FRAMEWORKS. - - - - - - - -On Mac OS X with gcc, -a list containing the paths to search for frameworks. -Used by the compiler to find framework-style includes like -#include <Fmwk/Header.h>. -Used by the linker to find user-specified frameworks when linking (see -&cv-link-FRAMEWORKS;). -For example: - - - - env.AppendUnique(FRAMEWORKPATH='#myframeworkdir') - - - -will add - - - - ... -Fmyframeworkdir - - - -to the compiler and linker command lines. - - - - - - - -On Mac OS X with gcc, the prefix to be used for the FRAMEWORKPATH entries. -(see &cv-link-FRAMEWORKPATH;). -The default value is -. - - - - - - - -On Mac OS X with gcc, an automatically-generated construction variable -containing the linker command-line options corresponding to -&cv-link-FRAMEWORKPATH;. - - - + + + + Sets construction variables for the Apple linker + (similar to the GNU linker). + + + + FRAMEWORKPATHPREFIX + _FRAMEWORKPATH + _FRAMEWORKS + LINKCOM + SHLINKFLAGS + SHLINKCOM + LDMODULEPREFIX + LDMODULESUFFIX + LDMODULEFLAGS + LDMODULECOM + APPLELINK_CURRENT_VERSION + APPLELINK_COMPATIBILITY_VERSION + + + FRAMEWORKSFLAGS + + + + + + + + On Mac OS X this is used to set the linker flag: + + -compatibility_version + + + The value is specified as X[.Y[.Z]] where X is between 1 and 65535, Y can be omitted or between 1 and + 255, Z can be omitted or between 1 and 255. This value will be set to &cv-link-SHLIBVERSION; if not + specified. + + See MacOS's ld manpage for more details + + + + + + + + On Mac OS X this is used to set the linker flag: + + -current_version + + + The value is specified as X[.Y[.Z]] where X is between 1 and 65535, Y can be omitted or between 1 and + 255, Z can be omitted or between 1 and 255. This value will be derived from &cv-link-SHLIBVERSION; if not + specified. The lowest digit will be dropped and replaced by a 0. + + See MacOS's ld manpage for more details + + + + + "> + + + On Mac OS X with gcc, + general user-supplied frameworks options to be added at + the end of a command + line building a loadable module. + (This has been largely superseded by + the &cv-link-FRAMEWORKPATH;, &cv-link-FRAMEWORKPATHPREFIX;, + &cv-link-FRAMEWORKPREFIX; and &cv-link-FRAMEWORKS; variables + described above.) + + + + + + + + On Mac OS X with gcc, a list of the framework names to be linked into a + program or shared library or bundle. + The default value is the empty list. + For example: + + + + env.AppendUnique(FRAMEWORKS=Split('System Cocoa SystemConfiguration')) + + + + + + + + + On Mac OS X with gcc, + the prefix to be used for linking in frameworks + (see &cv-link-FRAMEWORKS;). + The default value is + . + + + + + + + + On Mac OS X with gcc, + an automatically-generated construction variable + containing the linker command-line options + for linking with FRAMEWORKS. + + + + + + + + On Mac OS X with gcc, + a list containing the paths to search for frameworks. + Used by the compiler to find framework-style includes like + #include <Fmwk/Header.h>. + Used by the linker to find user-specified frameworks when linking (see + &cv-link-FRAMEWORKS;). + For example: + + + + env.AppendUnique(FRAMEWORKPATH='#myframeworkdir') + + + + will add + + + + ... -Fmyframeworkdir + + + + to the compiler and linker command lines. + + + + + + + + On Mac OS X with gcc, the prefix to be used for the FRAMEWORKPATH entries. + (see &cv-link-FRAMEWORKPATH;). + The default value is + . + + + + + + + + On Mac OS X with gcc, an automatically-generated construction variable + containing the linker command-line options corresponding to + &cv-link-FRAMEWORKPATH;. + + + -- cgit v0.12