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
use crate::package::Package;
use serde_derive::Deserialize;
use std::collections::BTreeMap;
use std::path::Path;
use thiserror::Error;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ExternalPackageSource {
Prebuilt {
repo: String,
commit: String,
sha256: String,
},
Manual,
}
#[derive(Deserialize, Debug)]
pub struct ExternalPackage {
#[serde(flatten)]
pub package: Package,
pub source: ExternalPackageSource,
}
#[derive(Deserialize, Debug)]
pub struct Config {
#[serde(default, rename = "package")]
pub packages: BTreeMap<String, Package>,
#[serde(default, rename = "external_package")]
pub external_packages: BTreeMap<String, ExternalPackage>,
}
#[derive(Error, Debug)]
pub enum ParseError {
#[error("Cannot parse toml: {0}")]
Toml(#[from] toml::de::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
pub fn parse<P: AsRef<Path>>(path: P) -> Result<Config, ParseError> {
let contents = std::fs::read_to_string(path.as_ref())?;
let cfg = toml::from_str::<Config>(&contents)?;
Ok(cfg)
}