Take meta.badPlatforms into account (#580)

This commit is contained in:
Naïm Favier 2022-12-06 23:30:58 +01:00 committed by GitHub
parent 66162e9896
commit 3a12920489
Failed to generate hash of commit
4 changed files with 27 additions and 48 deletions

View file

@ -2,6 +2,7 @@
/// Additionally, we implement converseions from the two possible input formats, i.e. /// Additionally, we implement converseions from the two possible input formats, i.e.
/// Flakes, or Nixpkgs. /// Flakes, or Nixpkgs.
use std::{ use std::{
collections::HashSet,
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
path::PathBuf, path::PathBuf,
}; };
@ -11,7 +12,6 @@ use serde::{Deserialize, Serialize};
use super::{ use super::{
import::{self, DocString, DocValue, ModulePath, NixOption}, import::{self, DocString, DocValue, ModulePath, NixOption},
pandoc::PandocExt, pandoc::PandocExt,
system::System,
utility::{AttributeQuery, Flatten, OneOrMany, Reverse}, utility::{AttributeQuery, Flatten, OneOrMany, Reverse},
}; };
@ -65,7 +65,7 @@ pub enum Derivation {
package_pname: String, package_pname: String,
package_pname_reverse: Reverse<String>, package_pname_reverse: Reverse<String>,
package_pversion: String, package_pversion: String,
package_platforms: Vec<System>, package_platforms: Vec<String>,
package_outputs: Vec<String>, package_outputs: Vec<String>,
package_default_output: Option<String>, package_default_output: Option<String>,
package_license: Vec<License>, package_license: Vec<License>,
@ -84,7 +84,7 @@ pub enum Derivation {
#[serde(rename = "app")] #[serde(rename = "app")]
App { App {
app_attr_name: String, app_attr_name: String,
app_platforms: Vec<System>, app_platforms: Vec<String>,
app_type: Option<String>, app_type: Option<String>,
@ -213,8 +213,7 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
let package_license: Vec<License> = package let package_license: Vec<License> = package
.meta .meta
.license .license
.map(OneOrMany::into_list) .map_or(Default::default(), OneOrMany::into_list)
.unwrap_or_default()
.into_iter() .into_iter()
.map(|sos| sos.0.into()) .map(|sos| sos.0.into())
.collect(); .collect();
@ -224,6 +223,23 @@ 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
.meta
.platforms
.map_or(Default::default(), Flatten::flatten)
.into_iter()
.collect();
let bad_platforms: HashSet<String> = package
.meta
.bad_platforms
.map_or(Default::default(), Flatten::flatten)
.into_iter()
.collect();
let platforms: Vec<String> =
platforms.difference(&bad_platforms).cloned().collect();
let package_maintainers: Vec<Maintainer> = package let package_maintainers: Vec<Maintainer> = package
.meta .meta
.maintainers .maintainers
@ -261,11 +277,7 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
package_pname: package.pname.clone(), package_pname: package.pname.clone(),
package_pname_reverse: Reverse(package.pname), package_pname_reverse: Reverse(package.pname),
package_pversion: package.version, package_pversion: package.version,
package_platforms: package package_platforms: platforms,
.meta
.platforms
.map(Flatten::flatten)
.unwrap_or_default(),
package_outputs: package.outputs.into_keys().collect(), package_outputs: package.outputs.into_keys().collect(),
package_default_output: package.default_output, package_default_output: package.default_output,
package_license, package_license,

View file

@ -11,7 +11,6 @@ use serde_json::Value;
use super::pandoc::PandocExt; use super::pandoc::PandocExt;
use super::prettyprint::print_value; use super::prettyprint::print_value;
use super::system::System;
use super::utility::{Flatten, OneOrMany}; use super::utility::{Flatten, OneOrMany};
/// Holds information about a specific derivation /// Holds information about a specific derivation
@ -27,7 +26,7 @@ pub enum FlakeEntry {
attribute_name: String, attribute_name: String,
name: String, name: String,
version: String, version: String,
platforms: Vec<System>, platforms: Vec<String>,
outputs: Vec<String>, outputs: Vec<String>,
default_output: String, default_output: String,
description: Option<String>, description: Option<String>,
@ -37,7 +36,7 @@ pub enum FlakeEntry {
App { App {
bin: Option<PathBuf>, bin: Option<PathBuf>,
attribute_name: String, attribute_name: String,
platforms: Vec<System>, platforms: Vec<String>,
app_type: Option<String>, app_type: Option<String>,
}, },
/// an option defined in a module of a flake /// an option defined in a module of a flake
@ -189,7 +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<System>>, pub platforms: Option<Flatten<String>>,
#[serde(rename = "badPlatforms")]
pub bad_platforms: Option<Flatten<String>>,
pub position: Option<String>, pub position: Option<String>,
pub description: Option<String>, pub description: Option<String>,
#[serde(rename = "longDescription")] #[serde(rename = "longDescription")]

View file

@ -4,7 +4,6 @@ pub mod import;
mod pandoc; mod pandoc;
mod prettyprint; mod prettyprint;
mod source; mod source;
mod system;
mod utility; mod utility;
pub use export::Export; pub use export::Export;

View file

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