diff options
Diffstat (limited to 'pkgs/build-support/testers/hasPkgConfigModules')
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModules/tester.nix | 34 | ||||
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModules/tests.nix | 20 |
2 files changed, 45 insertions, 9 deletions
diff --git a/pkgs/build-support/testers/hasPkgConfigModules/tester.nix b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix index bbcc4f0c0f710..3d4ded812f75e 100644 --- a/pkgs/build-support/testers/hasPkgConfigModules/tester.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix @@ -5,14 +5,16 @@ { package, moduleNames ? package.meta.pkgConfigModules, testName ? "check-pkg-config-${lib.concatStringsSep "-" moduleNames}", + version ? package.version or null, + versionCheck ? false, }: runCommand testName { nativeBuildInputs = [ pkg-config ]; buildInputs = [ package ]; - inherit moduleNames; + inherit moduleNames version versionCheck; meta = { - description = "Test whether ${package.name} exposes pkg-config modules ${lib.concatStringsSep ", " moduleNames}."; + description = "Test whether ${package.name} exposes pkg-config modules ${lib.concatStringsSep ", " moduleNames}"; } # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, # as hydra can't check this meta info in dependencies. @@ -31,20 +33,38 @@ runCommand testName { package.meta; } '' touch "$out" + notFound=0 + versionMismatch=0 for moduleName in $moduleNames; do echo "checking pkg-config module $moduleName in $buildInputs" set +e - version="$($PKG_CONFIG --modversion $moduleName)" + moduleVersion="$($PKG_CONFIG --modversion $moduleName)" r=$? set -e if [[ $r = 0 ]]; then - echo "✅ pkg-config module $moduleName exists and has version $version" + if [[ "$moduleVersion" == "$version" ]]; then + echo "✅ pkg-config module $moduleName exists and has version $moduleVersion" + else + echo "${if versionCheck then "❌" else "ℹ️"} pkg-config module $moduleName exists at version $moduleVersion != $version (drv version)" + ((versionMismatch+=1)) + fi printf '%s\t%s\n' "$moduleName" "$version" >> "$out" else - echo "These modules were available in the input propagation closure:" - $PKG_CONFIG --list-all echo "❌ pkg-config module $moduleName was not found" - false + ((notFound+=1)) fi done + + if [[ $notFound -eq 0 ]] && ([[ $versionMismatch -eq 0 ]] || [[ -z "$versionCheck" ]]); then + exit 0 + fi + if [[ $notFound -ne 0 ]]; then + echo "$notFound modules not found" + echo "These modules were available in the input propagation closure:" + $PKG_CONFIG --list-all + fi + if [[ $versionMismatch -ne 0 ]]; then + echo "$versionMismatch version mismatches" + fi + exit 1 '' diff --git a/pkgs/build-support/testers/hasPkgConfigModules/tests.nix b/pkgs/build-support/testers/hasPkgConfigModules/tests.nix index 96569498fb152..adad935079849 100644 --- a/pkgs/build-support/testers/hasPkgConfigModules/tests.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tests.nix @@ -1,9 +1,25 @@ # cd nixpkgs -# nix-build -A tests.testers.hasPkgConfigModule -{ lib, testers, zlib, openssl, runCommand }: +# nix-build -A tests.testers.hasPkgConfigModules +{ lib, testers, miniz, zlib, openssl, runCommand }: lib.recurseIntoAttrs { + miniz-versions-match = testers.hasPkgConfigModules { + package = miniz; + versionCheck = true; + }; + + miniz-versions-mismatch = testers.testBuildFailure (testers.hasPkgConfigModules { + package = miniz; + version = "1.2.3"; # Deliberately-incorrect version number + versionCheck = true; + }); + + miniz-no-versionCheck = testers.hasPkgConfigModules { + package = miniz; + version = "1.2.3"; # Deliberately-incorrect version number + }; + zlib-has-zlib = testers.hasPkgConfigModules { package = zlib; moduleNames = [ "zlib" ]; |