From 6710bc250a090c01da8659787e96aaea3df9ad32 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 12 Oct 2023 00:35:20 +0200 Subject: [PATCH] tests.nixpkgs-check-by-name: Minor refactor Allows a smaller diff for future changes --- pkgs/test/nixpkgs-check-by-name/src/eval.nix | 22 +++++++-------- pkgs/test/nixpkgs-check-by-name/src/eval.rs | 29 ++++++++++++++------ 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 378ecef46b57..087b0a519c71 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 17e22495b22a..458986a687a0 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, + variant: AttributeVariant, is_derivation: bool, } +#[derive(Deserialize)] +enum AttributeVariant { + /// The attribute is defined as a pkgs.callPackage + /// The path is None when the argument isn't a path + CallPackage { path: Option }, + /// 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( 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()