tests.nixpkgs-check-by-name: Basic info for non-by-name attributes
In a future commit this will be extended
This commit is contained in:
parent
da3e72b915
commit
69fc71a82c
@ -79,15 +79,26 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
attrInfos = map (name: [
|
||||
byNameAttrs = map (name: [
|
||||
name
|
||||
(
|
||||
if ! pkgs ? ${name} then
|
||||
{ Missing = null; }
|
||||
else
|
||||
{ Existing = attrInfo name pkgs.${name}; }
|
||||
)
|
||||
{
|
||||
ByName =
|
||||
if ! pkgs ? ${name} then
|
||||
{ Missing = null; }
|
||||
else
|
||||
{ Existing = attrInfo name pkgs.${name}; };
|
||||
}
|
||||
]) attrs;
|
||||
|
||||
# Information on all attributes that exist but are not in pkgs/by-name.
|
||||
# We need this to enforce pkgs/by-name for new packages
|
||||
nonByNameAttrs = map (name:
|
||||
[
|
||||
name
|
||||
{
|
||||
NonByName = null;
|
||||
}
|
||||
]
|
||||
) (builtins.attrNames (builtins.removeAttrs pkgs attrs));
|
||||
in
|
||||
attrInfos
|
||||
byNameAttrs ++ nonByNameAttrs
|
||||
|
@ -11,6 +11,14 @@ use std::process;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
/// Attribute set of this structure is returned by eval.nix
|
||||
#[derive(Deserialize)]
|
||||
enum Attribute {
|
||||
/// An attribute that should be defined via pkgs/by-name
|
||||
ByName(ByNameAttribute),
|
||||
/// An attribute not defined via pkgs/by-name
|
||||
NonByName,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
enum ByNameAttribute {
|
||||
/// The attribute doesn't exist at all
|
||||
@ -120,7 +128,7 @@ pub fn check_values(
|
||||
anyhow::bail!("Failed to run command {command:?}");
|
||||
}
|
||||
// Parse the resulting JSON value
|
||||
let attributes: Vec<(String, ByNameAttribute)> = serde_json::from_slice(&result.stdout)
|
||||
let attributes: Vec<(String, Attribute)> = serde_json::from_slice(&result.stdout)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to deserialise {}",
|
||||
@ -133,30 +141,34 @@ pub fn check_values(
|
||||
let relative_package_file = structure::relative_file_for_package(&attribute_name);
|
||||
|
||||
use ratchet::RatchetState::*;
|
||||
use Attribute::*;
|
||||
use AttributeInfo::*;
|
||||
use ByNameAttribute::*;
|
||||
use CallPackageVariant::*;
|
||||
|
||||
let check_result = match attribute_value {
|
||||
Missing => NixpkgsProblem::UndefinedAttr {
|
||||
NonByName => Success(ratchet::Package {
|
||||
empty_non_auto_called: Tight,
|
||||
}),
|
||||
ByName(Missing) => NixpkgsProblem::UndefinedAttr {
|
||||
relative_package_file: relative_package_file.clone(),
|
||||
package_name: attribute_name.clone(),
|
||||
}
|
||||
.into(),
|
||||
Existing(NonAttributeSet) => NixpkgsProblem::NonDerivation {
|
||||
ByName(Existing(NonAttributeSet)) => NixpkgsProblem::NonDerivation {
|
||||
relative_package_file: relative_package_file.clone(),
|
||||
package_name: attribute_name.clone(),
|
||||
}
|
||||
.into(),
|
||||
Existing(NonCallPackage) => NixpkgsProblem::WrongCallPackage {
|
||||
ByName(Existing(NonCallPackage)) => NixpkgsProblem::WrongCallPackage {
|
||||
relative_package_file: relative_package_file.clone(),
|
||||
package_name: attribute_name.clone(),
|
||||
}
|
||||
.into(),
|
||||
Existing(CallPackage(CallPackageInfo {
|
||||
ByName(Existing(CallPackage(CallPackageInfo {
|
||||
is_derivation,
|
||||
call_package_variant,
|
||||
})) => {
|
||||
}))) => {
|
||||
let check_result = if !is_derivation {
|
||||
NixpkgsProblem::NonDerivation {
|
||||
relative_package_file: relative_package_file.clone(),
|
||||
@ -203,7 +215,7 @@ pub fn check_values(
|
||||
));
|
||||
|
||||
Ok(check_result.map(|elems| ratchet::Nixpkgs {
|
||||
package_names,
|
||||
package_names: elems.iter().map(|(name, _)| name.to_owned()).collect(),
|
||||
package_map: elems.into_iter().collect(),
|
||||
}))
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use std::collections::HashMap;
|
||||
/// The ratchet value for the entirety of Nixpkgs.
|
||||
#[derive(Default)]
|
||||
pub struct Nixpkgs {
|
||||
/// Sorted list of attributes in package_map
|
||||
/// Sorted list of packages in package_map
|
||||
pub package_names: Vec<String>,
|
||||
/// The ratchet values for all packages
|
||||
pub package_map: HashMap<String, Package>,
|
||||
@ -29,14 +29,14 @@ impl Nixpkgs {
|
||||
}
|
||||
}
|
||||
|
||||
/// The ratchet value for a single package in `pkgs/by-name`
|
||||
/// The ratchet value for a top-level package
|
||||
pub struct Package {
|
||||
/// The ratchet value for the check for non-auto-called empty arguments
|
||||
pub empty_non_auto_called: RatchetState<EmptyNonAutoCalled>,
|
||||
}
|
||||
|
||||
impl Package {
|
||||
/// Validates the ratchet checks for a single package defined in `pkgs/by-name`
|
||||
/// Validates the ratchet checks for a top-level package
|
||||
pub fn compare(name: &str, optional_from: Option<&Self>, to: &Self) -> Validation<()> {
|
||||
RatchetState::<EmptyNonAutoCalled>::compare(
|
||||
name,
|
||||
|
Loading…
Reference in New Issue
Block a user