mod dependency;
mod error;
mod parse;
#[cfg(test)]
mod tests;
use std::collections::BTreeMap;
use std::path::Path;
pub use dependency::{Dependency, Revision};
pub use error::ManifestError;
use semver::{Version, VersionReq};
pub const MANIFEST_FILE_NAME: &str = "xidl.toml";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Manifest {
name: String,
version: Version,
files: Option<Vec<String>>,
exclude: Vec<String>,
compiler: Option<VersionReq>,
dependencies: BTreeMap<String, Dependency>,
}
impl Manifest {
pub fn load(path: &Path) -> Result<Self, ManifestError> {
let text = std::fs::read_to_string(path).map_err(|source| ManifestError::Read {
path: path.to_path_buf(),
source,
})?;
Self::parse(path, &text)
}
pub fn parse(path: &Path, text: &str) -> Result<Self, ManifestError> {
parse::from_str(path, text)
}
pub fn name(&self) -> &str {
&self.name
}
pub fn version(&self) -> &Version {
&self.version
}
pub fn files(&self) -> Option<&[String]> {
self.files.as_deref()
}
pub fn exclude(&self) -> &[String] {
&self.exclude
}
pub fn compiler(&self) -> Option<&VersionReq> {
self.compiler.as_ref()
}
pub fn dependencies(&self) -> &BTreeMap<String, Dependency> {
&self.dependencies
}
pub fn accepts_compiler(&self, version: &Version) -> bool {
self.compiler
.as_ref()
.is_none_or(|required| required.matches(version))
}
}