nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# Static arguments
2{
3 lib,
4 runCommand,
5 pkg-config,
6}:
7
8# Tester arguments
9{
10 package,
11 moduleNames ? package.meta.pkgConfigModules,
12 testName ? "check-pkg-config-${package.pname or package.name}",
13 version ? package.version or null,
14 versionCheck ? false,
15}:
16
17runCommand testName
18 {
19 nativeBuildInputs = [ pkg-config ];
20 buildInputs = [ package ];
21 inherit moduleNames version versionCheck;
22 meta = {
23 description = "Test whether ${package.name} exposes pkg-config modules ${lib.concatStringsSep ", " moduleNames}";
24 }
25 # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org,
26 # as hydra can't check this meta info in dependencies.
27 # The test itself is just Nixpkgs, with MIT license.
28 // builtins.intersectAttrs {
29 available = throw "unused";
30 broken = throw "unused";
31 insecure = throw "unused";
32 license = throw "unused";
33 maintainers = throw "unused";
34 teams = throw "unused";
35 platforms = throw "unused";
36 unfree = throw "unused";
37 unsupported = throw "unused";
38 } package.meta;
39 }
40 ''
41 touch "$out"
42 notFound=0
43 versionMismatch=0
44 for moduleName in $moduleNames; do
45 echo "checking pkg-config module $moduleName in $buildInputs"
46 set +e
47 moduleVersion="$($PKG_CONFIG --modversion $moduleName)"
48 r=$?
49 set -e
50 if [[ $r = 0 ]]; then
51 if [[ "$moduleVersion" == "$version" ]]; then
52 echo "✅ pkg-config module $moduleName exists and has version $moduleVersion"
53 else
54 echo "${
55 if versionCheck then "❌" else "ℹ️"
56 } pkg-config module $moduleName exists at version $moduleVersion != $version (drv version)"
57 ((versionMismatch+=1))
58 fi
59 printf '%s\t%s\n' "$moduleName" "$version" >> "$out"
60 else
61 echo "❌ pkg-config module $moduleName was not found"
62 ((notFound+=1))
63 fi
64 done
65
66 if [[ $notFound -eq 0 ]] && ([[ $versionMismatch -eq 0 ]] || [[ -z "$versionCheck" ]]); then
67 exit 0
68 fi
69 if [[ $notFound -ne 0 ]]; then
70 echo "$notFound modules not found"
71 echo "These modules were available in the input propagation closure:"
72 $PKG_CONFIG --list-all
73 fi
74 if [[ $versionMismatch -ne 0 ]]; then
75 echo "$versionMismatch version mismatches"
76 fi
77 exit 1
78 ''