-
Notifications
You must be signed in to change notification settings - Fork 60
/
meson.build
332 lines (285 loc) · 10.9 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
project('umockdev', 'c', 'vala',
version: run_command(meson.current_source_dir() / 'src' / 'getversion.sh', check: true).stdout().strip(),
license: 'LGPLv2.1+')
srcdir = meson.current_source_dir() / 'src'
testsdir = meson.current_source_dir() / 'tests'
lib_version = '0.3.0'
add_project_arguments(
'-std=gnu11',
'-Werror=missing-prototypes',
'-Werror=strict-prototypes',
'-Werror=nested-externs',
'-Werror=pointer-arith',
'-Werror=implicit-function-declaration',
'-Werror=implicit-int',
'-Werror=int-conversion',
'-Werror=old-style-definition',
'-Werror=pointer-arith',
'-Werror=init-self',
'-Werror=format-security',
'-Werror=format=2',
#'-Werror=missing-include-dirs',
'-Werror=return-type',
'-Werror=uninitialized',
language: 'c')
add_project_arguments('--abi-stability', language: 'vala')
conf = configuration_data()
cc = meson.get_compiler('c')
valac = meson.get_compiler('vala')
g_ir_compiler = find_program('g-ir-compiler', required: false)
# generated vala code triggers tons of these
add_project_arguments(
cc.get_supported_arguments(
# Vala doesn't have `const void*`, or a way to selectively #pragma these in the code
'-Wno-error=discarded-qualifiers',
# spi_ioc_transfer.[rx]x_buf are pointers, but declared u64 everywhere; Vala can't selectively #pragma these
'-Wno-error=pointer-to-int-cast',
# mostly const dropping and dropped "volatile" in fully autogenerated code;
# upstream Vala does not support fixing this warning
'-Wno-error=incompatible-pointer-types',
# https://gitlab.gnome.org/GNOME/vala/-/issues/1529
'-Wno-error=pointer-sign',
# "mostly harmless", fallout from Vala C code template generation, C compiler will optimize away
'-Wno-unused-but-set-variable',
'-Wno-unused-function',
'-Wno-unused-label',
'-Wno-unused-value',
'-Wno-unused-variable'
), language: 'c')
# HACK: vala doesn't support declaring const arguments, so we get a lot of errors
if cc.get_id() == 'clang'
add_project_arguments('-Wno-incompatible-function-pointer-types', language: 'c')
endif
conf.set('PACKAGE_NAME', meson.project_name())
conf.set_quoted('VERSION', meson.project_version())
# glibc versions somewhere between 2.28 and 2.34
if cc.has_function('__fxstatat', prefix: '#include <sys/stat.h>')
add_project_arguments('-DHAVE_FXSTATAT', language: 'c')
endif
# Not always explicit
if cc.has_function('openat64', prefix: '#include <fcntl.h>')
add_project_arguments('-DHAVE_OPENAT64', language: 'c')
endif
meson.add_dist_script(srcdir / 'getversion.sh')
#
# dependencies
#
optional_defines = []
dl = cc.find_library('dl')
selinux = cc.find_library('libselinux', required: false)
if selinux.found()
if cc.check_header('selinux/selinux.h')
optional_defines += ['--define=HAVE_SELINUX']
endif
endif
glib = dependency('glib-2.0', version: '>= 2.32.0')
gobject = dependency('gobject-2.0', version: '>= 2.32.0')
gio = dependency('gio-2.0', version: '>= 2.32.0')
gio_unix = dependency('gio-unix-2.0', version: '>= 2.32.0')
libudev = dependency('libudev')
libpcap = dependency('libpcap')
pthread = cc.find_library('pthread', required: true)
gudev = dependency('gudev-1.0', required: false)
python = find_program('python3', 'python', required: false)
vapi_posix = valac.find_library('posix')
vapi_linux = valac.find_library('linux')
vapi_linux_fixes = valac.find_library('linux_fixes', dirs: srcdir)
vapi_glibc = valac.find_library('glibc', dirs: srcdir)
vala_libudev = cc.find_library('udev')
vala_libutil = cc.find_library('util')
# local VAPIs
vapi_config = valac.find_library('config', dirs: srcdir)
vapi_ioctl = valac.find_library('ioctl', dirs: srcdir)
vapi_selinux = valac.find_library('selinux', dirs: srcdir)
vapi_assertions = valac.find_library('assertions', dirs: testsdir)
#
# system API checks
#
# glibc's ioctl takes an 'unsigned long' instead of the POSIX 'int' for the request parameter
if cc.compiles('''
#include <sys/ioctl.h>
extern int ioctl (int, int, ...);
void main(void) {}
''', name: 'ioctl request parameter type is int')
conf.set('IOCTL_REQUEST_TYPE', 'int')
else
conf.set('IOCTL_REQUEST_TYPE', 'unsigned long')
endif
#
# preload library
#
preload_lib = shared_library('umockdev-preload',
['src/libumockdev-preload.c',
'src/debug.c',
'src/utils.c',
'src/ioctl_tree.c'],
c_args: ['-fvisibility=default'],
version: '0.0.0',
dependencies: [dl, pthread],
install: true)
#
# umockdev client library
#
umockdev_utils_lib = static_library('umockdev-utils',
'src/umockdev-utils.vala',
vala_vapi: 'umockdev-utils.vapi',
dependencies: [glib, vapi_posix],
include_directories: include_directories('src'))
umockdev_lib = shared_library('umockdev',
['src/umockdev.vala',
'src/umockdev-ioctl.vala',
'src/umockdev-pcap.vala',
'src/umockdev-spi.vala',
'src/uevent_sender.vapi',
'src/uevent_sender.c',
'src/ioctl_tree.vapi',
'src/ioctl_tree.c',
'src/utils.c',
'src/debug.c'],
vala_vapi: 'umockdev-1.0.vapi',
vala_gir: 'UMockdev-1.0.gir',
dependencies: [glib, gobject, gio, gio_unix, vapi_posix, vapi_linux, vapi_linux_fixes, vala_libudev, vala_libutil, vapi_ioctl, vapi_selinux, libpcap, selinux],
link_with: [umockdev_utils_lib],
link_depends: ['src/umockdev.map'],
link_args: [
'-Wl,-export-dynamic',
'-Wl,--no-undefined',
'-Wl,--version-script,@0@/umockdev.map'.format(srcdir),
],
vala_args: ['--define=INTERNAL_REGISTER_API',
'--define=INTERNAL_UNREGISTER_PATH_API',
'--vapidir=@0@/src'.format(meson.current_source_dir())] + optional_defines,
include_directories: include_directories('src'),
version: lib_version,
install: true,
install_dir: [true, get_option('includedir') / 'umockdev-1.0', true, true])
# no way to insert "Rename to:" into annotations, so hack it
hacked_gir = custom_target('UMockdev-1.0 hacked gir',
command: ['sed', '/name="add_devicev"/ s/icev">$/icev" shadows="add_device">/', meson.current_build_dir() / 'UMockdev-1.0.gir'],
capture: true,
depends: umockdev_lib,
output: 'UMockdev-1.0-hacked.gir')
if g_ir_compiler.found()
umockdev_typelib = custom_target('UMockdev-1.0 typelib',
command: [g_ir_compiler, '--output', '@OUTPUT@', '-l', 'libumockdev.so.0', '@INPUT@'],
input: hacked_gir,
output: 'UMockdev-1.0.typelib',
install: true,
install_dir: get_option('libdir') / 'girepository-1.0')
endif
pkgconfig = import('pkgconfig')
pkgconfig.generate(umockdev_lib,
filebase: 'umockdev-1.0',
requires: ['glib-2.0', 'gobject-2.0'],
subdirs: ['umockdev-1.0'],
description: 'Mock hardware devices for creating unit tests')
#
# programs
#
install_data('src/umockdev-wrapper', install_dir: get_option('bindir'))
umockdev_run_exe = executable('umockdev-run',
'src/umockdev-run.vala',
dependencies: [glib, gobject, gio, vapi_posix, vapi_config],
link_with: [umockdev_lib, umockdev_utils_lib],
install: true)
umockdev_record_exe = executable('umockdev-record',
['src/umockdev-record.vala',
'src/umockdev-ioctl.vala',
'src/umockdev-pcap.vala',
'src/umockdev-spi.vala',
'src/ioctl_tree.vapi',
'src/ioctl_tree.c',
'src/utils.c',
'src/debug.c'],
dependencies: [glib, gobject, gio_unix, vapi_posix, vapi_config, vapi_ioctl, vapi_selinux, libpcap, selinux],
link_with: [umockdev_utils_lib],
vala_args: ['--define=INTERNAL_REGISTER_API',
'--define=INTERNAL_UNREGISTER_ALL_API',
'--vapidir=@0@/src'.format(meson.current_source_dir())] + optional_defines,
include_directories: include_directories('src'),
install: true)
#
# tests
#
test_env = environment()
test_env.set('G_DEBUG', 'fatal-warnings,fatal-criticals,gc-friendly')
test_env.set('MALLOC_CHECK_', '3')
test_env.set('TOP_SRCDIR', meson.current_source_dir())
test_env.prepend('LD_LIBRARY_PATH', meson.current_build_dir())
test_env.prepend('PATH', meson.current_build_dir())
test_env.prepend('GI_TYPELIB_PATH', meson.current_build_dir())
installed_env = environment()
test_env.set('TOP_SRCDIR', meson.current_source_dir())
add_test_setup('default',
exe_wrapper: srcdir / 'umockdev-wrapper',
# podman often hangs for a while in overlayfs
timeout_multiplier: 5,
env: test_env,
is_default: true)
add_test_setup('valgrind',
exe_wrapper: [srcdir / 'umockdev-wrapper', 'valgrind', '-q', '--leak-check=full', '--show-possibly-lost=no',
'--gen-suppressions=all', '--suppressions=' + srcdir / 'valgrind.supp',
'--errors-for-leak-kinds=definite', '--error-exitcode=33',
'--trace-children=yes', '--trace-children-skip=/bin*,/usr/bin/*,/usr/local/bin/*'],
timeout_multiplier: 10,
env: test_env)
add_test_setup('installed',
exe_wrapper: 'umockdev-wrapper',
# podman often hangs for a while in overlayfs
timeout_multiplier: 5,
env: test_env)
test_chatter_exe = executable('chatter', 'tests/chatter.c')
test_chatter_stream_exe = executable('chatter-socket-stream', 'tests/chatter-socket-stream.c')
test_readbyte_exe = executable('readbyte', 'tests/readbyte.c')
if gudev.found()
test('umockdev', executable('test-umockdev',
'tests/test-umockdev.c',
dependencies: [glib, libudev, gudev],
link_with: [umockdev_lib]),
depends: [preload_lib])
test('umockdev-vala', executable('test-umockdev-vala',
'tests/test-umockdev-vala.vala',
include_directories: include_directories('src'),
dependencies: [glib, gobject, gio, gudev, vapi_posix, vapi_assertions, vapi_ioctl, vapi_glibc, vapi_selinux, selinux],
link_with: [umockdev_lib, umockdev_utils_lib],
vala_args: optional_defines),
depends: [preload_lib],
suite: 'fails-valgrind')
endif
test('ioctl-tree', executable('test-ioctl-tree',
['tests/test-ioctl-tree.c',
'src/ioctl_tree.c',
'src/utils.c',
'src/debug.c'],
include_directories: include_directories('src'),
dependencies: [glib]))
test('umockdev-run', executable('test-umockdev-run',
'tests/test-umockdev-run.vala',
dependencies: [glib, gobject, gio, vapi_posix, vapi_assertions, vapi_config, vapi_selinux, selinux],
link_with: [umockdev_lib, umockdev_utils_lib],
vala_args: optional_defines),
depends: [umockdev_run_exe, preload_lib, test_chatter_exe, test_chatter_stream_exe])
test('umockdev-record', executable('test-umockdev-record',
'tests/test-umockdev-record.vala',
dependencies: [glib, gobject, gio, gio_unix, vapi_posix, vapi_linux, vapi_assertions, vapi_config, vala_libutil, vapi_selinux, selinux],
link_with: [umockdev_lib, umockdev_utils_lib],
vala_args: optional_defines),
depends: [umockdev_record_exe, preload_lib, test_readbyte_exe, test_chatter_exe, test_chatter_stream_exe],
suite: 'fails-valgrind')
test('static-code', files('tests/test-static-code'))
if python.found()
if g_ir_compiler.found()
test('umockdev.py', python,
args: ['-Wd', '-Werror::PendingDeprecationWarning', '-Werror::DeprecationWarning',
testsdir / 'test-umockdev.py'],
depends: [preload_lib, umockdev_typelib],
suite: 'fails-valgrind')
endif
endif
#
# outputs
#
configure_file(output: 'config.h', configuration: conf)
if get_option('gtk_doc')
subdir('docs/reference')
endif