1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch2,
6 meson,
7 ninja,
8 ruby,
9 python3,
10 nix-update-script,
11 testers,
12 iniparser,
13 validatePkgConfig,
14 # Adds test groups and extra CLI flags.
15 buildFixture ? false,
16 # Adds the ablilty to track malloc and free calls.
17 # Note that if fixtures are enabled, this option is ignored
18 # and will always be enabled.
19 buildMemory ? buildFixture,
20 # Adds double precision floating point assertions
21 supportDouble ? false,
22
23}:
24let
25 # On newer versions of Clang, Weverything is too much of everything.
26 ignoredErrors = [
27 "-Wno-unsafe-buffer-usage"
28 "-Wno-reserved-identifier"
29 "-Wno-extra-semi-stmt"
30 ];
31in
32stdenv.mkDerivation (finalAttrs: {
33 pname = "unity-test";
34 version = "2.6.1";
35
36 src = fetchFromGitHub {
37 owner = "ThrowTheSwitch";
38 repo = "Unity";
39 tag = "v${finalAttrs.version}";
40 hash = "sha256-g0ubq7RxGQmL1R6vz9RIGJpVWYsgrZhsTWSrL1ySEug=";
41 };
42
43 patches = [
44 # The meson file does not have the subdir set correctly
45 (fetchpatch2 {
46 url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/771.patch";
47 hash = "sha256-r8ldVb7WrzVwTC2CtGul9Jk4Rzt+6ejk+paYAfFlR5M=";
48 })
49 # Fix up the shebangs in the auto directory as not all are correct
50 (fetchpatch2 {
51 url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/790.patch";
52 hash = "sha256-K+OxMe/ZMXPPjZXjGhgc5ULLN7plBwL0hV5gwmgA3FM=";
53 })
54 ];
55
56 postPatch = ''
57 patchShebangs --build auto
58 '';
59
60 outputs = [
61 "out"
62 "dev"
63 ];
64
65 strictDeps = true;
66 nativeBuildInputs = [
67 meson
68 ninja
69 python3
70 validatePkgConfig
71 ];
72
73 # For the helper shebangs
74 buildInputs = [
75 python3
76 ruby
77 ];
78
79 mesonFlags = [
80 (lib.mesonBool "extension_memory" buildMemory)
81 (lib.mesonBool "extension_fixture" buildFixture)
82 (lib.mesonBool "support_double" supportDouble)
83 ];
84
85 doCheck = true;
86
87 checkPhase = ''
88 runHook preCheck
89
90 make -C../test -j $NIX_BUILD_CORES ${lib.optionalString stdenv.cc.isClang "CC=clang"} E="-Weverything ${lib.escapeShellArgs ignoredErrors}" test
91
92 runHook postCheck
93 '';
94
95 # Various helpers
96 postInstall = ''
97 mkdir -p "$out/share"
98 install -Dm755 ../auto/* -t "$out/share/"
99 '';
100
101 passthru = {
102 updateScript = nix-update-script { };
103 tests = {
104 inherit iniparser;
105 pkg-config = testers.hasPkgConfigModules {
106 package = finalAttrs.finalPackage;
107 versionCheck = true;
108 };
109 };
110 };
111
112 meta = {
113 description = "Unity Unit Testing Framework";
114 homepage = "https://www.throwtheswitch.org/unity";
115 changelog = "https://github.com/ThrowTheSwitch/Unity/releases/tag/v${finalAttrs.version}";
116 license = lib.licenses.mit;
117 platforms = lib.platforms.all;
118 pkgConfigModules = [ "unity" ];
119 maintainers = with lib.maintainers; [
120 i01011001
121 RossSmyth
122 ];
123 };
124})