diff --git a/Cargo.lock b/Cargo.lock index 33685585..3a40aa96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,11 +543,11 @@ dependencies = [ name = "cargo-toml-workspace" version = "1.0.0" dependencies = [ - "binstalk-types", "cargo_toml", "compact_str", "glob", "normalize-path", + "serde", "tempfile", "thiserror", "tracing", diff --git a/crates/cargo-toml-workspace/Cargo.toml b/crates/cargo-toml-workspace/Cargo.toml index b8bf31d9..938b6744 100644 --- a/crates/cargo-toml-workspace/Cargo.toml +++ b/crates/cargo-toml-workspace/Cargo.toml @@ -10,11 +10,11 @@ authors = ["Jiahao XU "] license = "Apache-2.0 OR MIT" [dependencies] -binstalk-types = { version = "0.6.0", path = "../binstalk-types" } cargo_toml = "0.16.0" compact_str = { version = "0.7.0", features = ["serde"] } glob = "0.3.1" normalize-path = { version = "0.2.1", path = "../normalize-path" } +serde = "1.0.163" thiserror = "1.0.40" tracing = "0.1.37" diff --git a/crates/cargo-toml-workspace/src/lib.rs b/crates/cargo-toml-workspace/src/lib.rs index 61ed3f7e..87f6e58d 100644 --- a/crates/cargo-toml-workspace/src/lib.rs +++ b/crates/cargo-toml-workspace/src/lib.rs @@ -3,11 +3,11 @@ use std::{ path::{Path, PathBuf}, }; -use binstalk_types::cargo_toml_binstall::Meta; use cargo_toml::{Error as CargoTomlError, Manifest}; use compact_str::CompactString; use glob::PatternError; use normalize_path::NormalizePath; +use serde::de::DeserializeOwned; use thiserror::Error as ThisError; use tracing::{debug, instrument, warn}; @@ -19,11 +19,14 @@ pub use cargo_toml; /// /// * `workspace_path` - can be a directory (path to workspace) or /// a file (path to `Cargo.toml`). -pub fn load_manifest_from_workspace( +pub fn load_manifest_from_workspace( workspace_path: impl AsRef, crate_name: impl AsRef, -) -> Result, Error> { - fn inner(workspace_path: &Path, crate_name: &str) -> Result, Error> { +) -> Result, Error> { + fn inner( + workspace_path: &Path, + crate_name: &str, + ) -> Result, Error> { load_manifest_from_workspace_inner(workspace_path, crate_name).map_err(|inner| Error { workspace_path: workspace_path.into(), crate_name: crate_name.into(), @@ -62,10 +65,10 @@ enum ErrorInner { } #[instrument] -fn load_manifest_from_workspace_inner( +fn load_manifest_from_workspace_inner( workspace_path: &Path, crate_name: &str, -) -> Result, ErrorInner> { +) -> Result, ErrorInner> { debug!( "Loading manifest of crate {crate_name} from workspace: {}", workspace_path.display() @@ -80,7 +83,7 @@ fn load_manifest_from_workspace_inner( let mut manifest_paths = vec![manifest_path]; while let Some(manifest_path) = manifest_paths.pop() { - let manifest = Manifest::::from_path_with_metadata(&manifest_path)?; + let manifest = Manifest::::from_path_with_metadata(&manifest_path)?; let name = manifest.package.as_ref().map(|p| &*p.name); debug!( @@ -244,7 +247,8 @@ mod test { .unwrap() .join("e2e-tests/manifests/workspace"); - let manifest = load_manifest_from_workspace(&p, "cargo-binstall").unwrap(); + let manifest = + load_manifest_from_workspace::(&p, "cargo-binstall").unwrap(); let package = manifest.package.unwrap(); assert_eq!(package.name, "cargo-binstall"); assert_eq!(package.version.as_ref().unwrap(), "0.12.0"); @@ -252,10 +256,12 @@ mod test { assert_eq!(manifest.bin[0].name.as_deref().unwrap(), "cargo-binstall"); assert_eq!(manifest.bin[0].path.as_deref().unwrap(), "src/main.rs"); - let err = load_manifest_from_workspace_inner(&p, "cargo-binstall2").unwrap_err(); + let err = load_manifest_from_workspace_inner::(&p, "cargo-binstall2") + .unwrap_err(); assert!(matches!(err, ErrorInner::NotFound), "{:#?}", err); - let manifest = load_manifest_from_workspace(&p, "cargo-watch").unwrap(); + let manifest = + load_manifest_from_workspace::(&p, "cargo-watch").unwrap(); let package = manifest.package.unwrap(); assert_eq!(package.name, "cargo-watch"); assert_eq!(package.version.as_ref().unwrap(), "8.4.0");