tests.nixpkgs-check-by-name: Minor refactor

Allows a smaller diff for future changes
This commit is contained in:
Silvan Mosberger 2023-10-12 00:35:20 +02:00
parent 21d520fbf2
commit 6710bc250a
2 changed files with 32 additions and 19 deletions

View File

@ -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;
};

View File

@ -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()