aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-08-19 20:27:34 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2018-08-24 03:39:26 +0530
commitcf7bfd05f6beb4fdcfac01a53365678e05864683 (patch)
treec4e386717b65afdd302f8283143082424389bed3
parent9364ff0dce99e52c40f1698341111b81a415551b (diff)
downloadmeson-cf7bfd05f6beb4fdcfac01a53365678e05864683.zip
meson-cf7bfd05f6beb4fdcfac01a53365678e05864683.tar.gz
meson-cf7bfd05f6beb4fdcfac01a53365678e05864683.tar.bz2
Test that system shlibs with undefined symbols can be found
-rwxr-xr-xrun_tests.py36
-rwxr-xr-xrun_unittests.py40
-rw-r--r--test cases/unit/33 external, internal library rpath/built library/meson.build13
-rw-r--r--test cases/unit/33 external, internal library rpath/external library/bar.c6
-rw-r--r--test cases/unit/33 external, internal library rpath/external library/meson.build17
5 files changed, 79 insertions, 33 deletions
diff --git a/run_tests.py b/run_tests.py
index af20ba2..1959d64 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -30,7 +30,32 @@ import mesonbuild
from mesonbuild import mesonlib
from mesonbuild import mesonmain
from mesonbuild import mlog
-from mesonbuild.environment import detect_ninja
+from mesonbuild.environment import Environment, detect_ninja
+
+
+# Fake classes and objects for mocking
+class FakeBuild:
+ def __init__(self, env):
+ self.environment = env
+
+class FakeCompilerOptions:
+ def __init__(self):
+ self.value = []
+
+def get_fake_options(prefix):
+ import argparse
+ opts = argparse.Namespace()
+ opts.cross_file = None
+ opts.wrap_mode = None
+ opts.prefix = prefix
+ opts.cmd_line_options = {}
+ return opts
+
+def get_fake_env(sdir, bdir, prefix):
+ env = Environment(sdir, bdir, get_fake_options(prefix))
+ env.coredata.compiler_options['c_args'] = FakeCompilerOptions()
+ return env
+
Backend = Enum('Backend', 'ninja vs xcode')
@@ -147,15 +172,6 @@ def ensure_backend_detects_changes(backend):
if backend is Backend.ninja:
time.sleep(1)
-def get_fake_options(prefix):
- import argparse
- opts = argparse.Namespace()
- opts.cross_file = None
- opts.wrap_mode = None
- opts.prefix = prefix
- opts.cmd_line_options = {}
- return opts
-
def should_run_linux_cross_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')
diff --git a/run_unittests.py b/run_unittests.py
index 775d316..7fe36ee 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -39,15 +39,16 @@ from mesonbuild.mesonlib import (
windows_proof_rmtree, python_command, version_compare,
grab_leading_numbers, BuildDirLock
)
-from mesonbuild.environment import Environment, detect_ninja
+from mesonbuild.environment import detect_ninja
from mesonbuild.mesonlib import MesonException, EnvironmentException
from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram
import mesonbuild.modules.pkgconfig
-from run_tests import exe_suffix, get_fake_options, get_meson_script
+from run_tests import exe_suffix, get_fake_env, get_meson_script
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 should_run_linux_cross_tests
+from run_tests import FakeBuild, FakeCompilerOptions
def get_dynamic_section_entry(fname, entry):
@@ -566,7 +567,7 @@ class InternalTests(unittest.TestCase):
'windows-mingw': {'shared': ['lib{}.dll.a', 'lib{}.lib', 'lib{}.dll',
'{}.dll.a', '{}.lib', '{}.dll'],
'static': msvc_static}}
- env = Environment('', '', get_fake_options(''))
+ env = get_fake_env('', '', '')
cc = env.detect_c_compiler(False)
if is_osx():
self._test_all_naming(cc, env, patterns, 'darwin')
@@ -609,7 +610,7 @@ class InternalTests(unittest.TestCase):
'''
with tempfile.TemporaryDirectory() as tmpdir:
pkgbin = ExternalProgram('pkg-config', command=['pkg-config'], silent=True)
- env = Environment('', '', get_fake_options(''))
+ env = get_fake_env('', '', '')
compiler = env.detect_c_compiler(False)
env.coredata.compilers = {'c': compiler}
p1 = Path(tmpdir) / '1'
@@ -1069,7 +1070,7 @@ class AllPlatformTests(BasePlatformTests):
https://github.com/mesonbuild/meson/issues/1355
'''
testdir = os.path.join(self.common_test_dir, '3 static')
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
cc = env.detect_c_compiler(False)
static_linker = env.detect_static_linker(cc)
if is_windows():
@@ -1356,7 +1357,7 @@ class AllPlatformTests(BasePlatformTests):
if not is_windows():
langs += [('objc', 'OBJC'), ('objcpp', 'OBJCXX')]
testdir = os.path.join(self.unit_test_dir, '5 compiler detection')
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
for lang, evar in langs:
# Detect with evar and do sanity checks on that
if evar in os.environ:
@@ -1458,7 +1459,7 @@ class AllPlatformTests(BasePlatformTests):
def test_always_prefer_c_compiler_for_asm(self):
testdir = os.path.join(self.common_test_dir, '141 c cpp and asm')
# Skip if building with MSVC
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
if env.detect_c_compiler(False).get_id() == 'msvc':
raise unittest.SkipTest('MSVC can\'t compile assembly')
self.init(testdir)
@@ -1716,7 +1717,7 @@ int main(int argc, char **argv) {
self.assertPathExists(os.path.join(testdir, i))
def detect_prebuild_env(self):
- env = Environment('', self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env('', self.builddir, self.prefix)
cc = env.detect_c_compiler(False)
stlinker = env.detect_static_linker(cc)
if mesonbuild.mesonlib.is_windows():
@@ -1882,7 +1883,7 @@ int main(int argc, char **argv) {
'--libdir=' + libdir])
# Find foo dependency
os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
kwargs = {'required': True, 'silent': True}
foo_dep = PkgConfigDependency('libfoo', env, kwargs)
# Ensure link_args are properly quoted
@@ -2172,7 +2173,7 @@ recommended as it is not supported on some platforms''')
testdirbase = os.path.join(self.unit_test_dir, '26 guessed linker dependencies')
testdirlib = os.path.join(testdirbase, 'lib')
extra_args = None
- env = Environment(testdirlib, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdirlib, self.builddir, self.prefix)
if env.detect_c_compiler(False).get_id() != 'msvc':
# static libraries are not linkable with -l with msvc because meson installs them
# as .a files which unix_args_to_native will not know as it expects libraries to use
@@ -2392,7 +2393,7 @@ recommended as it is not supported on some platforms''')
with open('docs/markdown/Builtin-options.md') as f:
md = f.read()
self.assertIsNotNone(md)
- env = Environment('.', self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env('', '', '')
# FIXME: Support other compilers
cc = env.detect_c_compiler(False)
cpp = env.detect_cpp_compiler(False)
@@ -2616,7 +2617,7 @@ class FailureTests(BasePlatformTests):
'''
Test that when we can't detect objc or objcpp, we fail gracefully.
'''
- env = Environment('', self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env('', self.builddir, self.prefix)
try:
env.detect_objc_compiler(False)
env.detect_objcpp_compiler(False)
@@ -2753,7 +2754,7 @@ class WindowsTests(BasePlatformTests):
ExternalLibraryHolder from build files.
'''
testdir = os.path.join(self.platform_test_dir, '1 basic')
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
cc = env.detect_c_compiler(False)
if cc.id != 'msvc':
raise unittest.SkipTest('Not using MSVC')
@@ -2766,7 +2767,7 @@ class WindowsTests(BasePlatformTests):
testdir = os.path.join(self.platform_test_dir, '5 resources')
# resource compiler depfile generation is not yet implemented for msvc
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
depfile_works = env.detect_c_compiler(False).get_id() != 'msvc'
self.init(testdir)
@@ -2855,7 +2856,7 @@ class LinuxlikeTests(BasePlatformTests):
'''
testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen')
self.init(testdir)
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
kwargs = {'required': True, 'silent': True}
os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir
foo_dep = PkgConfigDependency('libfoo', env, kwargs)
@@ -3105,7 +3106,7 @@ class LinuxlikeTests(BasePlatformTests):
an ordinary test because it requires passing options to meson.
'''
testdir = os.path.join(self.common_test_dir, '1 trivial')
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
cc = env.detect_c_compiler(False)
self._test_stds_impl(testdir, cc, 'c')
@@ -3115,7 +3116,7 @@ class LinuxlikeTests(BasePlatformTests):
be an ordinary test because it requires passing options to meson.
'''
testdir = os.path.join(self.common_test_dir, '2 cpp')
- env = Environment(testdir, self.builddir, get_fake_options(self.prefix))
+ env = get_fake_env(testdir, self.builddir, self.prefix)
cpp = env.detect_cpp_compiler(False)
self._test_stds_impl(testdir, cpp, 'cpp')
@@ -3659,8 +3660,6 @@ endian = 'little'
The system library is found with cc.find_library() and pkg-config deps.
'''
- if not is_osx():
- raise unittest.SkipTest('workflow currently only works on macOS')
oldprefix = self.prefix
# Install external library so we can find it
testdir = os.path.join(self.unit_test_dir, '33 external, internal library rpath', 'external library')
@@ -3683,6 +3682,9 @@ endian = 'little'
self.build()
# test uninstalled
self.run_tests()
+ if not is_osx():
+ # Rest of the workflow only works on macOS
+ return
# test running after installation
self.install(use_destdir=False)
prog = os.path.join(self.installdir, 'bin', 'prog')
diff --git a/test cases/unit/33 external, internal library rpath/built library/meson.build b/test cases/unit/33 external, internal library rpath/built library/meson.build
index 2b422f4..f633996 100644
--- a/test cases/unit/33 external, internal library rpath/built library/meson.build
+++ b/test cases/unit/33 external, internal library rpath/built library/meson.build
@@ -1,12 +1,21 @@
project('built library', 'c')
cc = meson.get_compiler('c')
+
+if host_machine.system() != 'cygwin'
+ # bar_in_system has undefined symbols, but still must be found
+ bar_system_dep = cc.find_library('bar_in_system')
+endif
+
foo_system_dep = cc.find_library('foo_in_system')
+
faa_pkg_dep = dependency('faa_pkg')
l = shared_library('bar_built', 'bar.c',
install: true,
dependencies : [foo_system_dep, faa_pkg_dep])
-e = executable('prog', 'prog.c', link_with: l, install: true)
-test('testprog', e)
+if host_machine.system() == 'darwin'
+ e = executable('prog', 'prog.c', link_with: l, install: true)
+ test('testprog', e)
+endif
diff --git a/test cases/unit/33 external, internal library rpath/external library/bar.c b/test cases/unit/33 external, internal library rpath/external library/bar.c
new file mode 100644
index 0000000..c6f42d6
--- /dev/null
+++ b/test cases/unit/33 external, internal library rpath/external library/bar.c
@@ -0,0 +1,6 @@
+int some_undefined_func (void);
+
+int bar_system_value (void)
+{
+ return some_undefined_func ();
+}
diff --git a/test cases/unit/33 external, internal library rpath/external library/meson.build b/test cases/unit/33 external, internal library rpath/external library/meson.build
index 6dcc97e..3c311f5 100644
--- a/test cases/unit/33 external, internal library rpath/external library/meson.build
+++ b/test cases/unit/33 external, internal library rpath/external library/meson.build
@@ -1,9 +1,22 @@
-project('system library', 'c')
+project('system library', 'c', default_options : ['b_lundef=false'])
shared_library('foo_in_system', 'foo.c', install : true)
l = shared_library('faa_pkg', 'faa.c', install: true)
+if host_machine.system() == 'darwin'
+ frameworks = ['-framework', 'CoreFoundation', '-framework', 'CoreMedia']
+ allow_undef_args = ['-Wl,-undefined,dynamic_lookup']
+else
+ frameworks = []
+ allow_undef_args = []
+endif
+
pkg = import('pkgconfig')
pkg.generate(name: 'faa_pkg',
- libraries: [l, '-framework', 'CoreFoundation', '-framework', 'CoreMedia'],
+ libraries: [l] + frameworks,
description: 'FAA, a pkg-config test library')
+
+# cygwin DLLs can't have undefined symbols
+if host_machine.system() != 'cygwin'
+ shared_library('bar_in_system', 'bar.c', install : true, link_args : allow_undef_args)
+endif