summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2018-12-10 22:33:14 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2018-12-10 22:33:14 (GMT)
commitf4b0ced65442d77b8925210cd81ae45d3266da85 (patch)
tree30b6f0b82773aaa57e0f8237424df7e2b82f7f05
parent903d9a41e160005360aef34d7850bde9e51ecc7c (diff)
downloadSCons-f4b0ced65442d77b8925210cd81ae45d3266da85.zip
SCons-f4b0ced65442d77b8925210cd81ae45d3266da85.tar.gz
SCons-f4b0ced65442d77b8925210cd81ae45d3266da85.tar.bz2
Add APPLELINK_NO_CURRENT_VERSION and APPLELINK_NO_COMPATIBILITY_VERSION to allow user to disable generating either or both -current_version and/or -compatibility_version to the applelink linker. Updates to docs. Add docstrings to generator functions
-rw-r--r--src/engine/SCons/Tool/applelink.py36
-rw-r--r--src/engine/SCons/Tool/applelink.xml40
-rw-r--r--test/LINK/applelink.py57
-rw-r--r--test/LINK/applelink_image/SConstruct_CurVers_CompatVers18
4 files changed, 140 insertions, 11 deletions
diff --git a/src/engine/SCons/Tool/applelink.py b/src/engine/SCons/Tool/applelink.py
index af854b7..efa7ee1 100644
--- a/src/engine/SCons/Tool/applelink.py
+++ b/src/engine/SCons/Tool/applelink.py
@@ -110,10 +110,20 @@ def _applelib_check_valid_version(version_string):
def _applelib_currentVersionFromSoVersion(source, target, env, for_signature):
"""
- -Wl,current_version=2.3
+ A generator function to create the -Wl,-current_version flag if needed.
+ If env['APPLELINK_NO_CURRENT_VERSION'] contains a true value no flag will be generated
+ Otherwise if APPLELINK_CURRENT_VERSION is not specified, env['SHLIBVERSION']
+ will be used.
+
+ :param source:
+ :param target:
+ :param env:
+ :param for_signature:
+ :return: A string providing the flag to specify the current_version of the shared library
"""
-
- if env.get('APPLELINK_CURRENT_VERSION', False):
+ if env.get('APPLELINK_NO_CURRENT_VERSION', False):
+ return ""
+ elif env.get('APPLELINK_CURRENT_VERSION', False):
version_string = env['APPLELINK_CURRENT_VERSION']
elif env.get('SHLIBVERSION', False):
version_string = env['SHLIBVERSION']
@@ -131,16 +141,29 @@ def _applelib_currentVersionFromSoVersion(source, target, env, for_signature):
def _applelib_compatVersionFromSoVersion(source, target, env, for_signature):
"""
- -Wl,compat_version=2.0
+ A generator function to create the -Wl,-compatibility_version flag if needed.
+ If env['APPLELINK_NO_COMPATIBILITY_VERSION'] contains a true value no flag will be generated
+ Otherwise if APPLELINK_COMPATIBILITY_VERSION is not specified
+ the first two parts of env['SHLIBVERSION'] will be used with a .0 appended.
+
+ :param source:
+ :param target:
+ :param env:
+ :param for_signature:
+ :return: A string providing the flag to specify the compatibility_version of the shared library
"""
-
- if env.get('APPLELINK_COMPATIBILITY_VERSION', False):
+ if env.get('APPLELINK_NO_COMPATIBILITY_VERSION', False):
+ return ""
+ elif env.get('APPLELINK_COMPATIBILITY_VERSION', False):
version_string = env['APPLELINK_COMPATIBILITY_VERSION']
elif env.get('SHLIBVERSION', False):
version_string = ".".join(env['SHLIBVERSION'].split('.')[:2] + ['0'])
else:
return ""
+ if version_string is None:
+ return ""
+
valid, reason = _applelib_check_valid_version(version_string)
if not valid:
raise AppleLinkInvalidCompatibilityVersionException(reason)
@@ -181,7 +204,6 @@ def generate(env):
env['LDMODULEFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -bundle')
env['LDMODULECOM'] = '$LDMODULE -o ${TARGET} $LDMODULEFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
- #
env['__SHLIBVERSIONFLAGS'] = '${__libversionflags(__env__,"SHLIBVERSION","_SHLIBVERSIONFLAGS")}'
diff --git a/src/engine/SCons/Tool/applelink.xml b/src/engine/SCons/Tool/applelink.xml
index c3346db..ca76aee 100644
--- a/src/engine/SCons/Tool/applelink.xml
+++ b/src/engine/SCons/Tool/applelink.xml
@@ -43,6 +43,9 @@ See its __doc__ string for a discussion of the format.
<item>LDMODULECOM</item>
<item>APPLELINK_CURRENT_VERSION</item>
<item>APPLELINK_COMPATIBILITY_VERSION</item>
+ <item>APPLELINK_NO_CURRENT_VERSION</item>
+ <item>APPLELINK_NO_COMPATIBILITY_VERSION</item>
+
</sets>
<uses>
<item>FRAMEWORKSFLAGS</item>
@@ -59,13 +62,30 @@ See its __doc__ string for a discussion of the format.
</para>
<para>
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
+ 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.
</para>
+ <para>
+ If the &cv-link-APPLELINK_NO_COMPATIBILITY_VERSION; is set then no -compatibility_version will be
+ output.
+ </para>
<para>See MacOS's ld manpage for more details</para>
</summary>
</cvar>
+ <cvar name="APPLELINK_NO_COMPATIBILITY_VERSION">
+ <summary>
+ <para>
+ Set this to any True (1|True|non-empty string) value to disable adding -compatibility_version flag when
+ generating versioned shared libraries.
+ </para>
+ <para>
+ This overrides &cv-link-APPLELINK_COMPATIBILITY_VERSION;.
+ </para>
+ </summary>
+ </cvar>
+
<cvar name="APPLELINK_CURRENT_VERSION">
<summary>
@@ -79,11 +99,29 @@ See its __doc__ string for a discussion of the format.
255, Z can be omitted or between 1 and 255. This value will be set to &cv-link-SHLIBVERSION; if not
specified.
</para>
+ <para>
+ If the &cv-link-APPLELINK_NO_CURRENT_VERSION; is set then no -current_version will be
+ output.
+ </para>
<para>See MacOS's ld manpage for more details</para>
</summary>
</cvar>
+
+ <cvar name="APPLELINK_CURRENT_VERSION">
+ <summary>
+ <para>
+ Set this to any True (1|True|non-empty string) value to disable adding -current_version flag when
+ generating versioned shared libraries.
+ </para>
+ <para>
+ This overrides &cv-link-APPLELINK_CURRENT_VERSION;.
+ </para>
+ </summary>
+ </cvar>
+
+
<cvar name="FRAMEWORKSFLAGS">">
<summary>
<para>
diff --git a/test/LINK/applelink.py b/test/LINK/applelink.py
index f48a498..86e0a4c 100644
--- a/test/LINK/applelink.py
+++ b/test/LINK/applelink.py
@@ -88,6 +88,63 @@ for SHLIBVERSION, APPLELINK_CURRENT_VERSION, APPLELINK_COMPATIBILITY_VERSION, sh
test.run(program='/usr/bin/otool', arguments='-L libfoo.%s.dylib' % SHLIBVERSION, stdout=otool_output)
+# Now test that None in APPLELINK_CURRENT_VERSION or APPLELINK_COMPATIBILITY_VERSION will skip
+# generating their relevant linker command line flag.
+for SHLIBVERSION, \
+ APPLELINK_CURRENT_VERSION, APPLELINK_COMPATIBILITY_VERSION, \
+ APPLELINK_NO_CURRENT_VERSION, APPLELINK_NO_COMPATIBILITY_VERSION in [
+ ('1.2.3', 0, 0, 0, 1),
+ ('1.2.3', 0, 0, 1, 0),
+ ('1.2.3', 0, 0, 1, 1),
+
+]:
+
+ if not APPLELINK_CURRENT_VERSION:
+ APPLELINK_CURRENT_VERSION = SHLIBVERSION
+ if not APPLELINK_COMPATIBILITY_VERSION:
+ APPLELINK_COMPATIBILITY_VERSION = '.'.join(APPLELINK_CURRENT_VERSION.split('.', 2)[:2] + ['0'])
+
+ test.run(
+ arguments='{extra_flags} -f SConstruct_CurVers_CompatVers SHLIBVERSION={SHLIBVERSION} '
+ 'APPLELINK_CURRENT_VERSION={APPLELINK_CURRENT_VERSION} '
+ 'APPLELINK_COMPATIBILITY_VERSION={APPLELINK_COMPATIBILITY_VERSION} '
+ 'APPLELINK_NO_CURRENT_VERSION={APPLELINK_NO_CURRENT_VERSION} '
+ 'APPLELINK_NO_COMPATIBILITY_VERSION={APPLELINK_NO_COMPATIBILITY_VERSION} '.format(
+ **locals()))
+
+ if APPLELINK_NO_CURRENT_VERSION:
+ # Should not contain -Wl,-current_version
+ test.must_not_contain_lines(test.stdout(),
+ ['-Wl,-current_version'])
+ else:
+ # Should contain -Wl,-current_version,{APPLELINK_CURRENT_VERSION}
+ test.must_contain_all_lines(test.stdout(),
+ ['-Wl,-current_version,{APPLELINK_CURRENT_VERSION}'.format(**locals())])
+
+ if APPLELINK_NO_COMPATIBILITY_VERSION:
+ # Should not contain -Wl,-compatibility_version
+ test.must_not_contain_lines(test.stdout(),
+ ['-Wl,-compatibility_version'])
+ else:
+ # Should contain -Wl,-compatibility_version,{APPLELINK_COMPATIBILITY_VERSION}
+ test.must_contain_all_lines(test.stdout(),
+ ['-Wl,-compatibility_version,{APPLELINK_COMPATIBILITY_VERSION}'.format(**locals())])
+
+ if not (extra_flags):
+ # Now run otool -L to get the compat and current version info and verify it's correct in the library.
+ # We expect output such as this
+ # libfoo.1.2.3.dylib:
+ # > libfoo.1.2.3.dylib (compatibility version 1.1.99, current version 9.9.9)
+ # > /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
+ if APPLELINK_NO_CURRENT_VERSION:
+ APPLELINK_CURRENT_VERSION = '0.0.0'
+ if APPLELINK_NO_COMPATIBILITY_VERSION:
+ APPLELINK_COMPATIBILITY_VERSION = '0.0.0'
+ otool_output = "libfoo.{SHLIBVERSION}.dylib:\n\tlibfoo.{SHLIBVERSION}.dylib (compatibility version {APPLELINK_COMPATIBILITY_VERSION}, current version {APPLELINK_CURRENT_VERSION})\n\t/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)\n".format(
+ **locals())
+
+ test.run(program='/usr/bin/otool', arguments='-L libfoo.%s.dylib' % SHLIBVERSION, stdout=otool_output)
+
test.pass_test()
# Local Variables:
diff --git a/test/LINK/applelink_image/SConstruct_CurVers_CompatVers b/test/LINK/applelink_image/SConstruct_CurVers_CompatVers
index b699ad8..fba953d 100644
--- a/test/LINK/applelink_image/SConstruct_CurVers_CompatVers
+++ b/test/LINK/applelink_image/SConstruct_CurVers_CompatVers
@@ -4,12 +4,25 @@ vars = Variables(None, ARGUMENTS)
vars.Add('SHLIBVERSION', 'Set the SHLIBVERSION', 0)
vars.Add('APPLELINK_CURRENT_VERSION', 'Set APPLELINK_CURRENT_VERSION', 0)
vars.Add('APPLELINK_COMPATIBILITY_VERSION', 'Set APPLELINK_COMPATIBILITY_VERSION', 0)
+vars.Add('APPLELINK_NO_CURRENT_VERSION', 'Set APPLELINK_NO_CURRENT_VERSION', 0)
+vars.Add('APPLELINK_NO_COMPATIBILITY_VERSION', 'Set APPLELINK_NO_COMPATIBILITY_VERSION', 0)
env = Environment(variables = vars, tools=['gcc', 'applelink'])
-obj = env.SharedObject('foo.c')
+if env['APPLELINK_NO_CURRENT_VERSION'] == '0':
+ env['APPLELINK_NO_CURRENT_VERSION'] = 0
+
+if env['APPLELINK_NO_COMPATIBILITY_VERSION'] == '0':
+ env['APPLELINK_NO_COMPATIBILITY_VERSION'] = 0
+
-# sl = env.SharedLibrary('foo', obj)
+print("SHLIBVERSION =[%s]"%env.get('SHLIBVERSION', False))
+print("APPLELINK_CURRENT_VERSION =[%s]"%env.get('APPLELINK_CURRENT_VERSION', False))
+print("APPLELINK_COMPATIBILITY_VERSION =[%s]"%env.get('APPLELINK_COMPATIBILITY_VERSION', False))
+print("APPLELINK_NO_CURRENT_VERSION =[%s]"%env.get('APPLELINK_NO_CURRENT_VERSION', False))
+print("APPLELINK_NO_COMPATIBILITY_VERSION=[%s]"%env.get('APPLELINK_NO_COMPATIBILITY_VERSION', False))
+
+obj = env.SharedObject('foo.c')
sl = env.SharedLibrary('foo', obj)
lm = env.LoadableModule('fool', obj)
@@ -20,4 +33,3 @@ env.InstallVersionedLib(target='#/install',
env.InstallVersionedLib(target='#/install',
source=lm)
-print("SHLIBVERSION=%s"%env['SHLIBVERSION'])