From b3fcdabeba447d3b2bf7350bafdc39e7d193aac9 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 3 Oct 2020 00:09:32 +0200 Subject: [PATCH] Add support for 2018 edition crate renaming (#59) --- src/interactors/crates.rs | 13 ++++++------- src/parsers/manifest.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/interactors/crates.rs b/src/interactors/crates.rs index c987f48..d2a021b 100644 --- a/src/interactors/crates.rs +++ b/src/interactors/crates.rs @@ -22,6 +22,8 @@ struct RegistryPackageDep { req: VersionReq, #[serde(default)] kind: Option, + #[serde(default)] + package: Option, } #[derive(Deserialize, Debug)] @@ -42,13 +44,10 @@ fn convert_pkgs( .map(|package| { let mut deps = CrateDeps::default(); for dep in package.deps { - match dep.kind.unwrap_or_else(|| "normal".into()).as_ref() { - "normal" => deps - .main - .insert(dep.name.parse()?, CrateDep::External(dep.req)), - "dev" => deps - .dev - .insert(dep.name.parse()?, CrateDep::External(dep.req)), + let name = dep.package.as_deref().unwrap_or(&dep.name).parse()?; + match dep.kind.as_deref().unwrap_or("normal") { + "normal" => deps.main.insert(name, CrateDep::External(dep.req)), + "dev" => deps.dev.insert(name, CrateDep::External(dep.req)), _ => None, }; } diff --git a/src/parsers/manifest.rs b/src/parsers/manifest.rs index fc8e63e..64535fd 100644 --- a/src/parsers/manifest.rs +++ b/src/parsers/manifest.rs @@ -11,6 +11,7 @@ struct CargoTomlComplexDependency { git: Option, path: Option, version: Option, + package: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -68,9 +69,10 @@ fn convert_dependency( .map(|parsed_name| (parsed_name, CrateDep::Internal(path))) }) } else { - cplx.version.map(|string| { + cplx.version.as_deref().map(|version| { + let name = cplx.package.as_deref().unwrap_or(&name); name.parse::().and_then(|parsed_name| { - string + version .parse::() .map_err(|err| err.into()) .map(|version| (parsed_name, CrateDep::External(version))) @@ -165,4 +167,29 @@ symbolic-common = { version = "2.0.6", path = "common" } _ => panic!("expected mixed manifest"), } } + + #[test] + fn parse_manifest_with_renamed_deps() { + let toml = r#"[package] +name = "symbolic" + +[dependencies] +symbolic-common_crate = { version = "2.0.6", package = "symbolic-common" } +"#; + + let manifest = parse_manifest_toml(toml).unwrap(); + + match manifest { + CrateManifest::Package(name, deps) => { + assert_eq!(name.as_ref(), "symbolic"); + assert_eq!(deps.main.len(), 1); + assert_eq!(deps.dev.len(), 0); + assert_eq!(deps.build.len(), 0); + + let name: CrateName = "symbolic-common".parse().unwrap(); + assert!(deps.main.get(&name).is_some()); + } + _ => panic!("expected package manifest"), + } + } }