From c0879aeec6e58e9b931c2bd2bc3a37eeffcb2267 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 7 Sep 2018 09:59:27 -0700 Subject: [PATCH] Handle renamed dependencies coming from Cargo This commit is intended to be coupled with https://github.com/rust-lang/cargo/pull/5993 where Cargo will start sending the registry more information about locally renamed crates to persist into the index. --- src/git.rs | 2 ++ src/models/dependency.rs | 13 ++++++++++++- src/views/krate_publish.rs | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/git.rs b/src/git.rs index b516999037d..994dacdfef1 100644 --- a/src/git.rs +++ b/src/git.rs @@ -34,6 +34,8 @@ pub struct Dependency { pub default_features: bool, pub target: Option, pub kind: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub package: Option, } fn index_file(base: &Path, name: &str) -> PathBuf { diff --git a/src/models/dependency.rs b/src/models/dependency.rs index f01a6a62586..05defc00ae6 100644 --- a/src/models/dependency.rs +++ b/src/models/dependency.rs @@ -96,15 +96,26 @@ pub fn add_dependencies( )); } + // If this dependency has an explicit name in `Cargo.toml` that + // means that the `name` we have listed is actually the package name + // that we're depending on. The `name` listed in the index is the + // Cargo.toml-written-name which is what cargo uses for + // `--extern foo=...` + let (name, package) = match &dep.explicit_name_in_toml { + Some(explicit) => (explicit.to_string(), Some(dep.name.to_string())), + None => (dep.name.to_string(), None), + }; + Ok(( git::Dependency { - name: dep.name.to_string(), + name, req: dep.version_req.to_string(), features: dep.features.iter().map(|s| s.to_string()).collect(), optional: dep.optional, default_features: dep.default_features, target: dep.target.clone(), kind: dep.kind.or(Some(DependencyKind::Normal)), + package, }, ( version_id.eq(target_version_id), diff --git a/src/views/krate_publish.rs b/src/views/krate_publish.rs index ecd732446fd..d604da01e09 100644 --- a/src/views/krate_publish.rs +++ b/src/views/krate_publish.rs @@ -63,6 +63,7 @@ pub struct CrateDependency { pub version_req: CrateVersionReq, pub target: Option, pub kind: Option, + pub explicit_name_in_toml: Option, } impl<'de> Deserialize<'de> for CrateName {