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.
/// 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<String>,
package_pversion: String,
package_platforms: Vec<System>,
package_platforms: Vec<String>,
package_outputs: Vec<String>,
package_default_output: Option<String>,
package_license: Vec<License>,
@ -84,7 +84,7 @@ pub enum Derivation {
#[serde(rename = "app")]
App {
app_attr_name: String,
app_platforms: Vec<System>,
app_platforms: Vec<String>,
app_type: Option<String>,
@ -213,8 +213,7 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
let package_license: Vec<License> = 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<import::NixpkgsEntry> for Derivation {
.map(|l: &License| l.fullName.to_owned())
.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
.meta
.maintainers
@ -261,11 +277,7 @@ impl TryFrom<import::NixpkgsEntry> 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,

View file

@ -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<System>,
platforms: Vec<String>,
outputs: Vec<String>,
default_output: String,
description: Option<String>,
@ -37,7 +36,7 @@ pub enum FlakeEntry {
App {
bin: Option<PathBuf>,
attribute_name: String,
platforms: Vec<System>,
platforms: Vec<String>,
app_type: Option<String>,
},
/// an option defined in a module of a flake
@ -189,7 +188,9 @@ pub struct Meta {
pub license: Option<OneOrMany<StringOrStruct<License>>>,
pub maintainers: Option<Flatten<Maintainer>>,
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 description: Option<String>,
#[serde(rename = "longDescription")]

View file

@ -4,7 +4,6 @@ pub mod import;
mod pandoc;
mod prettyprint;
mod source;
mod system;
mod utility;
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,
}