about summary refs log tree commit diff
path: root/pkgs/build-support/testers/hasPkgConfigModules/tester.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/testers/hasPkgConfigModules/tester.nix')
-rw-r--r--pkgs/build-support/testers/hasPkgConfigModules/tester.nix32
1 files changed, 26 insertions, 6 deletions
diff --git a/pkgs/build-support/testers/hasPkgConfigModules/tester.nix b/pkgs/build-support/testers/hasPkgConfigModules/tester.nix
index bbcc4f0c0f710..e9f246deaaf20 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 "${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
   ''