diff --git a/doc/builders/testers.chapter.md b/doc/builders/testers.chapter.md index fb6a28b7ee4b..b2a581c3dd8d 100644 --- a/doc/builders/testers.chapter.md +++ b/doc/builders/testers.chapter.md @@ -1,17 +1,31 @@ # Testers {#chap-testers} This chapter describes several testing builders which are available in the `testers` namespace. -## `hasPkgConfigModule` {#tester-hasPkgConfigModule} +## `hasPkgConfigModules` {#tester-hasPkgConfigModules} -Checks whether a package exposes a certain `pkg-config` module. + +[]{#tester-hasPkgConfigModule} +Checks whether a package exposes a given list of `pkg-config` modules. +If the `moduleNames` argument is omitted, `hasPkgConfigModules` will +use `meta.pkgConfigModules`. Example: ```nix -passthru.tests.pkg-config = testers.hasPkgConfigModule { +passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; - moduleName = "libfoo"; -} + moduleNames = [ "libfoo" ]; +}; +``` + +If the package in question has `meta.pkgConfigModules` set, it is even simpler: + +```nix +passthru.tests.pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; +}; + +meta.pkgConfigModules = [ "libfoo" ]; ``` ## `testVersion` {#tester-testVersion} diff --git a/pkgs/applications/networking/pjsip/default.nix b/pkgs/applications/networking/pjsip/default.nix index 9c1b8e4f2617..4ed0bad26c6f 100644 --- a/pkgs/applications/networking/pjsip/default.nix +++ b/pkgs/applications/networking/pjsip/default.nix @@ -102,9 +102,8 @@ stdenv.mkDerivation (finalAttrs: { command = "pjsua --version"; }; - passthru.tests.pkg-config = testers.hasPkgConfigModule { + passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; - moduleName = "libpjproject"; }; passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } '' @@ -118,5 +117,8 @@ stdenv.mkDerivation (finalAttrs: { maintainers = with maintainers; [ olynch ]; mainProgram = "pjsua"; platforms = platforms.linux ++ platforms.darwin; + pkgConfigModules = [ + "libpjproject" + ]; }; }) diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index d380dc6f30e1..3ff52ed0178c 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -1,4 +1,4 @@ -{ pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, }: +{ pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }: # Documentation is in doc/builders/testers.chapter.md { # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure @@ -137,7 +137,14 @@ in nixosTesting.simpleTest calledTest; - hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { }; + hasPkgConfigModule = + { moduleName, ... }@args: + lib.warn "testers.hasPkgConfigModule has been deprecated in favor of testers.hasPkgConfigModules. It accepts a list of strings via the moduleNames argument instead of a single moduleName." ( + testers.hasPkgConfigModules (builtins.removeAttrs args [ "moduleName" ] // { + moduleNames = [ moduleName ]; + }) + ); + hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { }; testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { }; } diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tester.nix b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix similarity index 50% rename from pkgs/build-support/testers/hasPkgConfigModule/tester.nix rename to pkgs/build-support/testers/hasPkgConfigModules/tester.nix index c8342cdd5c3b..755559038271 100644 --- a/pkgs/build-support/testers/hasPkgConfigModule/tester.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix @@ -1,18 +1,18 @@ # Static arguments -{ runCommand, pkg-config }: +{ lib, runCommand, pkg-config }: # Tester arguments { package, - moduleName, - testName ? "check-pkg-config-${moduleName}", + moduleNames ? package.meta.pkgConfigModules, + testName ? "check-pkg-config-${lib.concatStringsSep "-" moduleNames}", }: runCommand testName { nativeBuildInputs = [ pkg-config ]; buildInputs = [ package ]; - inherit moduleName; + inherit moduleNames; meta = { - description = "Test whether ${package.name} exposes pkg-config module ${moduleName}"; + 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. @@ -30,18 +30,20 @@ runCommand testName { } package.meta; } '' - echo "checking pkg-config module $moduleName in $buildInputs" - set +e - version="$(pkg-config --modversion $moduleName)" - r=$? - set -e - if [[ $r = 0 ]]; then - echo "✅ pkg-config module $moduleName exists and has version $version" - echo "$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 - fi + for moduleName in $moduleNames; do + echo "checking pkg-config module $moduleName in $buildInputs" + set +e + version="$(pkg-config --modversion $moduleName)" + r=$? + set -e + if [[ $r = 0 ]]; then + echo "✅ pkg-config module $moduleName exists and has version $version" + 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 + fi + done '' diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tests.nix b/pkgs/build-support/testers/hasPkgConfigModules/tests.nix similarity index 59% rename from pkgs/build-support/testers/hasPkgConfigModule/tests.nix rename to pkgs/build-support/testers/hasPkgConfigModules/tests.nix index 8005c3f93709..96569498fb15 100644 --- a/pkgs/build-support/testers/hasPkgConfigModule/tests.nix +++ b/pkgs/build-support/testers/hasPkgConfigModules/tests.nix @@ -1,19 +1,32 @@ # cd nixpkgs # nix-build -A tests.testers.hasPkgConfigModule -{ lib, testers, zlib, runCommand }: +{ lib, testers, zlib, openssl, runCommand }: lib.recurseIntoAttrs { - zlib-has-zlib = testers.hasPkgConfigModule { + zlib-has-zlib = testers.hasPkgConfigModules { package = zlib; - moduleName = "zlib"; + moduleNames = [ "zlib" ]; + }; + + zlib-has-meta-pkgConfigModules = testers.hasPkgConfigModules { + package = zlib; + }; + + openssl-has-openssl = testers.hasPkgConfigModules { + package = openssl; + moduleNames = [ "openssl" ]; + }; + + openssl-has-all-meta-pkgConfigModules = testers.hasPkgConfigModules { + package = openssl; }; zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" { failed = testers.testBuildFailure ( - testers.hasPkgConfigModule { + testers.hasPkgConfigModules { package = zlib; - moduleName = "ylib"; + moduleNames = [ "ylib" ]; } ); } '' diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix index fc4df4964f39..c48c9f299ebf 100644 --- a/pkgs/build-support/testers/test/default.nix +++ b/pkgs/build-support/testers/test/default.nix @@ -12,7 +12,7 @@ let in lib.recurseIntoAttrs { - hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { }; + hasPkgConfigModules = pkgs.callPackage ../hasPkgConfigModules/tests.nix { }; runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: { name = "runNixOSTest-test"; diff --git a/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix b/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix index 108a2b67504f..69ec5a0f09c1 100644 --- a/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix +++ b/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix @@ -40,7 +40,7 @@ let else if pkg.meta.broken then null - else testers.hasPkgConfigModule { inherit moduleName; package = pkg; }; + else testers.hasPkgConfigModules { moduleNames = [ moduleName ]; package = pkg; }; in lib.recurseIntoAttrs allTests // { inherit tests-combined; }