@ -2980,10 +2980,88 @@ class WindowsTests(BasePlatformTests):
self . utime ( os . path . join ( testdir , ' res ' , ' resource.h ' ) )
self . assertRebuiltTarget ( ' prog_1 ' )
class DarwinTests ( BasePlatformTests ) :
'''
Tests that should run on macOS
'''
def setUp ( self ) :
super ( ) . setUp ( )
self . platform_test_dir = os . path . join ( self . src_root , ' test cases/osx ' )
def test_apple_bitcode ( self ) :
'''
Test that - fembed - bitcode is correctly added while compiling and
- bitcode_bundle is added while linking when b_bitcode is true and not
when it is false . This can ' t be an ordinary test case because we need
to inspect the compiler database .
'''
testdir = os . path . join ( self . common_test_dir , ' 4 shared ' )
# Try with bitcode enabled
out = self . init ( testdir , extra_args = ' -Db_bitcode=true ' )
# Warning was printed
self . assertRegex ( out , ' WARNING:.*b_bitcode ' )
# Compiler options were added
compdb = self . get_compdb ( )
self . assertIn ( ' -fembed-bitcode ' , compdb [ 0 ] [ ' command ' ] )
build_ninja = os . path . join ( self . builddir , ' build.ninja ' )
# Linker options were added
with open ( build_ninja , ' r ' , encoding = ' utf-8 ' ) as f :
contents = f . read ( )
m = re . search ( ' LINK_ARGS =.*-bitcode_bundle ' , contents )
self . assertIsNotNone ( m , msg = contents )
# Try with bitcode disabled
self . setconf ( ' -Db_bitcode=false ' )
# Regenerate build
self . build ( )
compdb = self . get_compdb ( )
self . assertNotIn ( ' -fembed-bitcode ' , compdb [ 0 ] [ ' command ' ] )
build_ninja = os . path . join ( self . builddir , ' build.ninja ' )
with open ( build_ninja , ' r ' , encoding = ' utf-8 ' ) as f :
contents = f . read ( )
m = re . search ( ' LINK_ARGS =.*-bitcode_bundle ' , contents )
self . assertIsNone ( m , msg = contents )
def test_apple_bitcode_modules ( self ) :
'''
Same as above , just for shared_module ( )
'''
testdir = os . path . join ( self . common_test_dir , ' 153 shared module resolving symbol in executable ' )
# Ensure that it builds even with bitcode enabled
self . init ( testdir , extra_args = ' -Db_bitcode=true ' )
self . build ( )
self . run_tests ( )
def _get_darwin_versions ( self , fname ) :
fname = os . path . join ( self . builddir , fname )
out = subprocess . check_output ( [ ' otool ' , ' -L ' , fname ] , universal_newlines = True )
m = re . match ( r ' .*version (.*), current version (.*) \ ) ' , out . split ( ' \n ' ) [ 1 ] )
self . assertIsNotNone ( m , msg = out )
return m . groups ( )
def test_library_versioning ( self ) :
'''
Ensure that compatibility_version and current_version are set correctly
'''
testdir = os . path . join ( self . platform_test_dir , ' 2 library versions ' )
self . init ( testdir )
self . build ( )
targets = { }
for t in self . introspect ( ' --targets ' ) :
targets [ t [ ' name ' ] ] = t [ ' filename ' ]
self . assertEqual ( self . _get_darwin_versions ( targets [ ' some ' ] ) , ( ' 7.0.0 ' , ' 7.0.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' noversion ' ] ) , ( ' 0.0.0 ' , ' 0.0.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' onlyversion ' ] ) , ( ' 1.0.0 ' , ' 1.0.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' onlysoversion ' ] ) , ( ' 5.0.0 ' , ' 5.0.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' intver ' ] ) , ( ' 2.0.0 ' , ' 2.0.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' stringver ' ] ) , ( ' 2.3.0 ' , ' 2.3.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' stringlistver ' ] ) , ( ' 2.4.0 ' , ' 2.4.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' intstringver ' ] ) , ( ' 1111.0.0 ' , ' 2.5.0 ' ) )
self . assertEqual ( self . _get_darwin_versions ( targets [ ' stringlistvers ' ] ) , ( ' 2.6.0 ' , ' 2.6.1 ' ) )
class LinuxlikeTests ( BasePlatformTests ) :
'''
Tests that should run on Linux and * BSD
Tests that should run on Linux , macOS , and * BSD
'''
def test_basic_soname ( self ) :
'''
@ -3763,53 +3841,6 @@ endian = 'little'
deps . append ( b ' -lintl ' )
self . assertEqual ( set ( deps ) , set ( stdo . split ( ) ) )
def test_apple_bitcode ( self ) :
'''
Test that - fembed - bitcode is correctly added while compiling and
- bitcode_bundle is added while linking when b_bitcode is true and not
when it is false . This can ' t be an ordinary test case because we need
to inspect the compiler database .
'''
if not is_osx ( ) :
raise unittest . SkipTest ( ' Apple bitcode only works on macOS ' )
testdir = os . path . join ( self . common_test_dir , ' 4 shared ' )
# Try with bitcode enabled
out = self . init ( testdir , extra_args = ' -Db_bitcode=true ' )
# Warning was printed
self . assertRegex ( out , ' WARNING:.*b_bitcode ' )
# Compiler options were added
compdb = self . get_compdb ( )
self . assertIn ( ' -fembed-bitcode ' , compdb [ 0 ] [ ' command ' ] )
build_ninja = os . path . join ( self . builddir , ' build.ninja ' )
# Linker options were added
with open ( build_ninja , ' r ' , encoding = ' utf-8 ' ) as f :
contents = f . read ( )
m = re . search ( ' LINK_ARGS =.*-bitcode_bundle ' , contents )
self . assertIsNotNone ( m , msg = contents )
# Try with bitcode disabled
self . setconf ( ' -Db_bitcode=false ' )
# Regenerate build
self . build ( )
compdb = self . get_compdb ( )
self . assertNotIn ( ' -fembed-bitcode ' , compdb [ 0 ] [ ' command ' ] )
build_ninja = os . path . join ( self . builddir , ' build.ninja ' )
with open ( build_ninja , ' r ' , encoding = ' utf-8 ' ) as f :
contents = f . read ( )
m = re . search ( ' LINK_ARGS =.*-bitcode_bundle ' , contents )
self . assertIsNone ( m , msg = contents )
def test_apple_bitcode_modules ( self ) :
'''
Same as above , just for shared_module ( )
'''
if not is_osx ( ) :
raise unittest . SkipTest ( ' Apple bitcode not relevant ' )
testdir = os . path . join ( self . common_test_dir , ' 153 shared module resolving symbol in executable ' )
# Ensure that it builds even with bitcode enabled
self . init ( testdir , extra_args = ' -Db_bitcode=true ' )
self . build ( )
self . run_tests ( )
def test_deterministic_dep_order ( self ) :
'''
Test that the dependencies are always listed in a deterministic order .
@ -4159,5 +4190,7 @@ if __name__ == '__main__':
cases + = [ ' LinuxCrossMingwTests ' ]
if is_windows ( ) or is_cygwin ( ) :
cases + = [ ' WindowsTests ' ]
if is_osx ( ) :
cases + = [ ' DarwinTests ' ]
unittest . main ( defaultTest = cases , buffer = True )