crossbundle_tools/commands/common/
parse_manifest.rs

1use crate::error::*;
2use cargo::{
3    core::{EitherManifest, Manifest, SourceId},
4    util::toml::read_manifest,
5    Config,
6};
7use std::path::Path;
8
9/// Read manifest files and deserialize it
10pub fn parse_manifest(manifest_path: &Path) -> Result<Manifest> {
11    let source_id = SourceId::for_path(manifest_path)?;
12    let cargo_config = Config::default()?;
13    let either_manifest = read_manifest(manifest_path, source_id, &cargo_config)
14        .map_err(|_| Error::FailedToFindManifest(manifest_path.to_owned()))?
15        .0;
16    match either_manifest {
17        EitherManifest::Real(manifest) => Ok(manifest),
18        _ => Err(Error::FailedToFindManifest(manifest_path.to_owned())),
19    }
20}