Skip to content
Permalink
Browse files
WIP meson build system
todo:
- split out path changes in test-umockdev-record.vala
- fix gtk-doc *.types build
- fix unit tests
- valgrind
- code coverage

cleanup:
 - remove autogen/configure.ac/Makefile*/m4 etc.
 - remove src/umockdev-1.0.pc.in
 - conditional build without gudev, python, g-i
  • Loading branch information
martinpitt committed Nov 7, 2020
1 parent 3beb066 commit 37e9565
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 6 deletions.
@@ -32,7 +32,6 @@ version.xml
/aclocal.m4
/configure
/libtool
/docs/reference/
src/umockdev-1.0.vapi
src/umockdev.h
src/umockdev.c
@@ -0,0 +1,16 @@
version_xml = configure_file(
input: 'version.xml.in',
output: 'version.xml',
configuration: conf)

gnome = import('gnome')
gnome.gtkdoc('umockdev',
main_xml: 'umockdev-docs.xml',
src_dir: [srcdir],
content_files: [version_xml],
ignore_headers: ['uevent_sender.h', 'ioctl_tree.h', 'debug.h'],
# TODO: falls over when building .types file; see https://github.com/mesonbuild/meson/issues/3892
scan_args: ['--rebuild-types'],
dependencies: [glib, gobject, declare_dependency(link_with : [umockdev_lib])],
install: true,
)
@@ -0,0 +1,213 @@
project('umockdev', 'c', 'vala',
version: run_command('sh', '-ec', 'head -n1 NEWS | cut -f1 -d" "').stdout().strip(),
license: 'LGPLv2.1+')

srcdir = meson.current_source_dir() / 'src'
testsdir = meson.current_source_dir() / 'tests'

add_project_arguments(
'-Werror',
'-Werror=missing-prototypes',
'-Werror=strict-prototypes',
'-Werror=nested-externs',
'-Werror=pointer-arith',
'-Werror=implicit-function-declaration',
'-Werror=pointer-arith',
'-Werror=init-self',
'-Werror=format-security',
'-Werror=format=2',
#'-Werror=missing-include-dirs',
'-Werror=unused-variable',
'-Werror=return-type',
'-Werror=uninitialized',
language: 'c')

conf = configuration_data()
cc = meson.get_compiler('c')
valac = meson.get_compiler('vala')
g_ir_compiler = find_program('g-ir-compiler', required: false)

conf.set('PACKAGE_NAME', meson.project_name())
conf.set_quoted('VERSION', meson.project_version())

#
# dependencies
#

dl = cc.find_library('dl')

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')
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')
vala_libudev = cc.find_library('udev')
vala_libutil = cc.find_library('util')

# local VAPIs
vapi_config = valac.find_library('config', dirs: srcdir)
vapi_posix_extra = valac.find_library('posix_extra', dirs: srcdir)
vapi_ioctl = valac.find_library('ioctl', dirs: testsdir)
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
#

shared_library('umockdev-preload',
['src/libumockdev-preload.c',
'src/debug.c',
'src/ioctl_tree.c'],
c_args: ['-fvisibility=default'],
version: '0.0.0',
dependencies: [dl],
install: true)

#
# umockdev client library
#

