1{ stdenv
2, lib
3, docbook-xsl-nons
4, fetchurl
5, fetchpatch
6, glib
7, gobject-introspection
8, gtk-doc
9, libgudev
10, libpcap
11, meson
12, mesonEmulatorHook
13, ninja
14, pkg-config
15, python3
16, substituteAll
17, systemdMinimal
18, usbutils
19, vala
20, which
21}:
22
23stdenv.mkDerivation (finalAttrs: {
24 pname = "umockdev";
25 version = "0.18.1";
26
27 outputs = [ "bin" "out" "dev" "devdoc" ];
28
29 src = fetchurl {
30 url = "https://github.com/martinpitt/umockdev/releases/download/${finalAttrs.version}/umockdev-${finalAttrs.version}.tar.xz";
31 hash = "sha256-ZRtoaQM7sUiBNu1zxY6SRfWwGFYmHhzqBBAwuD+x7Xw=";
32 };
33
34 patches = [
35 # Hardcode absolute paths to libraries so that consumers
36 # do not need to set LD_LIBRARY_PATH themselves.
37 ./hardcode-paths.patch
38
39 # Replace references to udevadm with an absolute paths, so programs using
40 # umockdev will just work without having to provide it in their test environment
41 # $PATH.
42 (substituteAll {
43 src = ./substitute-udevadm.patch;
44 udevadm = "${systemdMinimal}/bin/udevadm";
45 })
46 ];
47
48 nativeBuildInputs = [
49 docbook-xsl-nons
50 gobject-introspection
51 gtk-doc
52 meson
53 ninja
54 pkg-config
55 vala
56 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
57 mesonEmulatorHook
58 ];
59
60 buildInputs = [
61 glib
62 systemdMinimal
63 libpcap
64 ];
65
66 checkInputs = lib.optionals finalAttrs.passthru.withGudev [
67 libgudev
68 ];
69
70 nativeCheckInputs = [
71 python3
72 usbutils
73 which
74 ];
75
76 strictDeps = true;
77
78 mesonFlags = [
79 "-Dgtk_doc=true"
80 ];
81
82 doCheck = true;
83
84 postPatch = ''
85 # Substitute the path to this derivation in the patch we apply.
86 substituteInPlace src/umockdev-wrapper \
87 --subst-var-by 'LIBDIR' "''${!outputLib}/lib"
88 '';
89
90 preCheck = ''
91 # Our patch makes the path to the `LD_PRELOAD`ed library absolute.
92 # When running tests, the library is not yet installed, though,
93 # so we need to replace the absolute path with a local one during build.
94 # We are using a symlink that will be overridden during installation.
95 mkdir -p "$out/lib"
96 ln -s "$PWD/libumockdev-preload.so.0" "$out/lib/libumockdev-preload.so.0"
97 '';
98
99 passthru = {
100 # libgudev is needed for an optional test but it itself relies on umockdev for testing.
101 withGudev = false;
102
103 tests = {
104 withGudev = finalAttrs.finalPackage.overrideAttrs (attrs: {
105 passthru = attrs.passthru // {
106 withGudev = true;
107 };
108 });
109 };
110 };
111
112 meta = with lib; {
113 homepage = "https://github.com/martinpitt/umockdev";
114 changelog = "https://github.com/martinpitt/umockdev/releases/tag/${finalAttrs.version}";
115 description = "Mock hardware devices for creating unit tests";
116 license = licenses.lgpl21Plus;
117 maintainers = with maintainers; [ flokli ];
118 platforms = with platforms; linux;
119 };
120})