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