testers.hasPkgConfigModules: allow checking multiple pkg-config mods

This is very useful in conjunction with meta.pkgConfigModules, as the
new tester can use the list provided by this meta attribute as a default
value for moduleNames, making its usage in passthru.tests very
convenient.

For backwards compatibility, a shim under the old name is maintained
with a warning.

+101 -63
+19 -5
doc/builders/testers.chapter.md
··· 1 1 # Testers {#chap-testers} 2 2 This chapter describes several testing builders which are available in the `testers` namespace. 3 3 4 - ## `hasPkgConfigModule` {#tester-hasPkgConfigModule} 4 + ## `hasPkgConfigModules` {#tester-hasPkgConfigModules} 5 5 6 - Checks whether a package exposes a certain `pkg-config` module. 6 + <!-- Old anchor name so links still work --> 7 + []{#tester-hasPkgConfigModule} 8 + Checks whether a package exposes a given list of `pkg-config` modules. 9 + If the `moduleNames` argument is omitted, `hasPkgConfigModules` will 10 + use `meta.pkgConfigModules`. 7 11 8 12 Example: 9 13 10 14 ```nix 11 - passthru.tests.pkg-config = testers.hasPkgConfigModule { 15 + passthru.tests.pkg-config = testers.hasPkgConfigModules { 12 16 package = finalAttrs.finalPackage; 13 - moduleName = "libfoo"; 14 - } 17 + moduleNames = [ "libfoo" ]; 18 + }; 19 + ``` 20 + 21 + If the package in question has `meta.pkgConfigModules` set, it is even simpler: 22 + 23 + ```nix 24 + passthru.tests.pkg-config = testers.hasPkgConfigModules { 25 + package = finalAttrs.finalPackage; 26 + }; 27 + 28 + meta.pkgConfigModules = [ "libfoo" ]; 15 29 ``` 16 30 17 31 ## `testVersion` {#tester-testVersion}
+4 -2
pkgs/applications/networking/pjsip/default.nix
··· 102 102 command = "pjsua --version"; 103 103 }; 104 104 105 - passthru.tests.pkg-config = testers.hasPkgConfigModule { 105 + passthru.tests.pkg-config = testers.hasPkgConfigModules { 106 106 package = finalAttrs.finalPackage; 107 - moduleName = "libpjproject"; 108 107 }; 109 108 110 109 passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } '' ··· 118 117 maintainers = with maintainers; [ olynch ]; 119 118 mainProgram = "pjsua"; 120 119 platforms = platforms.linux ++ platforms.darwin; 120 + pkgConfigModules = [ 121 + "libpjproject" 122 + ]; 121 123 }; 122 124 })
+9 -2
pkgs/build-support/testers/default.nix
··· 1 - { pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, }: 1 + { pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }: 2 2 # Documentation is in doc/builders/testers.chapter.md 3 3 { 4 4 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure ··· 137 137 in 138 138 nixosTesting.simpleTest calledTest; 139 139 140 - hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { }; 140 + hasPkgConfigModule = 141 + { moduleName, ... }@args: 142 + 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." ( 143 + testers.hasPkgConfigModules (builtins.removeAttrs args [ "moduleName" ] // { 144 + moduleNames = [ moduleName ]; 145 + }) 146 + ); 147 + hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { }; 141 148 142 149 testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { }; 143 150 }
-47
pkgs/build-support/testers/hasPkgConfigModule/tester.nix
··· 1 - # Static arguments 2 - { runCommand, pkg-config }: 3 - 4 - # Tester arguments 5 - { package, 6 - moduleName, 7 - testName ? "check-pkg-config-${moduleName}", 8 - }: 9 - 10 - runCommand testName { 11 - nativeBuildInputs = [ pkg-config ]; 12 - buildInputs = [ package ]; 13 - inherit moduleName; 14 - meta = { 15 - description = "Test whether ${package.name} exposes pkg-config module ${moduleName}"; 16 - } 17 - # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, 18 - # as hydra can't check this meta info in dependencies. 19 - # The test itself is just Nixpkgs, with MIT license. 20 - // builtins.intersectAttrs 21 - { 22 - available = throw "unused"; 23 - broken = throw "unused"; 24 - insecure = throw "unused"; 25 - license = throw "unused"; 26 - maintainers = throw "unused"; 27 - platforms = throw "unused"; 28 - unfree = throw "unused"; 29 - unsupported = throw "unused"; 30 - } 31 - package.meta; 32 - } '' 33 - echo "checking pkg-config module $moduleName in $buildInputs" 34 - set +e 35 - version="$(pkg-config --modversion $moduleName)" 36 - r=$? 37 - set -e 38 - if [[ $r = 0 ]]; then 39 - echo "✅ pkg-config module $moduleName exists and has version $version" 40 - echo "$version" > $out 41 - else 42 - echo "These modules were available in the input propagation closure:" 43 - pkg-config --list-all 44 - echo "❌ pkg-config module $moduleName was not found" 45 - false 46 - fi 47 - ''
+18 -5
pkgs/build-support/testers/hasPkgConfigModule/tests.nix pkgs/build-support/testers/hasPkgConfigModules/tests.nix
··· 1 1 # cd nixpkgs 2 2 # nix-build -A tests.testers.hasPkgConfigModule 3 - { lib, testers, zlib, runCommand }: 3 + { lib, testers, zlib, openssl, runCommand }: 4 4 5 5 lib.recurseIntoAttrs { 6 6 7 - zlib-has-zlib = testers.hasPkgConfigModule { 7 + zlib-has-zlib = testers.hasPkgConfigModules { 8 8 package = zlib; 9 - moduleName = "zlib"; 9 + moduleNames = [ "zlib" ]; 10 + }; 11 + 12 + zlib-has-meta-pkgConfigModules = testers.hasPkgConfigModules { 13 + package = zlib; 14 + }; 15 + 16 + openssl-has-openssl = testers.hasPkgConfigModules { 17 + package = openssl; 18 + moduleNames = [ "openssl" ]; 19 + }; 20 + 21 + openssl-has-all-meta-pkgConfigModules = testers.hasPkgConfigModules { 22 + package = openssl; 10 23 }; 11 24 12 25 zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" { 13 26 failed = testers.testBuildFailure ( 14 - testers.hasPkgConfigModule { 27 + testers.hasPkgConfigModules { 15 28 package = zlib; 16 - moduleName = "ylib"; 29 + moduleNames = [ "ylib" ]; 17 30 } 18 31 ); 19 32 } ''
+49
pkgs/build-support/testers/hasPkgConfigModules/tester.nix
··· 1 + # Static arguments 2 + { lib, runCommand, pkg-config }: 3 + 4 + # Tester arguments 5 + { package, 6 + moduleNames ? package.meta.pkgConfigModules, 7 + testName ? "check-pkg-config-${lib.concatStringsSep "-" moduleNames}", 8 + }: 9 + 10 + runCommand testName { 11 + nativeBuildInputs = [ pkg-config ]; 12 + buildInputs = [ package ]; 13 + inherit moduleNames; 14 + meta = { 15 + description = "Test whether ${package.name} exposes pkg-config modules ${lib.concatStringsSep ", " moduleNames}."; 16 + } 17 + # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, 18 + # as hydra can't check this meta info in dependencies. 19 + # The test itself is just Nixpkgs, with MIT license. 20 + // builtins.intersectAttrs 21 + { 22 + available = throw "unused"; 23 + broken = throw "unused"; 24 + insecure = throw "unused"; 25 + license = throw "unused"; 26 + maintainers = throw "unused"; 27 + platforms = throw "unused"; 28 + unfree = throw "unused"; 29 + unsupported = throw "unused"; 30 + } 31 + package.meta; 32 + } '' 33 + for moduleName in $moduleNames; do 34 + echo "checking pkg-config module $moduleName in $buildInputs" 35 + set +e 36 + version="$(pkg-config --modversion $moduleName)" 37 + r=$? 38 + set -e 39 + if [[ $r = 0 ]]; then 40 + echo "✅ pkg-config module $moduleName exists and has version $version" 41 + printf '%s\t%s\n' "$moduleName" "$version" >> "$out" 42 + else 43 + echo "These modules were available in the input propagation closure:" 44 + pkg-config --list-all 45 + echo "❌ pkg-config module $moduleName was not found" 46 + false 47 + fi 48 + done 49 + ''
+1 -1
pkgs/build-support/testers/test/default.nix
··· 12 12 13 13 in 14 14 lib.recurseIntoAttrs { 15 - hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { }; 15 + hasPkgConfigModules = pkgs.callPackage ../hasPkgConfigModules/tests.nix { }; 16 16 17 17 runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: { 18 18 name = "runNixOSTest-test";
+1 -1
pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix
··· 40 40 else if pkg.meta.broken 41 41 then null 42 42 43 - else testers.hasPkgConfigModule { inherit moduleName; package = pkg; }; 43 + else testers.hasPkgConfigModules { moduleNames = [ moduleName ]; package = pkg; }; 44 44 45 45 in 46 46 lib.recurseIntoAttrs allTests // { inherit tests-combined; }