about summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-10-12 00:35:20 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-10-12 02:27:02 +0200
commit6710bc250a090c01da8659787e96aaea3df9ad32 (patch)
tree116a6401cba7a5a9b40ad136a89107b9717dbcb7 /pkgs/test
parent21d520fbf202e84c80e32afc6b1377974335e4e4 (diff)
tests.nixpkgs-check-by-name: Minor refactor
Allows a smaller diff for future changes
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/nixpkgs-check-by-name/src/eval.nix22
-rw-r--r--pkgs/test/nixpkgs-check-by-name/src/eval.rs29
2 files changed, 32 insertions, 19 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.nix b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
index 378ecef46b57a..087b0a519c719 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/eval.nix
+++ b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
@@ -18,19 +18,23 @@ let
     callPackage = fn: args:
       let
         result = super.callPackage fn args;
+        variantInfo._attributeVariant = {
+          # These names are used by the deserializer on the Rust side
+          CallPackage.path =
+            if builtins.isPath fn then
+              toString fn
+            else
+              null;
+        };
       in
       if builtins.isAttrs result then
         # If this was the last overlay to be applied, we could just only return the `_callPackagePath`,
         # but that's not the case because stdenv has another overlays on top of user-provided ones.
         # So to not break the stdenv build we need to return the mostly proper result here
-        result // {
-          _callPackagePath = fn;
-        }
+        result // variantInfo
       else
         # It's very rare that callPackage doesn't return an attribute set, but it can occur.
-        {
-          _callPackagePath = fn;
-        };
+        variantInfo;
   };
 
   pkgs = import nixpkgsPath {
@@ -45,11 +49,7 @@ let
     in
     {
     # These names are used by the deserializer on the Rust side
-    call_package_path =
-      if value ? _callPackagePath && builtins.isPath value._callPackagePath then
-        toString value._callPackagePath
-      else
-        null;
+    variant = value._attributeVariant or { Other = null; };
     is_derivation = pkgs.lib.isDerivation value;
   };
 
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.rs b/pkgs/test/nixpkgs-check-by-name/src/eval.rs
index 17e22495b22ad..458986a687a03 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/eval.rs
+++ b/pkgs/test/nixpkgs-check-by-name/src/eval.rs
@@ -13,10 +13,19 @@ use tempfile::NamedTempFile;
 /// Attribute set of this structure is returned by eval.nix
 #[derive(Deserialize)]
 struct AttributeInfo {
-    call_package_path: Option<PathBuf>,
+    variant: AttributeVariant,
     is_derivation: bool,
 }
 
+#[derive(Deserialize)]
+enum AttributeVariant {
+    /// The attribute is defined as a pkgs.callPackage <path>
+    /// The path is None when the <path> argument isn't a path
+    CallPackage { path: Option<PathBuf> },
+    /// The attribute is not defined as pkgs.callPackage
+    Other,
+}
+
 const EXPR: &str = include_str!("eval.nix");
 
 /// Check that the Nixpkgs attribute values corresponding to the packages in pkgs/by-name are
@@ -97,14 +106,18 @@ pub fn check_values<W: io::Write>(
         let absolute_package_file = nixpkgs.path.join(&relative_package_file);
 
         if let Some(attribute_info) = actual_files.get(package_name) {
-            let is_expected_file =
-                if let Some(call_package_path) = &attribute_info.call_package_path {
-                    absolute_package_file == *call_package_path
-                } else {
-                    false
-                };
+            let valid = match &attribute_info.variant {
+                AttributeVariant::CallPackage { path } => {
+                    if let Some(call_package_path) = path {
+                        absolute_package_file == *call_package_path
+                    } else {
+                        false
+                    }
+                }
+                AttributeVariant::Other => false,
+            };
 
-            if !is_expected_file {
+            if !valid {
                 error_writer.write(&format!(
                     "pkgs.{package_name}: This attribute is not defined as `pkgs.callPackage {} {{ ... }}`.",
                     relative_package_file.display()