aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-08-08 04:31:09 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-08-11 04:16:18 -0700
commitae5ebd258f45cbca94197c8d380628095680544d (patch)
tree84547775db7b037c73b160db0191e61bef718958 /run_unittests.py
parent9ddc305e0727f5c89a61459c15325b31bf88f7da (diff)
downloadmeson-ae5ebd258f45cbca94197c8d380628095680544d.zip
meson-ae5ebd258f45cbca94197c8d380628095680544d.tar.gz
meson-ae5ebd258f45cbca94197c8d380628095680544d.tar.bz2
PkgConfigDependency: Don't try to resolve internal compiler libs
-lc -lm -ldl -lrt -lpthread are special linker arguments that should never be resolved to on-disk libraries. Closes https://github.com/mesonbuild/meson/issues/3879
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/run_unittests.py b/run_unittests.py
index e0f2fe5..efb69ad 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -51,11 +51,15 @@ from run_tests import get_builddir_target_args, get_backend_commands, Backend
from run_tests import ensure_backend_detects_changes, run_configure_inprocess
from run_tests import run_mtest_inprocess
-# Fake class for mocking
+# Fake classes for mocking
class FakeBuild:
def __init__(self, env):
self.environment = env
+class FakeCompilerOptions:
+ def __init__(self):
+ self.value = []
+
def get_dynamic_section_entry(fname, entry):
if is_cygwin() or is_osx():
raise unittest.SkipTest('Test only applicable to ELF platforms')
@@ -605,6 +609,7 @@ class InternalTests(unittest.TestCase):
env = Environment('', '', get_fake_options(''))
compiler = env.detect_c_compiler(False)
env.coredata.compilers = {'c': compiler}
+ env.coredata.compiler_options['c_link_args'] = FakeCompilerOptions()
p1 = Path(tmpdir) / '1'
p2 = Path(tmpdir) / '2'
p1.mkdir()
@@ -614,6 +619,12 @@ class InternalTests(unittest.TestCase):
# libbar.a is in both prefixes
(p1 / 'libbar.a').open('w').close()
(p2 / 'libbar.a').open('w').close()
+ # Ensure that we never statically link to these
+ (p1 / 'libpthread.a').open('w').close()
+ (p1 / 'libm.a').open('w').close()
+ (p1 / 'libc.a').open('w').close()
+ (p1 / 'libdl.a').open('w').close()
+ (p1 / 'librt.a').open('w').close()
def fake_call_pkgbin(self, args, env=None):
if '--libs' not in args:
@@ -622,6 +633,8 @@ class InternalTests(unittest.TestCase):
return 0, '-L{} -lfoo -L{} -lbar'.format(p1.as_posix(), p2.as_posix())
if args[0] == 'bar':
return 0, '-L{} -lbar'.format(p2.as_posix())
+ if args[0] == 'internal':
+ return 0, '-L{} -lpthread -lm -lc -lrt -ldl'.format(p1.as_posix())
old_call = PkgConfigDependency._call_pkgbin
old_check = PkgConfigDependency.check_pkgconfig
@@ -634,6 +647,14 @@ class InternalTests(unittest.TestCase):
[(p1 / 'libfoo.a').as_posix(), (p2 / 'libbar.a').as_posix()])
bar_dep = PkgConfigDependency('bar', env, kwargs)
self.assertEqual(bar_dep.get_link_args(), [(p2 / 'libbar.a').as_posix()])
+ internal_dep = PkgConfigDependency('internal', env, kwargs)
+ if compiler.get_id() == 'msvc':
+ self.assertEqual(internal_dep.get_link_args(), [])
+ else:
+ link_args = internal_dep.get_link_args()
+ for link_arg in link_args:
+ for lib in ('pthread', 'm', 'c', 'dl', 'rt'):
+ self.assertNotIn('lib{}.a'.format(lib), link_arg, msg=link_args)
# Test ends
PkgConfigDependency._call_pkgbin = old_call
PkgConfigDependency.check_pkgconfig = old_check
@@ -2797,7 +2818,7 @@ class WindowsTests(BasePlatformTests):
if cc.id != 'msvc':
raise unittest.SkipTest('Not using MSVC')
# To force people to update this test, and also test
- self.assertEqual(set(cc.ignore_libs), {'c', 'm', 'pthread'})
+ self.assertEqual(set(cc.ignore_libs), {'c', 'm', 'pthread', 'dl', 'rt'})
for l in cc.ignore_libs:
self.assertEqual(cc.find_library(l, env, []), [])