#
cargo/ops/
cargo_read_manifest.rs

    1use std::path::Path;
    2
    3use crate::core::{EitherManifest, Package, SourceId};
    4use crate::util::errors::CargoResult;
    5use crate::util::toml::read_manifest;
    6use crate::util::GlobalContext;
    7use tracing::trace;
    8
    9pub fn read_package(
    10    path: &Path,
    11    source_id: SourceId,
    12    gctx: &GlobalContext,
    13) -> CargoResult<Package> {
    14    trace!(
    15        "read_package; path={}; source-id={}",
    16        path.display(),
    17        source_id
    18    );
    19    let manifest = read_manifest(path, source_id, gctx)?;
    20    let manifest = match manifest {
    21        EitherManifest::Real(manifest) => manifest,
    22        EitherManifest::Virtual(..) => anyhow::bail!(
    23            "found a virtual manifest at `{}` instead of a package \
    24             manifest",
    25            path.display()
    26        ),
    27    };
    28
    29    Ok(Package::new(manifest, path))
    30}