mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 10:26:30 +00:00
Add support for 2018 edition crate renaming (#59)
This commit is contained in:
parent
66fd685062
commit
b3fcdabeba
2 changed files with 35 additions and 9 deletions
|
@ -22,6 +22,8 @@ struct RegistryPackageDep {
|
|||
req: VersionReq,
|
||||
#[serde(default)]
|
||||
kind: Option<String>,
|
||||
#[serde(default)]
|
||||
package: Option<String>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ struct CargoTomlComplexDependency {
|
|||
git: Option<String>,
|
||||
path: Option<RelativePathBuf>,
|
||||
version: Option<String>,
|
||||
package: Option<String>,
|
||||
}
|
||||
|
||||
#[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::<CrateName>().and_then(|parsed_name| {
|
||||
string
|
||||
version
|
||||
.parse::<VersionReq>()
|
||||
.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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue