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 | |
parent | af8edf6d75e467f35c837fe705257fbe7dc27fea (diff) | |
parent | c150eb5e442d717fc43c9e3b4475b547b03ba67d (diff) |
Merge #307770: add optional version check in `testers.hasPkgConfigModules`
4 files changed, 51 insertions, 13 deletions
diff --git a/doc/languages-frameworks/pkg-config.section.md b/doc/languages-frameworks/pkg-config.section.md index e5a2b85b65769..0b25396314cbb 100644 --- a/doc/languages-frameworks/pkg-config.section.md +++ b/doc/languages-frameworks/pkg-config.section.md @@ -7,10 +7,11 @@ Nixpkgs provides a couple of facilities for working with this tool. ## Writing packages providing pkg-config modules {#pkg-config-writing-packages} Packages should set `meta.pkgConfigModules` with the list of package config modules they provide. -They should also use `testers.testMetaPkgConfig` to check that the final built package matches that list. +They should also use `testers.hasPkgConfigModules` to check that the final built package matches that list, +and optionally check that the pkgconf modules' version metadata matches the derivation's. Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules. -A good example of all these things is zlib: +A good example of all these things is miniz: ```nix { pkg-config, testers, ... }: @@ -20,11 +21,14 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ pkg-config validatePkgConfig ]; - passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + passthru.tests.pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; + versionCheck = true; + }; meta = { /* ... */ - pkgConfigModules = [ "zlib" ]; + pkgConfigModules = [ "miniz" ]; }; }) ``` 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" ]; diff --git a/pkgs/development/libraries/miniz/default.nix b/pkgs/development/libraries/miniz/default.nix index 0c4d902f40bb2..0cb5087c4f7a0 100644 --- a/pkgs/development/libraries/miniz/default.nix +++ b/pkgs/development/libraries/miniz/default.nix @@ -28,7 +28,10 @@ stdenv.mkDerivation (finalAttrs: { --replace-fail '=''${exec_prefix}//' '=/' ''; - passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + passthru.tests.pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; + versionCheck = true; + }; meta = with lib; { description = "Single C source file zlib-replacement library"; |