1{ lib }:
2# helper functions for packaging programs with plugin systems
3{
4
5 /*
6 Takes a list of expected plugin names
7 and compares it to the found plugins given in the file,
8 one plugin per line.
9 If the lists differ, the build fails with a nice message.
10
11 This is helpful to ensure maintainers don’t miss
12 the addition or removal of a plugin.
13 */
14 diffPlugins = expectedPlugins: foundPluginsFilePath: ''
15 # sort both lists first
16 plugins_expected=$(mktemp)
17 (${lib.concatMapStrings (s: "echo \"${s}\";") expectedPlugins}) \
18 | sort -u > "$plugins_expected"
19 plugins_found=$(mktemp)
20 sort -u "${foundPluginsFilePath}" > "$plugins_found"
21
22 if ! mismatches="$(diff -y "$plugins_expected" "$plugins_found")"; then
23 echo "The the list of expected plugins (left side) doesn't match" \
24 "the list of plugins we found (right side):" >&2
25 echo "$mismatches" >&2
26 exit 1
27 fi
28 '';
29
30}