diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-08-28 15:17:00 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-08-29 15:51:23 -0700 |
commit | bead8287a5c047f31e6efe5c49039278341ae46c (patch) | |
tree | 28c54758068db7d900a2060d4d229454ccc09c45 /run_unittests.py | |
parent | b86f2fd17f1f0825e16b1df2b1f3f598c0d77b85 (diff) | |
download | meson-bead8287a5c047f31e6efe5c49039278341ae46c.zip meson-bead8287a5c047f31e6efe5c49039278341ae46c.tar.gz meson-bead8287a5c047f31e6efe5c49039278341ae46c.tar.bz2 |
Improve support for macOS dylib versioning
We now use the soversion to set compatibility_version and
current_version by default. This is the only sane thing we can do by
default because of the restrictions on the values that can be used for
compatibility and current version.
Users can override this value with the `darwin_versions:` kwarg, which
can be a single value or a two-element list of values. The first one
is the compatibility version and the second is the current version.
Fixes https://github.com/mesonbuild/meson/issues/3555
Fixes https://github.com/mesonbuild/meson/issues/1451
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 129 |
1 files changed, 81 insertions, 48 deletions
diff --git a/run_unittests.py b/run_unittests.py index 16eee3e..f17b7ae 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -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) |