flake-info: support platform patterns (#602)

...for some value of "support". For now, just skip them without causing
an error. Later, maybe figure out a way to display them properly.

An example of a pattern is `lib.systems.inspect.patterns.isGnu`.

Co-authored-by: Rok Garbas <rok@garbas.si>
This commit is contained in:
Naïm Favier 2023-01-27 18:37:52 +01:00 committed by GitHub
parent be9a717b80
commit 9e5ff1ceec
Failed to generate hash of commit
3 changed files with 44 additions and 15 deletions

View file

@ -202,19 +202,11 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
.map(|l: &License| l.fullName.to_owned()) .map(|l: &License| l.fullName.to_owned())
.collect(); .collect();
let platforms: HashSet<String> = package let platforms: HashSet<String> =
.meta package.meta.platforms.unwrap_or_default().collect();
.platforms
.map_or(Default::default(), Flatten::flatten)
.into_iter()
.collect();
let bad_platforms: HashSet<String> = package let bad_platforms: HashSet<String> =
.meta package.meta.bad_platforms.unwrap_or_default().collect();
.bad_platforms
.map_or(Default::default(), Flatten::flatten)
.into_iter()
.collect();
let platforms: Vec<String> = let platforms: Vec<String> =
platforms.difference(&bad_platforms).cloned().collect(); platforms.difference(&bad_platforms).cloned().collect();

View file

@ -188,9 +188,9 @@ pub struct Meta {
pub license: Option<OneOrMany<StringOrStruct<License>>>, pub license: Option<OneOrMany<StringOrStruct<License>>>,
pub maintainers: Option<Flatten<Maintainer>>, pub maintainers: Option<Flatten<Maintainer>>,
pub homepage: Option<OneOrMany<String>>, pub homepage: Option<OneOrMany<String>>,
pub platforms: Option<Flatten<String>>, pub platforms: Option<Platforms>,
#[serde(rename = "badPlatforms")] #[serde(rename = "badPlatforms")]
pub bad_platforms: Option<Flatten<String>>, pub bad_platforms: Option<Platforms>,
pub position: Option<String>, pub position: Option<String>,
pub description: Option<String>, pub description: Option<String>,
#[serde(rename = "longDescription")] #[serde(rename = "longDescription")]
@ -252,6 +252,36 @@ where
} }
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Platform {
System(String),
Pattern {}, // TODO how should those be displayed?
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Platforms(Flatten<Platform>);
impl Platforms {
// A bit of abstract nonsense: what we really want is
// into_iter : Platforms → ∃ (I : Iterator<String>). I
// however Rust makes this annoying to write: we would either have to pick a
// concrete iterator type or use something like Box<dyn Iterator<Item = String>>.
// Instead, we can use the dual Church-encoded form of that existential type:
// ? : Platforms → ∀ B. (∀ (I : Iterator<String>). I → B) → B
// ...which is exactly the type of collect! (think about what FromIterator means)
pub fn collect<B: std::iter::FromIterator<String>>(self) -> B {
self.0
.flatten()
.into_iter()
.flat_map(|p| match p {
Platform::System(s) => Some(s),
_ => None,
})
.collect()
}
}
/// Different representations of the licence attribute /// Different representations of the licence attribute
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
@ -388,7 +418,8 @@ mod tests {
"powerpc64-linux", "powerpc64-linux",
"powerpc64le-linux", "powerpc64le-linux",
"riscv32-linux", "riscv32-linux",
"riscv64-linux" "riscv64-linux",
{}
], ],
"position": "/nix/store/97lxf2n6zip41j5flbv6b0928mxv9za8-nixpkgs-unstable-21.03pre268853.d9c6f13e13f/nixpkgs-unstable/pkgs/games/0verkill/default.nix:34", "position": "/nix/store/97lxf2n6zip41j5flbv6b0928mxv9za8-nixpkgs-unstable-21.03pre268853.d9c6f13e13f/nixpkgs-unstable/pkgs/games/0verkill/default.nix:34",
"unfree": false, "unfree": false,

View file

@ -39,6 +39,12 @@ impl<T: Clone> Flatten<T> {
} }
} }
impl<T> Default for Flatten<T> {
fn default() -> Self {
Flatten::Deep(Vec::new())
}
}
// TODO: use this or a to_ist function? // TODO: use this or a to_ist function?
/// Serialization helper that serializes single elements as a list with a single /// Serialization helper that serializes single elements as a list with a single
/// item /// item