Add support for 2018 edition crate renaming (#59)

This commit is contained in:
Paolo Barbolini 2020-10-03 00:09:32 +02:00 committed by GitHub
parent 66fd685062
commit b3fcdabeba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 9 deletions

View file

@ -22,6 +22,8 @@ struct RegistryPackageDep {
req: VersionReq, req: VersionReq,
#[serde(default)] #[serde(default)]
kind: Option<String>, kind: Option<String>,
#[serde(default)]
package: Option<String>,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
@ -42,13 +44,10 @@ fn convert_pkgs(
.map(|package| { .map(|package| {
let mut deps = CrateDeps::default(); let mut deps = CrateDeps::default();
for dep in package.deps { for dep in package.deps {
match dep.kind.unwrap_or_else(|| "normal".into()).as_ref() { let name = dep.package.as_deref().unwrap_or(&dep.name).parse()?;
"normal" => deps match dep.kind.as_deref().unwrap_or("normal") {
.main "normal" => deps.main.insert(name, CrateDep::External(dep.req)),
.insert(dep.name.parse()?, CrateDep::External(dep.req)), "dev" => deps.dev.insert(name, CrateDep::External(dep.req)),
"dev" => deps
.dev
.insert(dep.name.parse()?, CrateDep::External(dep.req)),
_ => None, _ => None,
}; };
} }

View file

@ -11,6 +11,7 @@ struct CargoTomlComplexDependency {
git: Option<String>, git: Option<String>,
path: Option<RelativePathBuf>, path: Option<RelativePathBuf>,
version: Option<String>, version: Option<String>,
package: Option<String>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -68,9 +69,10 @@ fn convert_dependency(
.map(|parsed_name| (parsed_name, CrateDep::Internal(path))) .map(|parsed_name| (parsed_name, CrateDep::Internal(path)))
}) })
} else { } else {
cplx.version.map(|string| { cplx.version.as_deref().map(|version| {
let name = cplx.package.as_deref().unwrap_or(&name);
name.parse::<CrateName>().and_then(|parsed_name| { name.parse::<CrateName>().and_then(|parsed_name| {
string version
.parse::<VersionReq>() .parse::<VersionReq>()
.map_err(|err| err.into()) .map_err(|err| err.into())
.map(|version| (parsed_name, CrateDep::External(version))) .map(|version| (parsed_name, CrateDep::External(version)))
@ -165,4 +167,29 @@ symbolic-common = { version = "2.0.6", path = "common" }
_ => panic!("expected mixed manifest"), _ => 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"),
}
}
} }