diff options
| author | Sam James <sam@gentoo.org> | 2025-10-17 16:40:07 +0100 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-10-31 01:13:28 -0400 |
| commit | 4f43a402504aa57ffa3f7b6091f5fdccfd2a3000 (patch) | |
| tree | 37a8498c3b90d7bf3aeaa6b2798f0867ac4513bd /unittests | |
| parent | 373cc823b009c5a0ceb06c462d656ec510a2505b (diff) | |
| download | meson-4f43a402504aa57ffa3f7b6091f5fdccfd2a3000.tar.gz | |
Always check if found libraries are linkable
We don't always check if a library is actually linkable because of concerns
that a library may not be standalone, so linking against it may still have
unresolved references. We can workaround that by building a shared library
as a test rather than an executable, and in fact we already do that in a
bunch of cases since bb5f2ca3da821d7a8e865cd55a8d5d638e0aab22.
This comes up in particular with Fedora and dependency('atomic') because
on x86_64, they provide a libatomic.so linker script (so our file existence
check passes), but trying to use it later on will fail if the backing package
isn't installed.
_get_file_from_list has not been deleted because the Ninja backend's
guess_library_absolute_path uses it. We might be able to change it to
also use a link test but I've left that alone.
Test notes:
* The _test_all_naming unittest has been tweaked because we were using a
blank file rather than an actual shared library, which (as expected),
now fails.
* I've also added a test for dependency('atomic') providing a result that
can actually be linked against. I've not made it check generally whether
dependency('atomic') finds something when we expect to (at least for now)
as it'll involve some CI whack-a-mole.
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=2352531
Bug: https://github.com/mesonbuild/meson/issues/14946
Closes: https://github.com/mesonbuild/meson/issues/10936
Diffstat (limited to 'unittests')
| -rw-r--r-- | unittests/internaltests.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 71e32ba3f..8bc9c00c5 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -551,10 +551,14 @@ class InternalTests(unittest.TestCase): for i in ['libfoo.so.6.0', 'libfoo.so.5.0', 'libfoo.so.54.0', 'libfoo.so.66a.0b', 'libfoo.so.70.0.so.1', 'libbar.so.7.10', 'libbar.so.7.9', 'libbar.so.7.9.3']: libpath = Path(tmpdir) / i - libpath.write_text('', encoding='utf-8') - found = cc._find_library_real('foo', env, [tmpdir], '', LibType.PREFER_SHARED, lib_prefix_warning=True, ignore_system_dirs=False) + src = libpath.with_suffix('.c') + with src.open('w', encoding='utf-8') as f: + f.write('int meson_foobar (void) { return 0; }') + subprocess.check_call(['gcc', str(src), '-o', str(libpath), '-shared']) + + found = cc._find_library_real('foo', env, [tmpdir], 'int main(void) { return 0; }', LibType.PREFER_SHARED, lib_prefix_warning=True, ignore_system_dirs=False) self.assertEqual(os.path.basename(found[0]), 'libfoo.so.54.0') - found = cc._find_library_real('bar', env, [tmpdir], '', LibType.PREFER_SHARED, lib_prefix_warning=True, ignore_system_dirs=False) + found = cc._find_library_real('bar', env, [tmpdir], 'int main(void) { return 0; }', LibType.PREFER_SHARED, lib_prefix_warning=True, ignore_system_dirs=False) self.assertEqual(os.path.basename(found[0]), 'libbar.so.7.10') def test_find_library_patterns(self): @@ -610,17 +614,22 @@ class InternalTests(unittest.TestCase): https://github.com/mesonbuild/meson/issues/3951 ''' def create_static_lib(name): - if not is_osx(): - name.open('w', encoding='utf-8').close() - return src = name.with_suffix('.c') out = name.with_suffix('.o') with src.open('w', encoding='utf-8') as f: f.write('int meson_foobar (void) { return 0; }') # use of x86_64 is hardcoded in run_tests.py:get_fake_env() - subprocess.check_call(['clang', '-c', str(src), '-o', str(out), '-arch', 'x86_64']) + if is_osx(): + subprocess.check_call(['clang', '-c', str(src), '-o', str(out), '-arch', 'x86_64']) + else: + subprocess.check_call(['gcc', '-c', str(src), '-o', str(out)]) subprocess.check_call(['ar', 'csr', str(name), str(out)]) + # The test relies on some open-coded toolchain invocations for + # library creation in create_static_lib. + if is_windows() or is_cygwin(): + return + with tempfile.TemporaryDirectory() as tmpdir: pkgbin = ExternalProgram('pkg-config', command=['pkg-config'], silent=True) env = get_fake_env() |
