diff options
author | nicoo <nicoo@debian.org> | 2024-05-03 20:18:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 20:18:56 +0000 |
commit | a817fdac5fea62e89332ea223c0a5ea8b6443341 (patch) | |
tree | 00f59fb834333852c997fb13d37273a0e84af78b /pkgs/build-support | |
parent | af8edf6d75e467f35c837fe705257fbe7dc27fea (diff) | |
parent | c150eb5e442d717fc43c9e3b4475b547b03ba67d (diff) |
Merge #307770: add optional version check in `testers.hasPkgConfigModules`
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModules/tester.nix | 32 | ||||
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModules/tests.nix | 15 |
2 files changed, 39 insertions, 8 deletions
diff --git a/pkgs/build-support/testers/hasPkgConfigModules/tester.nix b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix index bbcc4f0c0f710..b8ae884ba7b0f 100644 --- a/pkgs/build-support/testers/hasPkgConfigModules/tester.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix @@ -5,12 +5,14 @@ { 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}."; } @@ -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 "❌ pkg-config module $moduleName exists and has version $moduleVersion when $version was expected" + ((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 ]] || [[ "$versionCheck" == false ]]); 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..bf992d040b4b3 100644 --- a/pkgs/build-support/testers/hasPkgConfigModules/tests.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tests.nix @@ -1,9 +1,20 @@ # 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"; + versionCheck = true; + }); + zlib-has-zlib = testers.hasPkgConfigModules { package = zlib; moduleNames = [ "zlib" ]; |