aboutsummaryrefslogtreecommitdiff
blob: 2d081d87d1e68ce77d437a22dd952803a29358c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright 2016-2018 Doug Goldstein <cardoe@cardoe.com>
 *
 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 * http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 * <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 * option. This file may not be copied, modified, or distributed
 * except according to those terms.
 */

use cargo_metadata::Package;
use itertools::Itertools;
use serde::Serialize;
use std::collections::BTreeSet;

#[derive(Serialize)]
pub struct EbuildConfig {
    pub name: String,
    pub version: String,
    pub inherit: Option<String>,
    pub homepage: String,
    pub description: String,
    pub license: String,
    pub restrict: Option<String>,
    pub slot: Option<String>,
    pub keywords: Option<String>,
    pub iuse: Option<String>,
    pub depend: Option<String>,
    pub rdepend: Option<String>,
    pub pdepend: Option<String>,
    pub depend_is_rdepend: bool,
    pub crates: Vec<String>,
}

impl EbuildConfig {
    pub fn from_package(package: Package, crates: Vec<String>, licenses: BTreeSet<String>) -> Self {
        // package description
        let desc = package
            .description
            .as_ref()
            .cloned()
            .unwrap_or_else(|| package.name.clone());

        // package homepage
        let homepage = package.repository.unwrap_or_else(|| {
            String::from("homepage field in Cargo.toml inaccessible to cargo metadata")
        });

        EbuildConfig {
            name: package.name,
            version: package.version.to_string(),
            inherit: None,
            homepage,
            description: desc,
            license: licenses.iter().format(" ").to_string(),
            restrict: None,
            slot: None,
            keywords: None,
            iuse: None,
            depend: None,
            rdepend: None,
            pdepend: None,
            depend_is_rdepend: true,
            crates,
        }
    }
}