Skip to content

Commit 37ab1a2

Browse files
committed
meson: add test-libsystemd-sym, fix linking of libsystemd
This is quite messy. I think libtool might have been using something like -Wl,--whole-archive, but I don't think meson has support for that. For now, just recompile all the sources for linking into libsystemd directly. This should not matter much for efficiency, since it's a few small files.
1 parent 4e4ab1c commit 37ab1a2

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

meson.build

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,18 +967,20 @@ libjournal_core = static_library(
967967
libsystemd_journal_internal],
968968
install : false)
969969

970-
version_script_arg = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sym)
970+
libsystemd_sym_path = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sym)
971971
libsystemd = shared_library(
972972
'systemd',
973973
libsystemd_internal_sources,
974+
libsystemd_journal_internal_sources,
974975
version : '0.18.0',
975976
include_directories : includes,
976977
link_args : ['-shared',
977-
'-Wl,--version-script=' + version_script_arg],
978-
link_with : [libbasic,
979-
libsystemd_internal,
980-
libsystemd_journal_internal],
981-
dependencies : [threads],
978+
'-Wl,--version-script=' + libsystemd_sym_path],
979+
link_with : [libbasic],
980+
dependencies : [threads,
981+
librt,
982+
libxz,
983+
liblz4],
982984
link_depends : libsystemd_sym,
983985
install : true,
984986
install_dir : rootlibdir)
@@ -1932,6 +1934,20 @@ foreach tuple : tests
19321934
endif
19331935
endforeach
19341936

1937+
test_libsystemd_sym = executable(
1938+
'test-libsystemd-sym',
1939+
test_libsystemd_sym_c,
1940+
include_directories : includes,
1941+
# link_with : [libsystemd],
1942+
# TODO: try again with https://github.com/mesonbuild/meson/pull/1545
1943+
link_args : ['libsystemd.so.0.18.0'],
1944+
# link_depends : [libsystemd],
1945+
# TODO: try again after "Link_depends arguments must be strings." is solved
1946+
install : install_tests,
1947+
install_dir : testsdir)
1948+
test('test-libsystemd-sym',
1949+
test_libsystemd_sym)
1950+
19351951
############################################################
19361952

19371953
make_directive_index_py = find_program('tools/make-directive-index.py')

src/systemd/meson.build

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- mode: meson -*-
22

3-
headers = '''
3+
systemd_headers = files('''
44
sd-bus.h
55
sd-bus-protocol.h
66
sd-bus-vtable.h
@@ -10,8 +10,7 @@ headers = '''
1010
sd-journal.h
1111
sd-login.h
1212
sd-messages.h
13-
_sd-common.h
14-
'''.split()
13+
'''.split())
1514

1615
# sd-device.h
1716
# sd-hwdb.h
@@ -30,4 +29,7 @@ headers = '''
3029
# sd-resolve.h
3130
# sd-utf8.h
3231

33-
install_headers(headers, subdir : 'systemd')
32+
install_headers(
33+
systemd_headers,
34+
'_sd-common.h',
35+
subdir : 'systemd')

src/test/generate-sym-test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python3
2+
import sys, re
3+
4+
print('#include <stdio.h>')
5+
for header in sys.argv[2:]:
6+
print('#include "{}"'.format(header.split('/')[-1]))
7+
8+
print('''
9+
void* functions[] = {''')
10+
11+
for line in open(sys.argv[1]):
12+
match = re.search('^ +([a-zA-Z0-9_]+);', line)
13+
if match:
14+
print(' {},'.format(match.group(1)))
15+
16+
print('''};
17+
18+
int main(void) {
19+
unsigned i;
20+
for (i = 0; i < sizeof(functions)/sizeof(void*); i++)
21+
printf("%p\\n", functions[i]);
22+
return 0;
23+
}''')

src/test/meson.build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ test_env.set('SYSTEMD_LANGUAGE_FALLBACK_MAP', language_fallback_map)
1717
test_env.set('PATH', path)
1818
test_env.prepend('PATH', meson.build_root())
1919

20+
############################################################
21+
22+
generate_sym_test_py = find_program('generate-sym-test.py')
23+
24+
test_libsystemd_sym_c = custom_target(
25+
'test-libsystemd-sym.c',
26+
input : [libsystemd_sym_path] + systemd_headers,
27+
output : 'test-libsystemd-sym.c',
28+
command : [generate_sym_test_py, libsystemd_sym_path] + systemd_headers,
29+
capture : true)
30+
31+
############################################################
32+
2033
tests += [
2134
[['src/test/test-device-nodes.c'],
2235
[libshared],

0 commit comments

Comments
 (0)