umockdev_lib = shared_library('umockdev',
['src/umockdev.vala',
'src/uevent_sender.vapi',
'src/uevent_sender.c'],
vala_vapi: 'umockdev-1.0.vapi',
vala_gir: 'UMockdev-1.0.gir',
dependencies: [glib, gobject, gio, gio_unix, vapi_posix, vapi_linux, vala_libudev, vala_libutil],
link_depends: ['src/umockdev.map'],
link_args: [
'-Wl,-export-dynamic',
'-Wl,--no-undefined',
'-Wl,--version-script,@0@/umockdev.map'.format(srcdir),
],
include_directories: ['src'],
version: '0.3.0',
install: true,
install_dir: [true, true, 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')

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')

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'))

executable('umockdev-run',
'src/umockdev-run.vala',
dependencies: [glib, gobject, gio, vapi_posix, vapi_config],
link_with: [umockdev_lib],
install: true)

executable('umockdev-record',
'src/umockdev-record.vala',
dependencies: [glib, gobject, gio, vapi_posix, vapi_config, vapi_posix_extra],
link_with: [umockdev_lib],
install: true)

#
# tests
#

test_env = environment()
test_env.set('G_DEBUG', 'fatal-warnings,fatal-criticals')
test_env.set('G_SLICE', 'debug-blocks')
test_env.set('MALLOC_CHECK_', '3')
test_env.set('TOP_SRCDIR', meson.current_source_dir())
test_env.set('TOP_BUILDDIR', meson.current_build_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())

add_test_setup('default',
exe_wrapper: srcdir / 'umockdev-wrapper',
env: test_env,
is_default: true)

executable('chatter', 'tests/chatter.c')
executable('chatter-socket-stream', 'tests/chatter-socket-stream.c')
executable('readbyte', 'tests/readbyte.c')

test('umockdev', executable('test-umockdev',
'tests/test-umockdev.c',
dependencies: [glib, libudev, gudev],
link_with: [umockdev_lib]))

test('umockdev-vala', executable('test-umockdev-vala',
'tests/test-umockdev-vala.vala',
dependencies: [glib, gobject, gio, gudev, vapi_posix, vapi_posix_extra, vapi_assertions, vapi_ioctl],
link_with: [umockdev_lib]))

test('ioctl-tree', executable('test-ioctl-tree',
['tests/test-ioctl-tree.c',
'src/ioctl_tree.c',
'src/debug.c'],
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],
link_with: [umockdev_lib]))

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],
link_with: [umockdev_lib]))

test('static-code', files('tests/test-static-code'))

if python.found()
test('umockdev.py', python,
args: ['-Wd', '-Werror::PendingDeprecationWarning', '-Werror::DeprecationWarning',
testsdir / 'test-umockdev.py'])
endif

#
# outputs
#

configure_file(output: 'config.h', configuration: conf)

if get_option('gtk_doc')
subdir('docs/reference')
endif
@@ -0,0 +1,4 @@
option('gtk_doc',
type : 'boolean',
value : false,
description : 'use gtk-doc to build documentation')
@@ -0,0 +1,9 @@
{
global:
umockdev_testbed_*;
umockdev_error_*;
umockdev_in_mock_environment*;

local:
*;
};
@@ -590,7 +590,7 @@ t_system_script_log_chatter ()
try {
assert (Process.spawn_async_with_pipes (null,
{umockdev_record_path, "--script", (string) ptyname + "=" + log, "--",
Path.build_filename (rootdir, "tests", "chatter"), (string) ptyname},
Path.build_filename (rootdir, "chatter"), (string) ptyname},
null, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD | SpawnFlags.STDOUT_TO_DEV_NULL,
null, out chatter_pid, null, null, null));
} catch (SpawnError e) {
@@ -669,7 +669,7 @@ t_system_script_log_chatter_socket_stream ()
try {
assert (Process.spawn_async_with_pipes (null,
{umockdev_record_path, "--script", spath + "=" + log, "--",
Path.build_filename (rootdir, "tests", "chatter-socket-stream"), spath},
Path.build_filename (rootdir, "chatter-socket-stream"), spath},
null, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD | SpawnFlags.STDOUT_TO_DEV_NULL,
null, out chatter_pid, null, null, null));
} catch (SpawnError e) {
@@ -901,9 +901,9 @@ main (string[] args)
else
rootdir = r;

umockdev_record_path = Path.build_filename (rootdir, "src", "umockdev-record");
umockdev_run_path = Path.build_filename (rootdir, "src", "umockdev-run");
readbyte_path = Path.build_filename (rootdir, "tests", "readbyte");
umockdev_record_path = Path.build_filename (rootdir, "umockdev-record");
umockdev_run_path = Path.build_filename (rootdir, "umockdev-run");
readbyte_path = Path.build_filename (rootdir, "readbyte");

Test.add_func ("/umockdev-record/testbed-all-empty", t_testbed_all_empty);
Test.add_func ("/umockdev-record/testbed-one", t_testbed_one);

0 comments on commit 37e9565

Please sign in to comment.