about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/umockdev/default.nix
blob: 9c3026b0c9fbe1d2b0ec8b8d0b1217c3926da955 (plain) (blame)
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
{ stdenv
, lib
, docbook-xsl-nons
, fetchurl
, fetchpatch
, glib
, gobject-introspection
, gtk-doc
, libgudev
, libpcap
, meson
, mesonEmulatorHook
, ninja
, pkg-config
, python3
, substituteAll
, systemdMinimal
, usbutils
, vala
, which
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "umockdev";
  version = "0.17.18";

  outputs = [ "bin" "out" "dev" "devdoc" ];

  src = fetchurl {
    url = "https://github.com/martinpitt/umockdev/releases/download/${finalAttrs.version}/umockdev-${finalAttrs.version}.tar.xz";
    sha256 = "sha256-RmrT4McV5W9Q6mqWUWWCPQc6hBN6y4oeObZlc2SKmF8=";
  };

  patches = [
    # Hardcode absolute paths to libraries so that consumers
    # do not need to set LD_LIBRARY_PATH themselves.
    ./hardcode-paths.patch

    # Replace references to udevadm with an absolute paths, so programs using
    # umockdev will just work without having to provide it in their test environment
    # $PATH.
    (substituteAll {
      src = ./substitute-udevadm.patch;
      udevadm = "${systemdMinimal}/bin/udevadm";
    })

    (fetchpatch {
      name = "musl.patch";
      url = "https://github.com/martinpitt/umockdev/commit/d4efe24be59bd859b87473ea3d7efe8100bedc74.patch";
      hash = "sha256-whf3p2e7FWN1xk5+HF9KsbMW74DPOQ0R0+FxBfCZTX0=";
    })
  ];

  nativeBuildInputs = [
    docbook-xsl-nons
    gobject-introspection
    gtk-doc
    meson
    ninja
    pkg-config
    vala
  ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
    mesonEmulatorHook
  ];

  buildInputs = [
    glib
    systemdMinimal
    libpcap
  ];

  checkInputs = lib.optionals finalAttrs.passthru.withGudev [
    libgudev
  ];

  nativeCheckInputs = [
    python3
    usbutils
    which
  ];

  strictDeps = true;

  mesonFlags = [
    "-Dgtk_doc=true"
  ];

  doCheck = true;

  postPatch = ''
    # Substitute the path to this derivation in the patch we apply.
    substituteInPlace src/umockdev-wrapper \
      --subst-var-by 'LIBDIR' "''${!outputLib}/lib"
  '';

  preCheck = ''
    # Our patch makes the path to the `LD_PRELOAD`ed library absolute.
    # When running tests, the library is not yet installed, though,
    # so we need to replace the absolute path with a local one during build.
    # We are using a symlink that will be overridden during installation.
    mkdir -p "$out/lib"
    ln -s "$PWD/libumockdev-preload.so.0" "$out/lib/libumockdev-preload.so.0"
  '';

  passthru = {
    # libgudev is needed for an optional test but it itself relies on umockdev for testing.
    withGudev = false;

    tests = {
      withGudev = finalAttrs.finalPackage.overrideAttrs (attrs: {
        passthru = attrs.passthru // {
          withGudev = true;
        };
      });
    };
  };

  meta = with lib; {
    homepage = "https://github.com/martinpitt/umockdev";
    changelog = "https://github.com/martinpitt/umockdev/releases/tag/${finalAttrs.version}";
    description = "Mock hardware devices for creating unit tests";
    license = licenses.lgpl21Plus;
    maintainers = with maintainers; [ flokli ];
    platforms = with platforms; linux;
  };
})