From 3a129204890ffb018f2f796f2f2cbdc85f5d0b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Tue, 6 Dec 2022 23:30:58 +0100 Subject: [PATCH] Take `meta.badPlatforms` into account (#580) --- flake-info/src/data/export.rs | 32 ++++++++++++++++++++++---------- flake-info/src/data/import.rs | 9 +++++---- flake-info/src/data/mod.rs | 1 - flake-info/src/data/system.rs | 33 --------------------------------- 4 files changed, 27 insertions(+), 48 deletions(-) delete mode 100644 flake-info/src/data/system.rs diff --git a/flake-info/src/data/export.rs b/flake-info/src/data/export.rs index f953814..f48c5ee 100644 --- a/flake-info/src/data/export.rs +++ b/flake-info/src/data/export.rs @@ -2,6 +2,7 @@ /// Additionally, we implement converseions from the two possible input formats, i.e. /// Flakes, or Nixpkgs. use std::{ + collections::HashSet, convert::{TryFrom, TryInto}, path::PathBuf, }; @@ -11,7 +12,6 @@ use serde::{Deserialize, Serialize}; use super::{ import::{self, DocString, DocValue, ModulePath, NixOption}, pandoc::PandocExt, - system::System, utility::{AttributeQuery, Flatten, OneOrMany, Reverse}, }; @@ -65,7 +65,7 @@ pub enum Derivation { package_pname: String, package_pname_reverse: Reverse, package_pversion: String, - package_platforms: Vec, + package_platforms: Vec, package_outputs: Vec, package_default_output: Option, package_license: Vec, @@ -84,7 +84,7 @@ pub enum Derivation { #[serde(rename = "app")] App { app_attr_name: String, - app_platforms: Vec, + app_platforms: Vec, app_type: Option, @@ -213,8 +213,7 @@ impl TryFrom for Derivation { let package_license: Vec = package .meta .license - .map(OneOrMany::into_list) - .unwrap_or_default() + .map_or(Default::default(), OneOrMany::into_list) .into_iter() .map(|sos| sos.0.into()) .collect(); @@ -224,6 +223,23 @@ impl TryFrom for Derivation { .map(|l: &License| l.fullName.to_owned()) .collect(); + let platforms: HashSet = package + .meta + .platforms + .map_or(Default::default(), Flatten::flatten) + .into_iter() + .collect(); + + let bad_platforms: HashSet = package + .meta + .bad_platforms + .map_or(Default::default(), Flatten::flatten) + .into_iter() + .collect(); + + let platforms: Vec = + platforms.difference(&bad_platforms).cloned().collect(); + let package_maintainers: Vec = package .meta .maintainers @@ -261,11 +277,7 @@ impl TryFrom for Derivation { package_pname: package.pname.clone(), package_pname_reverse: Reverse(package.pname), package_pversion: package.version, - package_platforms: package - .meta - .platforms - .map(Flatten::flatten) - .unwrap_or_default(), + package_platforms: platforms, package_outputs: package.outputs.into_keys().collect(), package_default_output: package.default_output, package_license, diff --git a/flake-info/src/data/import.rs b/flake-info/src/data/import.rs index 4e11c0a..eef11b3 100644 --- a/flake-info/src/data/import.rs +++ b/flake-info/src/data/import.rs @@ -11,7 +11,6 @@ use serde_json::Value; use super::pandoc::PandocExt; use super::prettyprint::print_value; -use super::system::System; use super::utility::{Flatten, OneOrMany}; /// Holds information about a specific derivation @@ -27,7 +26,7 @@ pub enum FlakeEntry { attribute_name: String, name: String, version: String, - platforms: Vec, + platforms: Vec, outputs: Vec, default_output: String, description: Option, @@ -37,7 +36,7 @@ pub enum FlakeEntry { App { bin: Option, attribute_name: String, - platforms: Vec, + platforms: Vec, app_type: Option, }, /// an option defined in a module of a flake @@ -189,7 +188,9 @@ pub struct Meta { pub license: Option>>, pub maintainers: Option>, pub homepage: Option>, - pub platforms: Option>, + pub platforms: Option>, + #[serde(rename = "badPlatforms")] + pub bad_platforms: Option>, pub position: Option, pub description: Option, #[serde(rename = "longDescription")] diff --git a/flake-info/src/data/mod.rs b/flake-info/src/data/mod.rs index 2915a92..a72de5d 100644 --- a/flake-info/src/data/mod.rs +++ b/flake-info/src/data/mod.rs @@ -4,7 +4,6 @@ pub mod import; mod pandoc; mod prettyprint; mod source; -mod system; mod utility; pub use export::Export; diff --git a/flake-info/src/data/system.rs b/flake-info/src/data/system.rs deleted file mode 100644 index 1ebe319..0000000 --- a/flake-info/src/data/system.rs +++ /dev/null @@ -1,33 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(untagged)] -pub enum System { - Plain(String), - Detailed { cpu: Cpu, kernel: Kernel }, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Cpu { - family: String, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Kernel { - name: String, -} - -impl ToString for System { - fn to_string(&self) -> String { - match self { - System::Plain(system) => system.to_owned(), - System::Detailed { cpu, kernel } => format!("{}-{}", cpu.family, kernel.name), - } - } -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct InstancePlatform { - system: System, - version: String, -}