-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathassertions.nix
75 lines (73 loc) · 2.72 KB
/
assertions.nix
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
{ config, lib, ... }:
let
cargoHooks = { inherit (config.hooks) cargo-bench cargo-check cargo-test clippy; };
forAllCargoHooks = assertions:
lib.mapAttrsToList
(hook: { settings, ... }: assertions "${hook}.settings" settings)
cargoHooks;
in
[ ]
++ forAllCargoHooks (hook: { profile ? null, release ? false, ... }: {
assertion = release -> profile == null;
message = "Options `${hook}.release` and `${hook}.profile` are mutually exclusive";
})
++ forAllCargoHooks (hook: { exclude ? [ ], workspace ? false, ... }: {
assertion = exclude != [ ] -> workspace;
message = "Option `${hook}.exclude` requires `${hook}.workspace == true`";
})
++ forAllCargoHooks (hook: { package ? [ ], workspace ? false, ... }: {
assertion = package != [ ] -> workspace;
message = "Option `${hook}.package` requires `${hook}.workspace == true`";
})
++ forAllCargoHooks (hook: { bench ? [ ], benches ? false, ... }: {
assertion = benches -> bench == [ ];
message = "Options `${hook}.bench` and `${hook}.benches` are mutually exclusive";
})
++ forAllCargoHooks (hook: { bin ? [ ], bins ? false, ... }: {
assertion = bins -> bin == [ ];
message = "Options `${hook}.bin` and `${hook}.bins` are mutually exclusive";
})
++ forAllCargoHooks (hook: { example ? [ ], examples ? false, ... }: {
assertion = examples -> example == [ ];
message = "Options `${hook}.example` and `${hook}.examples` are mutually exclusive";
})
++ forAllCargoHooks (hook: { test ? [ ], tests ? false, ... }: {
assertion = tests -> test == [ ];
message = "Options `${hook}.test` and `${hook}.tests` are mutually exclusive";
})
++ forAllCargoHooks (
hook:
{ all-targets ? false
, bench ? [ ]
, benches ? false
, bin ? [ ]
, bins ? false
, example ? [ ]
, examples ? false
, lib ? false
, test ? [ ]
, tests ? false
, ...
}: {
assertion = all-targets -> (
!lib
&& bench == [ ] && !benches
&& bin == [ ] && !bins
&& example == [ ] && !examples
&& test == [ ] && !tests
);
message = "The `${hook}.all-targets` option and other target options are mutually exclusive";
}
)
++ forAllCargoHooks (hook: { all-features ? false, features ? [ ], ... }: {
assertion = all-features -> features == [ ];
message = "Options `${hook}.all-features` and `${hook}.features` are mutually exclusive";
})
++ forAllCargoHooks (hook: { all-features ? false, no-default-features ? false, ... }: {
assertion = all-features -> !no-default-features;
message = "Options `${hook}.all-features` and `${hook}.no-default-features` are mutually exclusive";
})
++ forAllCargoHooks (hook: { frozen ? false, locked ? false, ... }: {
assertion = locked -> !frozen;
message = "Options `${hook}.locked` and `${hook}.frozen` are mutually exclusive";
})