From 7e160e51104c5b0e50c05efac46056a454c7f23b Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 16 Dec 2021 15:18:51 -0800 Subject: [PATCH] Add function for parsing already-read manifest This makes the function formerly known as `do_read_manifest` public under the name `read_manifest_from_str` so that Cargo-as-a-library users can parse a manifest without re-reading a `Cargo.toml` file they have already read from disk themselves. --- src/cargo/util/toml/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e34b0809330..d4b26991d61 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -52,12 +52,20 @@ pub fn read_manifest( ); let contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?; - do_read_manifest(&contents, path, source_id, config) + read_manifest_from_str(&contents, path, source_id, config) .with_context(|| format!("failed to parse manifest at `{}`", path.display())) .map_err(|err| ManifestError::new(err, path.into())) } -fn do_read_manifest( +/// Parse an already-loaded `Cargo.toml` as a Cargo manifest. +/// +/// This could result in a real or virtual manifest being returned. +/// +/// A list of nested paths is also returned, one for each path dependency +/// within the manifest. For virtual manifests, these paths can only +/// come from patched or replaced dependencies. These paths are not +/// canonicalized. +pub fn read_manifest_from_str( contents: &str, manifest_file: &Path, source_id: SourceId,